Java Code Examples for org.opengis.feature.simple.SimpleFeature#getFeatureType()

The following examples show how to use org.opengis.feature.simple.SimpleFeature#getFeatureType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FeatureUtilities.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Getter for attributes of a feature.
 * 
 * <p>If the attribute is not found, checks are done in non
 * case sensitive mode.
 * 
 * @param feature the feature from which to get the attribute.
 * @param field the name of the field.
 * @return the attribute or null if none found.
 */
public static Object getAttributeCaseChecked( SimpleFeature feature, String field ) {
    Object attribute = feature.getAttribute(field);
    if (attribute == null) {
        attribute = feature.getAttribute(field.toLowerCase());
        if (attribute != null)
            return attribute;
        attribute = feature.getAttribute(field.toUpperCase());
        if (attribute != null)
            return attribute;

        // alright, last try, search for it
        SimpleFeatureType featureType = feature.getFeatureType();
        field = findAttributeName(featureType, field);
        if (field != null) {
            return feature.getAttribute(field);
        }
    }
    return attribute;
}
 
Example 2
Source File: OmsLW04_BankfullWidthAnalyzer.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
private DefaultFeatureCollection getNetworkPoints( CoordinateReferenceSystem crs,
        LinkedHashMap<SimpleFeature, double[]> validPointsMap ) throws Exception {

    FeatureExtender ext = null;
    DefaultFeatureCollection newCollection = new DefaultFeatureCollection();
    Set<Entry<SimpleFeature, double[]>> entrySet = validPointsMap.entrySet();
    for( Entry<SimpleFeature, double[]> entry : entrySet ) {
        SimpleFeature pointFeature = entry.getKey();

        if (ext == null) {
            ext = new FeatureExtender(pointFeature.getFeatureType(), new String[]{WIDTH, WIDTH_FROM},
                    new Class[]{Double.class, Double.class});
        }

        double[] attributes = entry.getValue();
        Object[] attrObj = new Object[attributes.length];
        for( int i = 0; i < attrObj.length; i++ ) {
            attrObj[i] = attributes[i];
        }
        SimpleFeature extendedFeature = ext.extendFeature(pointFeature, attrObj);
        newCollection.add(extendedFeature);
    }

    return newCollection;
}
 
Example 3
Source File: OmsLW04_BankfullWidthAnalyzer.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
private DefaultFeatureCollection getProblemPoints( CoordinateReferenceSystem crs,
        LinkedHashMap<SimpleFeature, String> problemPointsMap ) throws Exception {

    FeatureExtender ext = null;

    DefaultFeatureCollection newCollection = new DefaultFeatureCollection();
    Set<Entry<SimpleFeature, String>> entrySet = problemPointsMap.entrySet();
    for( Entry<SimpleFeature, String> entry : entrySet ) {
        SimpleFeature pointFeature = entry.getKey();
        String notes = entry.getValue();

        if (ext == null) {
            ext = new FeatureExtender(pointFeature.getFeatureType(), new String[]{NOTES}, new Class[]{String.class});
        }

        SimpleFeature extendedFeature = ext.extendFeature(pointFeature, new Object[]{notes});
        newCollection.add(extendedFeature);
    }

    return newCollection;
}
 
Example 4
Source File: VectorExportMapper.java    From geowave with Apache License 2.0 6 votes vote down vote up
@Override
protected void map(
    final GeoWaveInputKey key,
    final SimpleFeature value,
    final Mapper<GeoWaveInputKey, SimpleFeature, AvroKey<AvroSimpleFeatureCollection>, NullWritable>.Context context)
    throws IOException, InterruptedException {
  AvroSFCWriter avroWriter = adapterIdToAvroWriterMap.get(key.getInternalAdapterId());
  if (avroWriter == null) {
    avroWriter = new AvroSFCWriter(value.getFeatureType(), batchSize);
    adapterIdToAvroWriterMap.put(key.getInternalAdapterId(), avroWriter);
  }
  final AvroSimpleFeatureCollection retVal = avroWriter.write(value);
  if (retVal != null) {
    outKey.datum(retVal);
    context.write(outKey, outVal);
  }
}
 
