Java Code Examples for org.geotools.feature.simple.SimpleFeatureBuilder#set()

The following examples show how to use org.geotools.feature.simple.SimpleFeatureBuilder#set() . 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: AttributesSubsetQueryIT.java    From geowave with Apache License 2.0 6 votes vote down vote up
private static SimpleFeature buildSimpleFeature(
    final String city,
    final String state,
    final double population,
    final double landArea,
    final Coordinate coordinate) {

  final SimpleFeatureBuilder builder = new SimpleFeatureBuilder(simpleFeatureType);

  builder.set(CITY_ATTRIBUTE, city);
  builder.set(STATE_ATTRIBUTE, state);
  builder.set(POPULATION_ATTRIBUTE, population);
  builder.set(LAND_AREA_ATTRIBUTE, landArea);
  builder.set(GEOMETRY_ATTRIBUTE, GeometryUtils.GEOMETRY_FACTORY.createPoint(coordinate));

  return builder.buildFeature(UUID.randomUUID().toString());
}
 
Example 2
Source File: SplitsProviderIT.java    From geowave with Apache License 2.0 6 votes vote down vote up
public static void createSkewedFeatures(
    final SimpleFeatureBuilder pointBuilder,
    final Writer<SimpleFeature> writer,
    final int firstFeatureId) {

  int featureId = firstFeatureId;
  for (double longitude = -180.0; longitude <= 180.0; longitude += 1.0) {
    for (double latitude = -90.0; latitude <= 90.0; latitude += ((longitude + 181.0) / 10.0)) {
      pointBuilder.set(
          "geometry",
          GeometryUtils.GEOMETRY_FACTORY.createPoint(new Coordinate(longitude, latitude)));
      pointBuilder.set("TimeStamp", new Date());
      pointBuilder.set("Latitude", latitude);
      pointBuilder.set("Longitude", longitude);
      // Note since trajectoryID and comment are marked as nillable we
      // don't need to set them (they default ot null).

      final SimpleFeature sft = pointBuilder.buildFeature(String.valueOf(featureId));
      writer.write(sft);
      featureId++;
    }
  }
}
 
Example 3
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 sceneWriter) {
  final SimpleFeatureBuilder bldr = new SimpleFeatureBuilder(sceneType);
  String fid = null;
  for (int i = 0; i < sceneType.getAttributeCount(); i++) {
    final AttributeDescriptor attr = sceneType.getDescriptor(i);
    final String attrName = attr.getLocalName();
    final Object attrValue = firstBandOfScene.getAttribute(attrName);
    if (attrValue != null) {
      bldr.set(i, attrValue);
      if (attrName.equals(SceneFeatureIterator.ENTITY_ID_ATTRIBUTE_NAME)) {
        fid = attrValue.toString();
      }
    }
  }
  if (fid != null) {
    sceneWriter.write(bldr.buildFeature(fid));
  }
}
 
Example 4
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 5
Source File: GeoWaveGTQueryTest.java    From rya with Apache License 2.0 5 votes vote down vote up
private static SimpleFeature buildSimpleFeature(final String locationName, final Coordinate coordinate) {
    final SimpleFeatureBuilder builder = new SimpleFeatureBuilder(getPointSimpleFeatureType());
    builder.set("locationName", locationName);
    builder.set("geometry", GeometryUtils.GEOMETRY_FACTORY.createPoint(coordinate));

    return builder.buildFeature(locationName);
}
 
