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

The following examples show how to use org.opengis.feature.simple.SimpleFeature#getAttribute() . 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: SeaRouting.java    From searoute with European Union Public License 1.2 6 votes vote down vote up
/**
 * Build the edge weighters, with different possiblities regarding Suez and Panama channels.
 * 
 * @param allowSuez
 * @param allowPanama
 * @return
 */
private EdgeWeighter buildEdgeWeighter(boolean allowSuez, boolean allowPanama) {
	return new DijkstraIterator.EdgeWeighter() {
		public double getWeight(Edge e) {
			//deal with edge around the globe
			if( e.getObject()==null ) return 0;
			SimpleFeature f = (SimpleFeature) e.getObject();
			if(allowSuez && allowPanama)
				return GeoDistanceUtil.getLengthGeoKM((Geometry)f.getDefaultGeometry());
			String desc = (String)f.getAttribute("desc_");
			if(!allowSuez && "suez".equals(desc)) return Double.MAX_VALUE;
			if(!allowPanama && "panama".equals(desc)) return Double.MAX_VALUE;
			return GeoDistanceUtil.getLengthGeoKM((Geometry)f.getDefaultGeometry());
		}
	};
}
 
Example 2
Source File: VectorIngestRunner.java    From geowave with Apache License 2.0 6 votes vote down vote up
public static void writeScene(
    final SimpleFeatureType sceneType,
    final SimpleFeature firstBandOfScene,
    final Writer<SimpleFeature> sceneWriter) {
  final SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(sceneType);
  String fid = null;

  for (int i = 0; i < sceneType.getAttributeCount(); i++) {
    final AttributeDescriptor descriptor = sceneType.getDescriptor(i);

    final String name = descriptor.getLocalName();
    final Object value = firstBandOfScene.getAttribute(name);

    if (value != null) {
      featureBuilder.set(i, value);

      if (name.equals(SceneFeatureIterator.ENTITY_ID_ATTRIBUTE_NAME)) {
        fid = value.toString();
      }
    }
  }
  if (fid != null) {
    sceneWriter.write(featureBuilder.buildFeature(fid));
  }
}
 
Example 3
Source File: ElasticFeatureFilterIT.java    From elasticgeo with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testReadStringArrayWithCsvStrategy() throws Exception {
    init();
    dataStore.setArrayEncoding(ArrayEncoding.CSV);
    FilterFactory ff = dataStore.getFilterFactory();
    PropertyIsEqualTo filter = ff.equals(ff.property("modem_b"), ff.literal(true));

    SimpleFeatureCollection features = featureSource.getFeatures(filter);
    assertEquals(8, features.size());

    try (SimpleFeatureIterator iterator = features.features()) {
        assertTrue(iterator.hasNext());
        SimpleFeature feature = iterator.next();
        String st = (String) feature.getAttribute("standard_ss");
        // changed from "IEEE 802.11b" in SolrFeatureSourceTest
        assertTrue(URLDecoder.decode(st, StandardCharsets.UTF_8.toString()).startsWith("IEEE 802.11"));
    }
}
 
Example 4
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 5
Source File: FeatureSorter.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
public int compare( SimpleFeature f1, SimpleFeature f2 ) {
    if (fieldName == null) {
        throw new IllegalArgumentException("A fieldname for the sorting has to be defined.");
    }

    Object a1 = f1.getAttribute(fieldName);
    Object a2 = f2.getAttribute(fieldName);

    if (a1 instanceof Number && a2 instanceof Number) {
        double d1 = ((Number) a1).doubleValue();
        double d2 = ((Number) a2).doubleValue();
        if (d1 < d2) {
            return -1;
        } else if (d1 > d2) {
            return 1;
        } else {
            return 0;
        }
    }
    throw new IllegalArgumentException("Type not supported.");
}
 
Example 6
Source File: FeatureUtilities.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
public static LinkedHashMap<String, String> feature2AlphanumericToHashmap( SimpleFeature feature ) {
    LinkedHashMap<String, String> attributes = new LinkedHashMap<>();
    List<AttributeDescriptor> attributeDescriptors = feature.getFeatureType().getAttributeDescriptors();
    int index = 0;
    for( AttributeDescriptor attributeDescriptor : attributeDescriptors ) {
        if (!(attributeDescriptor instanceof GeometryDescriptor)) {
            String fieldName = attributeDescriptor.getLocalName();
            Object attribute = feature.getAttribute(index);
            if (attribute == null) {
                attribute = "";
            }
            String value = attribute.toString();
            attributes.put(fieldName, value);
        }
        index++;
    }
    return attributes;
}
 
