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

The following examples show how to use org.opengis.feature.simple.SimpleFeature#getID() . 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: BandFeatureIterator.java    From geowave with Apache License 2.0 6 votes vote down vote up
@Override
public Iterator<SimpleFeature> apply(final SimpleFeature scene) {
  if (scene == null) {
    return Collections.emptyIterator();
  }
  final String entityId = scene.getID();
  final List<SimpleFeature> bands = new ArrayList<>();

  for (final String bandId : scene.getAttribute(
      SceneFeatureIterator.BANDS_ATTRIBUTE_NAME).toString().split(";")) {
    final SimpleFeature band = featureBuilder.buildFeature(entityId + "_" + bandId);

    for (final Property property : scene.getProperties()) {
      band.setAttribute(property.getName(), property.getValue());
    }
    band.setAttribute(BAND_ATTRIBUTE_NAME, bandId);

    bands.add(band);
  }
  return bands.iterator();
}
 
Example 2
Source File: DownloadRunner.java    From geowave with Apache License 2.0 6 votes vote down vote up
protected static File getDownloadFile(final SimpleFeature band, final String workspaceDirectory) {
  final int path = (int) band.getAttribute(SceneFeatureIterator.PATH_ATTRIBUTE_NAME);
  final int row = (int) band.getAttribute(SceneFeatureIterator.ROW_ATTRIBUTE_NAME);
  final String entity = (String) band.getAttribute(SceneFeatureIterator.ENTITY_ID_ATTRIBUTE_NAME);
  return new File(
      workspaceDirectory
          + File.separator
          + DOWNLOAD_DIRECTORY
          + File.separator
          + path
          + File.separator
          + row
          + File.separator
          + entity
          + File.separator
          + band.getID()
          + ".TIF");
}
 
Example 3
Source File: WmsLayer.java    From geomajas-project-server with GNU Affero General Public License v3.0 6 votes vote down vote up
private Feature toDto(SimpleFeature feature) {
	if (feature == null) {
		return null;
	}
	Feature dto = new Feature(feature.getID());

	HashMap<String, Attribute> attributes = new HashMap<String, Attribute>();

	for (AttributeDescriptor desc : feature.getType().getAttributeDescriptors()) {
		Object obj = feature.getAttribute(desc.getName());
		if (null != obj) {
			attributes.put(desc.getLocalName(), new StringAttribute(obj.toString()));
		}
	}
	dto.setAttributes(attributes);
	dto.setId(feature.getID());

	dto.setUpdatable(false);
	dto.setDeletable(false);
	return dto;

}
 
Example 4
Source File: FeatureUtilities.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Extract the numeric feature id from a feature.
 * 
 * @param feature the feature to check.
 * @return the id as long.
 */
public static long getFeatureId( SimpleFeature feature ) {
    String idStr = feature.getID();
    int lastIndexOf = idStr.lastIndexOf('.');
    String idNumStr = idStr.substring(lastIndexOf + 1);
    return Long.parseLong(idNumStr);
}
 
Example 5
Source File: DBScanMapReduce.java    From geowave with Apache License 2.0 5 votes vote down vote up
@Override
public ClusterItem convert(final ByteArray id, final Object o) {
  final SimpleFeature feature = (SimpleFeature) o;
  final Long count =
      (Long) feature.getAttribute(AnalyticFeature.ClusterFeatureAttribute.COUNT.attrName());

  return new ClusterItem(
      feature.getID(),
      projection.getProjection(feature),
      count == null ? 1 : count,
      false);
}
 
Example 6
Source File: DateFieldRetypingSource.java    From geowave with Apache License 2.0 4 votes vote down vote up
@Override
public String getFeatureId(final SimpleFeature original) {
  // We don't need to do much, we're not changing the ID
  return original.getID();
}
 
Example 7
Source File: BandFeatureIterator.java    From geowave with Apache License 2.0 4 votes vote down vote up
@Override
public Iterator<SimpleFeature> apply(final SimpleFeature scene) {
  if (scene == null) {
    return Collections.emptyIterator();
  }
  final String entityId = scene.getID();
  final int path = (int) scene.getAttribute(SceneFeatureIterator.PATH_ATTRIBUTE_NAME);
  final int row = (int) scene.getAttribute(SceneFeatureIterator.ROW_ATTRIBUTE_NAME);
  final List<SimpleFeature> bands = new ArrayList<>();
  final String indexHtml = getDownloadIndexHtml(entityId, path, row);
  List<String> htmlLines;
  int retry = 0;
  boolean success = false;
  while (!success && (retry < DOWNLOAD_RETRY)) {
    try {
      if (retry > 0) {
        // wait for a second
        Thread.sleep(1000L);
      }
      htmlLines = IOUtils.readLines(new URL(indexHtml).openStream());
      success = true;
      for (final String line : htmlLines) {
        // read everything before the tif
        int endIndex = line.indexOf(".TIF\"");
        if (endIndex > 0) {
          // read everything after the underscore
          int beginIndex = line.indexOf("_") + 1;
          final String bandId = line.substring(beginIndex, endIndex);
          endIndex = line.indexOf("MB)");
          double divisor = 1;
          if (endIndex < 0) {
            endIndex = line.indexOf("KB)");
            divisor = 1000;
          }
          if (endIndex < 0) {
            continue;
          }
          // rather than match on a specific string for the
          // beginning of the number, let's be flexible and
          // match on several preceding characters and then
          // strip out non-numerics
          beginIndex = endIndex - 6;

          String sizeStr = line.substring(beginIndex, endIndex);
          sizeStr = sizeStr.replaceAll("[^\\d.]", "");
          final double mb = Double.parseDouble(sizeStr) / divisor;
          for (final String attributeName : SceneFeatureIterator.SCENE_ATTRIBUTES) {
            featureBuilder.set(attributeName, scene.getAttribute(attributeName));
          }
          featureBuilder.set(SIZE_ATTRIBUTE_NAME, mb);
          featureBuilder.set(BAND_ATTRIBUTE_NAME, bandId);
          featureBuilder.set(
              BAND_DOWNLOAD_ATTRIBUTE_NAME,
              getDownloadImage(entityId, path, row, bandId));
          bands.add(featureBuilder.buildFeature(entityId + "_" + bandId));
        }
      }
    } catch (final IOException | InterruptedException e) {
      LOGGER.warn("Unable to read '" + indexHtml + "'; retry round " + ++retry, e);
    }
  }
  return bands.iterator();
}
 
Example 8
Source File: GeoToolsFeatureModel.java    From geomajas-project-server with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public String getId(Object feature) throws LayerException {
	SimpleFeature featureAsFeature = asFeature(feature);
	return featureAsFeature.getID();
}
 
Example 9
Source File: ShapeInMemFeatureModel.java    From geomajas-project-server with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public String getId(Object feature) throws LayerException {
	SimpleFeature realFeature = asFeature(feature);
	return realFeature.getID();
}