Example 6
Source File: GeoWaveCustomIndexIT.java    From geowave with Apache License 2.0 5 votes vote down vote up
private static List<SimpleFeature> getGriddedTemporalFeaturesWithEnumString(
    final SimpleFeatureBuilder pointBuilder,
    final int firstFeatureId) {

  int featureId = firstFeatureId;
  final Calendar cal = Calendar.getInstance();
  cal.set(1996, Calendar.JUNE, 15, 0, 0, 0);
  final Date[] dates = new Date[3];
  dates[0] = cal.getTime();
  cal.set(1996, Calendar.JUNE, 16, 0, 0, 0);
  dates[1] = cal.getTime();
  cal.set(1996, Calendar.JUNE, 17, 0, 0, 0);
  dates[2] = cal.getTime();
  // put 3 points on each grid location with different temporal attributes
  final List<SimpleFeature> feats = new ArrayList<>();
  for (int longitude = -9; longitude <= 9; longitude++) {
    for (int latitude = -4; latitude <= 4; latitude++) {
      for (int date = 0; date < dates.length; date++) {
        pointBuilder.set(
            "geometry",
            GeometryUtils.GEOMETRY_FACTORY.createPoint(new Coordinate(longitude, latitude)));
        pointBuilder.set("TimeStamp", dates[date]);
        pointBuilder.set("Latitude", latitude);
        pointBuilder.set("Longitude", longitude);
        pointBuilder.set("Comment", getCommentValue(featureId));
        // Note since trajectoryID and comment are marked as
        // nillable we
        // don't need to set them (they default to null).

        final SimpleFeature sft = pointBuilder.buildFeature(String.valueOf(featureId));
        feats.add(sft);
        featureId++;
      }
    }
  }
  return feats;
}
 
Example 7
Source File: GeoWaveGeometryPrecisionIT.java    From geowave with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
private void ingestData(final Geometry[] geometries, final @Nullable Integer geometryPrecision) {
  dataStore = dataStorePluginOptions.createDataStore();
  final SpatialOptions spatialOptions = new SpatialOptions();
  spatialOptions.setGeometryPrecision(geometryPrecision);
  spatialIndex = new SpatialDimensionalityTypeProvider().createIndex(spatialOptions);
  final SpatialTemporalOptions spatialTemporalOptions = new SpatialTemporalOptions();
  spatialTemporalOptions.setGeometryPrecision(geometryPrecision);
  spatialTemporalIndex =
      new SpatialTemporalDimensionalityTypeProvider().createIndex(spatialTemporalOptions);
  final GeotoolsFeatureDataAdapter fda = SimpleIngest.createDataAdapter(featureType);
  final SimpleFeatureBuilder builder = new SimpleFeatureBuilder(featureType);

  final List<SimpleFeature> features = new ArrayList<>();

  for (int i = 0; i < geometries.length; i++) {
    builder.set(GEOMETRY_ATTRIBUTE_NAME, geometries[i]);
    builder.set(TIME_ATTRIBUTE_NAME, new Date());
    features.add(builder.buildFeature(String.valueOf(i)));
  }

  dataStore.addType(fda, spatialIndex, spatialTemporalIndex);
  try (Writer writer = dataStore.createWriter(fda.getTypeName())) {
    for (final SimpleFeature feat : features) {
      writer.write(feat);
    }
  }
}
 
Example 8
Source File: GPXConsumer.java    From geowave with Apache License 2.0 5 votes vote down vote up
private static void setAttribute(
    final SimpleFeatureBuilder builder,
    final String name,
    final Object obj) {
  if ((builder.getFeatureType().getDescriptor(name) != null) && (obj != null)) {
    builder.set(name, obj);
  }
}
 
Example 9
Source File: CustomIndexExample.java    From geowave with Apache License 2.0 5 votes vote down vote up
private SimpleFeature buildSimpleFeature(
    final String featureId,
    final Coordinate coordinate,
    final String uuid) {

  final SimpleFeatureBuilder builder = new SimpleFeatureBuilder(simpleFeatureType);
  builder.set("geometry", GeometryUtils.GEOMETRY_FACTORY.createPoint(coordinate));
  builder.set("uuid", uuid);

  return builder.buildFeature(featureId);
}
 
Example 10
Source File: SimpleIngest.java    From geowave with Apache License 2.0 5 votes vote down vote up
public static List<SimpleFeature> getGriddedFeatures(
    final SimpleFeatureBuilder pointBuilder,
    final int firstFeatureId) {

  // features require a featureID - this should be uniqiue per data type
  // adapter ID
  // (i.e. writing a new feature with the same feature id for the same
  // data type adapter will
  // overwrite the existing feature)
  int featureId = firstFeatureId;
  final List<SimpleFeature> feats = new ArrayList<>();
  for (int longitude = -180; longitude <= 180; longitude += 5) {
    for (int latitude = -90; latitude <= 90; latitude += 5) {
      pointBuilder.set(
          "geometry",
          GeometryUtils.GEOMETRY_FACTORY.createPoint(new Coordinate(longitude, latitude)));
      pointBuilder.set("TimeStamp", new Date());
      pointBuilder.set("Latitude", latitude);
      pointBuilder.set("Longitude", longitude);
      // Note since trajectoryID and comment are marked as nillable we
      // don't need to set them (they default ot null).

      final SimpleFeature sft = pointBuilder.buildFeature(String.valueOf(featureId));
      feats.add(sft);
      featureId++;
    }
  }
  return feats;
}
 