Example 7
Source File: VectorCountAggregation.java    From geowave with Apache License 2.0 5 votes vote down vote up
@Override
public void aggregate(SimpleFeature entry) {
  Object o;
  if ((fieldNameParam != null) && !fieldNameParam.isEmpty()) {
    o = entry.getAttribute(fieldNameParam.getFieldName());
    if (o != null) {
      count++;
    }
  } else {
    count++;
  }
}
 
Example 8
Source File: FeatureFixedBinNumericStatistics.java    From geowave with Apache License 2.0 5 votes vote down vote up
@Override
public void entryIngested(final SimpleFeature entry, final GeoWaveRow... rows) {
  final Object o = entry.getAttribute(getFieldName());
  if (o == null) {
    return;
  }
  if (o instanceof Date) {
    add(1, ((Date) o).getTime());
  } else if (o instanceof Number) {
    add(1, ((Number) o).doubleValue());
  }
}
 
Example 9
Source File: AnalyzeRunner.java    From geowave with Apache License 2.0 5 votes vote down vote up
private void nextScene(final SimpleFeature currentBand) {
  printSceneInfo();
  sceneCount++;
  entityBandIdToSimpleFeatureMap.clear();
  final int path = (int) currentBand.getAttribute(SceneFeatureIterator.PATH_ATTRIBUTE_NAME);
  final int row = (int) currentBand.getAttribute(SceneFeatureIterator.ROW_ATTRIBUTE_NAME);
  final float cloudCover =
      (float) currentBand.getAttribute(SceneFeatureIterator.CLOUD_COVER_ATTRIBUTE_NAME);
  final String processingLevel =
      (String) currentBand.getAttribute(SceneFeatureIterator.PROCESSING_LEVEL_ATTRIBUTE_NAME);
  final Date date =
      (Date) currentBand.getAttribute(SceneFeatureIterator.ACQUISITION_DATE_ATTRIBUTE_NAME);
  minRow = Math.min(minRow, row);
  maxRow = Math.max(maxRow, row);
  minPath = Math.min(minPath, path);
  maxPath = Math.max(maxPath, path);
  final Envelope env = ((Geometry) currentBand.getDefaultGeometry()).getEnvelopeInternal();
  minLat = Math.min(minLat, env.getMinY());
  maxLat = Math.max(maxLat, env.getMaxY());
  minLon = Math.min(minLon, env.getMinX());
  maxLon = Math.max(maxLon, env.getMaxX());

  minCloudCover = Math.min(minCloudCover, cloudCover);
  maxCloudCover = Math.max(maxCloudCover, cloudCover);
  totalCloudCover += cloudCover;

  Integer count = processingLevelCounts.get(processingLevel);
  if (count == null) {
    count = 0;
  }
  processingLevelCounts.put(processingLevel, ++count);

  startDate = Math.min(startDate, date.getTime());
  endDate = Math.max(endDate, date.getTime());
  wrs2Keys.add(new WRS2Key(path, row));
}
 
Example 10
Source File: FeatureNumericRangeStatistics.java    From geowave with Apache License 2.0 5 votes vote down vote up
@Override
protected NumericRange getRange(final SimpleFeature entry) {

  final Object o = entry.getAttribute(getFieldName());
  if (o == null) {
    return null;
  }
  final double num = ((Number) o).doubleValue();
  return new NumericRange(num, num);
}
 
Example 11
Source File: VectorBoundingBoxAggregation.java    From geowave with Apache License 2.0 5 votes vote down vote up
@Override
protected Envelope getEnvelope(final SimpleFeature entry) {
  Object o;
  if ((fieldNameParam != null) && !fieldNameParam.isEmpty()) {
    o = entry.getAttribute(fieldNameParam.getFieldName());
  } else {
    o = entry.getDefaultGeometry();
  }
  if ((o != null) && (o instanceof Geometry)) {
    final Geometry geometry = (Geometry) o;
    return geometry.getEnvelopeInternal();
  }
  return null;
}
 