Example 5
Source File: OmsJami.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Fills the elevation and id arrays for the stations, ordering in ascending
 * elevation order.
 * 
 * @throws Exception
 *             in the case the sorting gives problems.
 */
private void extractFromStationFeatures() throws Exception {
    int stationIdIndex = -1;
    int stationElevIndex = -1;
    pm.beginTask("Filling the elevation and id arrays for the stations, ordering them in ascending elevation order.",
            stationCoordinates.size());
    for( int i = 0; i < stationCoordinates.size(); i++ ) {
        pm.worked(1);
        SimpleFeature stationF = stationFeatures.get(i);
        Coordinate stationCoord = stationCoordinates.get(i);
        if (stationIdIndex == -1) {
            SimpleFeatureType featureType = stationF.getFeatureType();
            stationIdIndex = featureType.indexOf(fStationid);
            stationElevIndex = featureType.indexOf(fStationelev);
            if (stationIdIndex == -1) {
                throw new IllegalArgumentException("Could not find the field: " + fStationid);
            }
            if (stationElevIndex == -1) {
                throw new IllegalArgumentException("Could not find the field: " + fStationelev);
            }
        }
        int id = ((Number) stationF.getAttribute(stationIdIndex)).intValue();
        double elev = ((Number) stationF.getAttribute(stationElevIndex)).doubleValue();
        statElev[i] = elev;
        statId[i] = id;
        stationId2CoordinateMap.put(id, stationCoord);
    }
    pm.done();
    // sort
    QuickSortAlgorithm qsA = new QuickSortAlgorithm(pm);
    qsA.sort(statElev, statId);
}
 
Example 6
Source File: AddCsvFileAction.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void actionPerformed(ActionEvent e) {
    PropertyMap preferences = appContext.getPreferences();
    final SnapFileChooser fileChooser = getFileChooser(
            preferences.getPropertyString(LAST_OPEN_CSV_DIR, SystemUtils.getUserHomeDir().getPath()));
    int answer = fileChooser.showDialog(parent, "Select");
    if (answer == JFileChooser.APPROVE_OPTION) {
        File selectedFile = fileChooser.getSelectedFile();
        preferences.setPropertyString(LAST_OPEN_CSV_DIR, selectedFile.getParent());
        try {
            final List<SimpleFeature> extendedFeatures = PixExOpUtils.extractFeatures(selectedFile);
            for (SimpleFeature extendedFeature : extendedFeatures) {
                final GenericPlacemarkDescriptor placemarkDescriptor = new GenericPlacemarkDescriptor(
                        extendedFeature.getFeatureType());
                final Placemark placemark = placemarkDescriptor.createPlacemark(extendedFeature);
                setName(extendedFeature, placemark);
                setDateTime(extendedFeature, placemark);
                setPlacemarkGeoPos(extendedFeature, placemark);
                tableModel.addPlacemark(placemark);
            }
        } catch (IOException exception) {
            appContext.handleError(String.format("Error occurred while reading file: %s \n" +
                                                         exception.getLocalizedMessage() +
                                                         "\nPossible reason: Other char separator than tabulator used",
                                                 selectedFile), exception);
        }
    }
}
 
Example 7
Source File: FeatureSerializer.java    From geowave with Apache License 2.0 5 votes vote down vote up
@Override
public void write(final Kryo arg0, final Output arg1, final SimpleFeature arg2) {
  final FeatureWritable fw = new FeatureWritable(arg2.getFeatureType());
  fw.setFeature(arg2);
  final ByteArrayOutputStream bos = new ByteArrayOutputStream();
  try (DataOutputStream os = new DataOutputStream(bos)) {
    fw.write(os);
    os.flush();
    final byte[] data = bos.toByteArray();
    arg1.writeInt(data.length);
    arg1.write(data);
  } catch (final IOException e) {
    LOGGER.error("Cannot serialize Simple Feature", e);
  }
}