Example 11
Source File: SpatialTemporalQueryExample.java    From geowave with Apache License 2.0 5 votes vote down vote up
private static SimpleFeature buildSimpleFeature(
    final String locationName,
    final Coordinate coordinate,
    final Date startTime,
    final Date endTime) {

  final SimpleFeatureBuilder builder = new SimpleFeatureBuilder(getPointSimpleFeatureType());
  builder.set("locationName", locationName);
  builder.set("geometry", GeometryUtils.GEOMETRY_FACTORY.createPoint(coordinate));
  builder.set("startTime", startTime);
  builder.set("endTime", endTime);

  return builder.buildFeature(locationName);
}
 
Example 12
Source File: QueryOptionsIT.java    From geowave with Apache License 2.0 5 votes vote down vote up
private static SimpleFeature buildSimpleFeature(
    final SimpleFeatureBuilder builder,
    final String city,
    final String state,
    final double population,
    final double landArea,
    final Coordinate coordinate) {
  builder.set(CITY_ATTRIBUTE, city);
  builder.set(STATE_ATTRIBUTE, state);
  builder.set(POPULATION_ATTRIBUTE, population);
  builder.set(LAND_AREA_ATTRIBUTE, landArea);
  builder.set(GEOMETRY_ATTRIBUTE, GeometryUtils.GEOMETRY_FACTORY.createPoint(coordinate));
  return builder.buildFeature(UUID.randomUUID().toString());
}
 
Example 13
Source File: GPXConsumer.java    From geowave with Apache License 2.0 4 votes vote down vote up
public boolean build(
    final SimpleFeatureBuilder builder,
    final Long backupTimestamp,
    final boolean timeRange) {
  if ((lon != null) && (lat != null)) {
    final Coordinate p = getCoordinate();
    builder.set("geometry", GeometryUtils.GEOMETRY_FACTORY.createPoint(p));
    builder.set("Latitude", lat);
    builder.set("Longitude", lon);
  }
  setAttribute(builder, "Elevation", elevation);
  setAttribute(builder, "Course", course);
  setAttribute(builder, "Speed", speed);
  setAttribute(builder, "Source", src);
  setAttribute(builder, "Link", link);
  setAttribute(builder, "URL", url);
  setAttribute(builder, "URLName", urlname);
  setAttribute(builder, "MagneticVariation", magvar);
  setAttribute(builder, "Satellites", sat);
  setAttribute(builder, "Symbol", sym);
  setAttribute(builder, "VDOP", vdop);
  setAttribute(builder, "HDOP", hdop);
  setAttribute(builder, "GeoHeight", geoidheight);
  setAttribute(builder, "Fix", fix);
  setAttribute(builder, "Station", dgpsid);
  setAttribute(builder, "PDOP", pdop);
  setAttribute(builder, "Classification", type);
  setAttribute(builder, "Name", name);
  setAttribute(builder, "Comment", cmt);
  setAttribute(builder, "Description", desc);
  setAttribute(builder, "Symbol", sym);
  if (timestamp != null) {
    setAttribute(builder, "Timestamp", new Date(timestamp));
  } else if ((backupTimestamp != null) && !timeRange) {
    setAttribute(builder, "Timestamp", new Date(backupTimestamp));
  }
  if (children != null) {

    boolean setDuration = true;

    final List<Coordinate> childSequence = buildCoordinates();

    final int childCoordCount = childSequence.size();
    if (childCoordCount <= 1) {
      return false;
    }

    final LineString geom =
        GeometryUtils.GEOMETRY_FACTORY.createLineString(
            childSequence.toArray(new Coordinate[childSequence.size()]));

    // Filter gpx track based on maxExtent
    if (geom.isEmpty() || (geom.getEnvelopeInternal().maxExtent() > maxLineLength)) {
      return false;
    }

    builder.set("geometry", geom);

    setAttribute(builder, "NumberPoints", Long.valueOf(childCoordCount));

    Long minTime = getStartTime();
    if (minTime != null) {
      builder.set("StartTimeStamp", new Date(minTime));
    } else if ((timestamp != null) && timeRange) {
      minTime = timestamp;
      builder.set("StartTimeStamp", new Date(timestamp));
    } else if ((backupTimestamp != null) && timeRange) {
      minTime = backupTimestamp;
      builder.set("StartTimeStamp", new Date(backupTimestamp));
    } else {
      setDuration = false;
    }
    Long maxTime = getEndTime();
    if (maxTime != null) {
      builder.set("EndTimeStamp", new Date(maxTime));
    } else if ((timestamp != null) && timeRange) {
      maxTime = timestamp;
      builder.set("EndTimeStamp", new Date(timestamp));
    } else if ((backupTimestamp != null) && timeRange) {
      maxTime = backupTimestamp;
      builder.set("EndTimeStamp", new Date(backupTimestamp));
    } else {
      setDuration = false;
    }
    if (setDuration) {
      builder.set("Duration", maxTime - minTime);
    }
  }
  return true;
}
 