Example 12
Source File: SimpleFeatureItemWrapperFactory.java    From geowave with Apache License 2.0 5 votes vote down vote up
@Override
public AnalyticItemWrapper<SimpleFeature> createNextItem(
    final SimpleFeature feature,
    final String groupID,
    final Coordinate coordinate,
    final String[] extraNames,
    final double[] extraValues) {
  final Geometry geometry =
      (Geometry) feature.getAttribute(ClusterFeatureAttribute.GEOMETRY.attrName());

  return new SimpleFeatureAnalyticItemWrapper(
      AnalyticFeature.createGeometryFeature(
          feature.getFeatureType(),
          feature.getAttribute(ClusterFeatureAttribute.BATCH_ID.attrName()).toString(),
          UUID.randomUUID().toString(),
          getAttribute(feature, ClusterFeatureAttribute.NAME.attrName()),
          groupID,
          ((Double) feature.getAttribute(
              ClusterFeatureAttribute.WEIGHT.attrName())).doubleValue(),
          geometry.getFactory().createPoint(coordinate),
          extraNames,
          extraValues,
          ((Integer) feature.getAttribute(
              ClusterFeatureAttribute.ZOOM_LEVEL.attrName())).intValue(),
          ((Integer) feature.getAttribute(
              ClusterFeatureAttribute.ITERATION.attrName())).intValue() + 1,
          ((Long) feature.getAttribute(ClusterFeatureAttribute.COUNT.attrName())).longValue()));
}
 
Example 13
Source File: Pipe.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Check if there is the field in a SimpleFeature and if it's a Number.
 * 
 * @param pipe
 *            the feature.
 * @param key
 *            the key string of the field.
 * @return the Number associated at this key.
 */
private Number setFeatureField( SimpleFeature pipe, String key ) {
    Number field = ((Number) pipe.getAttribute(key));
    if (field == null) {
        pm.errorMessage(msg.message("trentoP.error.number") + key);
        throw new IllegalArgumentException(msg.message("trentoP.error.number") + key);
    }

    // return the Number
    return field;
}
 
Example 14
Source File: InternalDistributedRenderProcess.java    From geowave with Apache License 2.0 5 votes vote down vote up
@DescribeResult(
    name = "result",
    description = "This is just a pass-through, the key is to provide enough information within invertQuery to perform a map to screen transform")
public GridCoverage2D execute(
    @DescribeParameter(
        name = "data",
        description = "Feature collection containing the rendered image") final SimpleFeatureCollection features)
    throws ProcessException {
  // vector-to-raster render transform that take a single feature that
  // wraps a distributed render result and converts it to a GridCoverage2D
  if (features != null) {
    final SimpleFeatureIterator it = features.features();
    if (it.hasNext()) {
      final SimpleFeature resultFeature = features.features().next();
      final DistributedRenderResult actualResult =
          (DistributedRenderResult) resultFeature.getAttribute(0);
      final DistributedRenderOptions renderOptions =
          (DistributedRenderOptions) resultFeature.getAttribute(1);
      // convert to the GridCoverage2D required for output
      final GridCoverageFactory gcf =
          CoverageFactoryFinder.getGridCoverageFactory(GeoTools.getDefaultHints());
      final BufferedImage result = actualResult.renderComposite(renderOptions);
      final GridCoverage2D gridCov =
          gcf.create("Process Results", result, renderOptions.getEnvelope());
      return gridCov;
    }
  }
  return null;
}
 
Example 15
Source File: AnalyzeRunner.java    From geowave with Apache License 2.0 4 votes vote down vote up
private void printSceneInfo() {
  if (sceneCount > 0) {
    final SimpleDateFormat sdf =
        new SimpleDateFormat(SceneFeatureIterator.AQUISITION_DATE_FORMAT);
    boolean first = true;
    for (final Entry<String, SimpleFeature> entry : entityBandIdToSimpleFeatureMap.entrySet()) {
      final String bandId = entry.getKey();
      final SimpleFeature feature = entry.getValue();
      if (first) {
        if (feature == null) {
          throw new RuntimeException("feature is null");
        }
        // print scene info
        System.out.println(
            "\n<--   "
                + feature.getAttribute(SceneFeatureIterator.ENTITY_ID_ATTRIBUTE_NAME)
                + "   -->");
        System.out.println(
            "Acquisition Date: "
                + sdf.format(
                    feature.getAttribute(
                        SceneFeatureIterator.ACQUISITION_DATE_ATTRIBUTE_NAME)));
        System.out.println(
            "Cloud Cover: "
                + feature.getAttribute(SceneFeatureIterator.CLOUD_COVER_ATTRIBUTE_NAME));
        System.out.println(
            "Scene Download URL: "
                + feature.getAttribute(SceneFeatureIterator.SCENE_DOWNLOAD_ATTRIBUTE_NAME));
        first = false;
      }
      final float mb = (Float) feature.getAttribute(BandFeatureIterator.SIZE_ATTRIBUTE_NAME);
      final String bandDownloadUrl =
          (String) feature.getAttribute(BandFeatureIterator.BAND_DOWNLOAD_ATTRIBUTE_NAME);
      // print band info
      System.out.println("Band " + bandId + ": " + mb + " MB, download at " + bandDownloadUrl);
      Float totalMb = bandIdToMbMap.get(bandId);
      if (totalMb == null) {
        totalMb = 0.0f;
      }
      totalMb += mb;
      bandIdToMbMap.put(bandId, totalMb);
    }
  }
}
 