Example 14
Source File: SpatialQueryExample.java    From geowave with Apache License 2.0 4 votes vote down vote up
private void ingestPolygonFeature() throws ParseException {
  log.info("Ingesting polygon data");
  // First, we'll build our third kind of SimpleFeature, which we'll call
  // "polygon-feature"
  // We need the type builder to build the feature type
  final SimpleFeatureTypeBuilder sftBuilder = new SimpleFeatureTypeBuilder();
  // AttributeTypeBuilder for the attributes of the SimpleFeature
  final AttributeTypeBuilder attrBuilder = new AttributeTypeBuilder();
  // Here we're setting the SimpleFeature name. Later on, we'll be able to
  // query GW just by this particular feature.
  sftBuilder.setName("polygon-feature");
  // Add the attributes to the feature
  // Add the geometry attribute, which is mandatory for GeoWave to be able
  // to construct an index out of the SimpleFeature
  // Will be any arbitrary geometry; in this case, a polygon.
  sftBuilder.add(attrBuilder.binding(Geometry.class).nillable(false).buildDescriptor("geometry"));
  // Add another attribute just to be able to filter by it in CQL
  sftBuilder.add(attrBuilder.binding(String.class).nillable(false).buildDescriptor("filter"));

  // Create the SimpleFeatureType
  final SimpleFeatureType sfType = sftBuilder.buildFeatureType();
  // We need the adapter for all our operations with GeoWave
  final FeatureDataAdapter sfAdapter = new FeatureDataAdapter(sfType);

  // Now we build the actual features. We'll create one polygon.
  // First point
  final SimpleFeatureBuilder sfBuilder = new SimpleFeatureBuilder(sfType);

  // For ease of use, we'll create the polygon geometry with WKT format.
  final String polygonDefinition =
      "POLYGON (( "
          + "-80.3045654296875 25.852426562716428, "
          + "-80.123291015625 25.808545671771615, "
          + "-80.19195556640625 25.7244467526159, "
          + "-80.34233093261719 25.772068899816585, "
          + "-80.3045654296875 25.852426562716428"
          + "))";
  final Geometry geom =
      new WKTReader(JTSFactoryFinder.getGeometryFactory()).read(polygonDefinition);
  sfBuilder.set("geometry", geom);
  sfBuilder.set("filter", "Polygon");
  // When calling buildFeature, we need to pass an unique id for that
  // feature, or it will be overwritten.
  final SimpleFeature polygon = sfBuilder.buildFeature("1");

  final ArrayList<SimpleFeature> features = new ArrayList<>();
  features.add(polygon);

  // Ingest the data. For that purpose, we need the feature adapter,
  // the index type (the default spatial index is used here),
  // and an iterator of SimpleFeature
  ingest(sfAdapter, new SpatialIndexBuilder().createIndex(), features);
  log.info("Polygon data ingested");
}
 
Example 15
Source File: SpatialQueryExample.java    From geowave with Apache License 2.0 4 votes vote down vote up
/** We're going to ingest a more complete simple feature. */
private void ingestPointComplexFeature() {
  // First, we'll build our second kind of SimpleFeature, which we'll call
  // "complex-feature"
  // We need the type builder to build the feature type
  final SimpleFeatureTypeBuilder sftBuilder = new SimpleFeatureTypeBuilder();
  // AttributeTypeBuilder for the attributes of the SimpleFeature
  final AttributeTypeBuilder attrBuilder = new AttributeTypeBuilder();
  // Here we're setting the SimpleFeature name. Later on, we'll be able to
  // query GW just by this particular feature.
  sftBuilder.setName("complex-feature");
  // Add the attributes to the feature
  // Add the geometry attribute, which is mandatory for GeoWave to be able
  // to construct an index out of the SimpleFeature
  sftBuilder.add(attrBuilder.binding(Point.class).nillable(false).buildDescriptor("geometry"));
  // Add another attribute just to be able to filter by it in CQL
  sftBuilder.add(attrBuilder.binding(String.class).nillable(false).buildDescriptor("filter"));
  // Add more attributes to use with CQL filtering later on.
  sftBuilder.add(attrBuilder.binding(Double.class).nillable(false).buildDescriptor("latitude"));
  sftBuilder.add(attrBuilder.binding(Double.class).nillable(false).buildDescriptor("longitude"));

  // Create the SimpleFeatureType
  final SimpleFeatureType sfType = sftBuilder.buildFeatureType();
  // We need the adapter for all our operations with GeoWave
  final FeatureDataAdapter sfAdapter = new FeatureDataAdapter(sfType);

  // Now we build the actual features. We'll create two more points.
  // First point
  final SimpleFeatureBuilder sfBuilder = new SimpleFeatureBuilder(sfType);
  sfBuilder.set(
      "geometry",
      GeometryUtils.GEOMETRY_FACTORY.createPoint(new Coordinate(-80.193388, 25.780538)));
  sfBuilder.set("filter", "Complex-Station");
  sfBuilder.set("latitude", 25.780538);
  sfBuilder.set("longitude", -80.193388);
  // When calling buildFeature, we need to pass an unique id for that
  // feature, or it will be overwritten.
  final SimpleFeature basicPoint1 = sfBuilder.buildFeature("1");

  // Construct the second feature.
  sfBuilder.set(
      "geometry",
      GeometryUtils.GEOMETRY_FACTORY.createPoint(
          new Coordinate(-118.26713562011719, 33.988349152677955)));
  sfBuilder.set("filter", "Complex-LA");
  sfBuilder.set("latitude", 33.988349152677955);
  sfBuilder.set("longitude", -118.26713562011719);
  final SimpleFeature basicPoint2 = sfBuilder.buildFeature("2");

  final ArrayList<SimpleFeature> features = new ArrayList<>();
  features.add(basicPoint1);
  features.add(basicPoint2);

  // Ingest the data. For that purpose, we need the feature adapter,
  // the index type (the default spatial index is used here),
  // and an iterator of SimpleFeature
  ingest(sfAdapter, new SpatialIndexBuilder().createIndex(), features);

  /** After ingest, a single point might look like this in Accumulo. */
  // \x1F\x11\xCB\xFC\xB6\xEFT\x00\xFFcomplex_feature4\x00\x00\x00\x0E\x00\x00\x00\x01\x00\x00\x00\x00
  // complex_feature:filter [] Complex-LA
  // \x1F\x11\xCB\xFC\xB6\xEFT\x00\xFFcomplex_feature4\x00\x00\x00\x0E\x00\x00\x00\x01\x00\x00\x00\x00
  // complex_feature:geom\x00\x00 []
  // \x00\x00\x00\x00\x01\xC0]\x91\x18\xC0\x00\x00\x00@@\xFE\x829\x9B\xE3\xFC
  // \x1F\x11\xCB\xFC\xB6\xEFT\x00\xFFcomplex_feature4\x00\x00\x00\x0E\x00\x00\x00\x01\x00\x00\x00\x00
  // complex_feature:latitude [] @@\xFE\x829\x9B\xE3\xFC
  // \x1F\x11\xCB\xFC\xB6\xEFT\x00\xFFcomplex_feature\x00\x00\x00\x0E\x00\x00\x00\x01\x00\x00\x00\x00
  // complex_feature:longitude [] \xC0]\x91\x18\xC0\x00\x00\x
}
 