Example 16
Source File: AddCsvFileAction.java    From snap-desktop with GNU General Public License v3.0 4 votes vote down vote up
private void setName(SimpleFeature extendedFeature, Placemark placemark) {
    if (extendedFeature.getAttribute("Name") != null) {
        placemark.setName(extendedFeature.getAttribute("Name").toString());
    }
}
 
Example 17
Source File: OmsDelaunayTriangulation.java    From hortonmachine with GNU General Public License v3.0 4 votes vote down vote up
@Execute
public void process() throws Exception {
    checkNull(inMap);

    if (!EGeometryType.isPoint(inMap.getSchema().getGeometryDescriptor())) {
        throw new ModelsIllegalargumentException("The input geometry needs to be points.", this, pm);
    }

    if (fElev != null) {
        fElev = FeatureUtilities.findAttributeName(inMap.getSchema(), fElev);
        if (fElev == null) {
            throw new ModelsIllegalargumentException("Couldn't find field: " + fElev, this);
        }
    }

    CoordinateReferenceSystem crs = inMap.getBounds().getCoordinateReferenceSystem();
    List<SimpleFeature> fList = FeatureUtilities.featureCollectionToList(inMap);

    pm.beginTask("Processing...", fList.size());
    DelaunayTriangulationBuilder b = new DelaunayTriangulationBuilder();
    List<Coordinate> cList = new ArrayList<Coordinate>();
    for( SimpleFeature f : fList ) {
        Geometry geometry = (Geometry) f.getDefaultGeometry();
        double elev = 0.0;
        if (fElev != null)
            elev = (Double) f.getAttribute(fElev);

        Coordinate c = geometry.getCoordinate();
        c.z = elev;
        cList.add(c);
        pm.worked(1);
    }
    pm.done();

    b.setSites(cList);

    List<Geometry> geosList = new ArrayList<Geometry>();
    Geometry triangles = b.getTriangles(gf);
    for( int i = 0; i < triangles.getNumGeometries(); i++ ) {
        Geometry geometryN = triangles.getGeometryN(i);
        Coordinate[] coordinates = geometryN.getCoordinates();
        double min = Double.POSITIVE_INFINITY;
        double max = Double.NEGATIVE_INFINITY;
        for( Coordinate coordinate : coordinates ) {
            min = Math.min(min, coordinate.z);
            max = Math.max(max, coordinate.z);
        }
        geometryN.setUserData(new String[]{"" + min, "" + max});
        geosList.add(geometryN);
    }
    outMap = FeatureUtilities.featureCollectionFromGeometry(crs, geosList.toArray(new Geometry[0]));
}
 
Example 18
Source File: SimpleFeatureGeometryExtractor.java    From geowave with Apache License 2.0 4 votes vote down vote up
@Override
public String getGroupID(final SimpleFeature anObject) {
  final Object v = anObject.getAttribute("GroupID");
  return v == null ? null : v.toString();
}
 
Example 19
Source File: SimpleFeatureItemWrapperFactory.java    From geowave with Apache License 2.0 4 votes vote down vote up
private static String getAttribute(final SimpleFeature feature, final String name) {
  final Object att = feature.getAttribute(name);
  return att == null ? null : att.toString();
}
 
Example 20
Source File: CustomIndexExample.java    From geowave with Apache License 2.0 2 votes vote down vote up
/**
 * The method supplies all of the insertion IDs needed for a given entry. It is possible to
 * insert the same SimpleFeature multiple times in the index under different insertion IDs, but
 * for this case we only need to use the UUID as the lone insertion ID.
 * 
 * @param entry the feature to generate sort keys for.
 * @return the insertion IDs for the given feature
 */
@Override
public InsertionIds getInsertionIds(SimpleFeature entry) {
  final String featureUUID = (String) entry.getAttribute(uuidField);;
  return new InsertionIds(Lists.newArrayList(StringUtils.stringToBinary(featureUUID)));
}