Example 16
Source File: GeoWaveAvroFeatureDataAdapterTest.java    From geowave with Apache License 2.0 4 votes vote down vote up
@Test
public void basicTest() throws Exception {

  final GeoWaveAvroFeatureDataAdapter adapter = new GeoWaveAvroFeatureDataAdapter(schema);

  final GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();
  final SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(schema);

  final int numFeatures = 10;

  final List<SimpleFeature> data = new ArrayList<>();
  final Map<Integer, SimpleFeature> dataMap = new HashMap<>();
  // Write data using the whole feature data adapter
  for (int i = 0; i < numFeatures; i++) {

    final Point point = geometryFactory.createPoint(new Coordinate(i, i));

    featureBuilder.set("geometry", point);
    featureBuilder.set("pop", i);
    featureBuilder.set("when", new Date(0));
    featureBuilder.set("whennot", new Date());

    data.add(featureBuilder.buildFeature(Integer.toString(i)));
    dataMap.put(i, data.get(data.size() - 1));
  }

  ingestCannedData(adapter, data);

  final Coordinate[] coordArray = new Coordinate[5];
  coordArray[0] = new Coordinate(-180, -90);
  coordArray[1] = new Coordinate(180, -90);
  coordArray[2] = new Coordinate(180, 90);
  coordArray[3] = new Coordinate(-180, 90);
  coordArray[4] = new Coordinate(-180, -90);
  // read data using the whole feature data adapter
  VectorQueryBuilder bldr =
      VectorQueryBuilder.newBuilder().addTypeName(adapter.getTypeName()).indexName(INDEX_NAME);
  bldr =
      bldr.constraints(
          bldr.constraintsFactory().spatialTemporalConstraints().spatialConstraints(
              new GeometryFactory().createPolygon(coordArray)).build());
  try (final CloseableIterator<SimpleFeature> itr = dataStore.query(bldr.build())) {

    while (itr.hasNext()) {
      final SimpleFeature feat = itr.next();

      final SimpleFeature feature = dataMap.remove(Integer.parseInt(feat.getID()));
      assertEquals(DataUtilities.encodeFeature(feature), DataUtilities.encodeFeature(feat));
    }
    assertTrue(dataMap.isEmpty());
  }
}
 
Example 17
Source File: SpatialQueryExample.java    From geowave with Apache License 2.0 4 votes vote down vote up
private void ingestPointBasicFeature() {
  // First, we'll build our first kind of SimpleFeature, which we'll call
  // "basic-feature"
  // We need the type builder to build the feature type
  final SimpleFeatureTypeBuilder sftBuilder = new SimpleFeatureTypeBuilder();
  // AttributeTypeBuilder for the attributes of the SimpleFeature
  final AttributeTypeBuilder attrBuilder = new AttributeTypeBuilder();
  // Here we're setting the SimpleFeature name. Later on, we'll be able to
  // query GW just by this particular feature.
  sftBuilder.setName("basic-feature");
  // Add the attributes to the feature
  // Add the geometry attribute, which is mandatory for GeoWave to be able
  // to construct an index out of the SimpleFeature
  sftBuilder.add(attrBuilder.binding(Point.class).nillable(false).buildDescriptor("geometry"));
  // Add another attribute just to be able to filter by it in CQL
  sftBuilder.add(attrBuilder.binding(String.class).nillable(false).buildDescriptor("filter"));

  // Create the SimpleFeatureType
  final SimpleFeatureType sfType = sftBuilder.buildFeatureType();
  // We need the adapter for all our operations with GeoWave
  final FeatureDataAdapter sfAdapter = new FeatureDataAdapter(sfType);

  // Now we build the actual features. We'll create two points.
  // First point
  final SimpleFeatureBuilder sfBuilder = new SimpleFeatureBuilder(sfType);
  sfBuilder.set(
      "geometry",
      GeometryUtils.GEOMETRY_FACTORY.createPoint(
          new Coordinate(-80.211181640625, 25.848101000701597)));
  sfBuilder.set("filter", "Basic-Stadium");
  // When calling buildFeature, we need to pass an unique id for that
  // feature, or it will be overwritten.
  final SimpleFeature basicPoint1 = sfBuilder.buildFeature("1");

  // Construct the second feature.
  sfBuilder.set(
      "geometry",
      GeometryUtils.GEOMETRY_FACTORY.createPoint(new Coordinate(-80.191360, 25.777804)));
  sfBuilder.set("filter", "Basic-College");
  final SimpleFeature basicPoint2 = sfBuilder.buildFeature("2");

  final ArrayList<SimpleFeature> features = new ArrayList<>();
  features.add(basicPoint1);
  features.add(basicPoint2);

  // Ingest the data. For that purpose, we need the feature adapter,
  // the index type (the default spatial index is used here),
  // and an iterator of SimpleFeature
  ingest(sfAdapter, new SpatialIndexBuilder().createIndex(), features);
}
 
Example 18
Source File: PolygonDataIdQueryIT.java    From geowave with Apache License 2.0 4 votes vote down vote up
private static SimpleFeature buildSimpleFeature(final String dataId, final Geometry geo) {
  final SimpleFeatureBuilder builder = new SimpleFeatureBuilder(simpleFeatureType);
  builder.set(GEOMETRY_ATTRIBUTE, geo);
  return builder.buildFeature(dataId);
}
 
Example 19
Source File: SqlResultsWriter.java    From geowave with Apache License 2.0 4 votes vote down vote up
public void writeResults(String typeName) {
  if (typeName == null) {
    typeName = DEFAULT_TYPE_NAME;
    LOGGER.warn(
        "Using default type name (adapter id): '" + DEFAULT_TYPE_NAME + "' for SQL output");
  }

  final StructType schema = results.schema();
  final SimpleFeatureType featureType = SchemaConverter.schemaToFeatureType(schema, typeName);

  final SimpleFeatureBuilder sfBuilder = new SimpleFeatureBuilder(featureType);

  final FeatureDataAdapter featureAdapter = new FeatureDataAdapter(featureType);

  final DataStore featureStore = outputDataStore.createDataStore();
  final Index featureIndex =
      new SpatialDimensionalityTypeProvider().createIndex(new SpatialOptions());
  featureStore.addType(featureAdapter, featureIndex);
  try (Writer writer = featureStore.createWriter(featureAdapter.getTypeName())) {

    final List<Row> rows = results.collectAsList();

    for (int r = 0; r < rows.size(); r++) {
      final Row row = rows.get(r);

      for (int i = 0; i < schema.fields().length; i++) {
        final StructField field = schema.apply(i);
        final Object rowObj = row.apply(i);
        if (rowObj != null) {
          if (field.name().equals("geom")) {
            final Geometry geom = (Geometry) rowObj;

            sfBuilder.set("geom", geom);
          } else if (field.dataType() == DataTypes.TimestampType) {
            final long millis = ((Timestamp) rowObj).getTime();
            final Date date = new Date(millis);

            sfBuilder.set(field.name(), date);
          } else {
            sfBuilder.set(field.name(), rowObj);
          }
        }
      }

      final SimpleFeature sf = sfBuilder.buildFeature("result-" + nf.format(r));

      writer.write(sf);
    }
  }
}
 
Example 20
Source File: SLDUtils.java    From snap-desktop with GNU General Public License v3.0 4 votes vote down vote up
public static SimpleFeature createStyledFeature(SimpleFeatureType type, SimpleFeature feature, String styleCSS) {
    SimpleFeatureBuilder sfb = new SimpleFeatureBuilder(type);
    sfb.init(feature);
    sfb.set(PlainFeatureFactory.ATTRIB_NAME_STYLE_CSS, styleCSS);
    return sfb.buildFeature(feature.getID());
}