org.geotools.feature.simple.SimpleFeatureBuilder Java Examples

The following examples show how to use org.geotools.feature.simple.SimpleFeatureBuilder. 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: OmsGridsGenerator.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
private void createPoints( CoordinateReferenceSystem crs, GeometryFactory gf, List<LineString> verticals,
        List<LineString> horizontals ) {
    outMap = new DefaultFeatureCollection();
    SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
    b.setName(POINT);
    b.setCRS(crs);
    b.add("the_geom", Point.class);
    b.add("id", Long.class);
    SimpleFeatureType type = b.buildFeatureType();
    SimpleFeatureBuilder fbuilder = new SimpleFeatureBuilder(type);

    Geometry gVer = gf.createMultiLineString(verticals.toArray(new LineString[0]));
    Geometry gHor = gf.createMultiLineString(horizontals.toArray(new LineString[0]));

    Geometry intersection = gHor.intersection(gVer);

    long index = 0;
    int numGeometries = intersection.getNumGeometries();
    for( int i = 0; i < numGeometries; i++ ) {
        Geometry geometry = intersection.getGeometryN(i);
        Object[] values = new Object[]{geometry, index++};
        fbuilder.addAll(values);
        SimpleFeature feature = fbuilder.buildFeature(null);
        ((DefaultFeatureCollection) outMap).add(feature);
    }
}
 
Example #3
Source File: TestProfile.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
private SimpleFeatureCollection doCollection() {
    CoordinateReferenceSystem crs = HMTestMaps.getCrs();
    SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
    b.setName("typename");
    b.setCRS(crs);
    b.add("the_geom", LineString.class);
    SimpleFeatureType type = b.buildFeatureType();
    SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type);

    Coordinate one = new Coordinate(westNorth.x + ep.getXres() / 2, centerCoord.y + ep.getYres() / 2);
    Coordinate two = new Coordinate(eastSouth.x - ep.getXres() / 2, centerCoord.y + ep.getYres() / 2);

    LineString lineString = GeometryUtilities.gf().createLineString(new Coordinate[]{one, two});
    Object[] values = new Object[]{lineString};
    builder.addAll(values);
    SimpleFeature feature = builder.buildFeature(null);
    DefaultFeatureCollection newCollection = new DefaultFeatureCollection();
    newCollection.add(feature);
    return newCollection;
}
 
Example #4
Source File: JsonDefinitionColumnVisibilityManagementTest.java    From geowave with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() throws SchemaException, CQLException {
  type =
      DataUtilities.createType(
          "geostuff",
          "geometry:Geometry:srid=4326,vis:java.lang.String,pop:java.lang.Long,pid:String");
  descriptors = type.getAttributeDescriptors();
  defaults = new Object[descriptors.size()];
  int p = 0;
  for (final AttributeDescriptor descriptor : descriptors) {
    defaults[p++] = descriptor.getDefaultValue();
  }

  newFeature = SimpleFeatureBuilder.build(type, defaults, UUID.randomUUID().toString());
  newFeature.setAttribute("pop", Long.valueOf(100));
  newFeature.setAttribute("pid", UUID.randomUUID().toString());
  newFeature.setAttribute("vis", "{\"pid\":\"TS\", \"geo.*\":\"S\"}");
  newFeature.setAttribute("geometry", factory.createPoint(new Coordinate(43.454, 128.232)));
}
 
Example #5
Source File: SplitsProviderIT.java    From geowave with Apache License 2.0 6 votes vote down vote up
private void ingestWithDistribution(final Distribution distr) {
  final DataStore dataStore = dataStorePluginOptions.createDataStore();
  dataStore.addType(fda, idx);
  try (final Writer<SimpleFeature> writer = dataStore.createWriter(fda.getTypeName())) {

    switch (distr) {
      case UNIFORM:
        createUniformFeatures(new SimpleFeatureBuilder(sft), writer, 100000);
        break;
      case BIMODAL:
        createBimodalFeatures(new SimpleFeatureBuilder(sft), writer, 400000);
        break;
      case SKEWED:
      default:
        createSkewedFeatures(new SimpleFeatureBuilder(sft), writer, 700000);
        break;
    }
  }
}
 
Example #6
Source File: OmsZonalStats.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
public static SimpleFeatureBuilder createFeatureBuilder( CoordinateReferenceSystem crs, boolean hasUserTotalMean ) {
    SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
    b.setName("stats");
    b.setCRS(crs);
    b.add("the_geom", Polygon.class);
    b.add(MIN, Double.class);
    b.add(MAX, Double.class);
    b.add(AVG, Double.class);
    b.add(VAR, Double.class);
    b.add(SDEV, Double.class);
    b.add(SUM, Double.class);
    if (hasUserTotalMean)
        b.add(AVGABSDEV, Double.class);
    b.add(ACTCELLS, Integer.class);
    b.add(INVCELLS, Integer.class);
    SimpleFeatureType type = b.buildFeatureType();
    return new SimpleFeatureBuilder(type);
}
 
Example #7
Source File: GeoWaveCustomIndexIT.java    From geowave with Apache License 2.0 6 votes vote down vote up
public void ingest(boolean addSpatialTemporal) {
  final SimpleFeatureType sft = SimpleIngest.createPointFeatureType();
  final GeotoolsFeatureDataAdapter fda = SimpleIngest.createDataAdapter(sft);
  final List<SimpleFeature> features =
      getGriddedTemporalFeaturesWithEnumString(new SimpleFeatureBuilder(sft), 6001);
  TestUtils.deleteAll(dataStoreOptions);
  final DataStore dataStore = dataStoreOptions.createDataStore();
  if (addSpatialTemporal) {
    dataStore.addType(
        fda,
        new SpatialIndexBuilder().createIndex(),
        new SpatialTemporalIndexBuilder().createIndex(),
        getTestEnumIndex());
  } else {
    dataStore.addType(fda, getTestEnumIndex());
  }
  try (Writer<SimpleFeature> writer = dataStore.createWriter(sft.getTypeName())) {
    features.stream().forEach(f -> writer.write(f));
  }
}
 
Example #8
Source File: OmsNmeaFeatureReader.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
public static SimpleFeatureBuilder getNmeaFeatureBuilder() {
    SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
    b.setName("nmea");
    b.setCRS(DefaultGeographicCRS.WGS84);
    b.add("the_geom", Point.class);
    b.add(NmeaGpsPoint.strSpeed, Double.class);
    b.add(NmeaGpsPoint.strAltitude, Double.class);
    b.add(NmeaGpsPoint.strQuality, Double.class);
    b.add(NmeaGpsPoint.strSat, Integer.class);
    b.add(NmeaGpsPoint.strHdop, Double.class);
    b.add(NmeaGpsPoint.strMsl, Double.class);
    b.add(NmeaGpsPoint.strUtctime, String.class);
    b.add(NmeaGpsPoint.strMag_var, Double.class);
    b.add(NmeaGpsPoint.strAngle, Double.class);
    final SimpleFeatureType featureType = b.buildFeatureType();
    SimpleFeatureBuilder nmeaSimpleFeatureBuilder = new SimpleFeatureBuilder(featureType);
    return nmeaSimpleFeatureBuilder;
}
 
Example #9
Source File: OmsLasConverter.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
private void createBboxGeometry( CoordinateReferenceSystem crs, File lasFile, SimpleFeatureCollection outGeodata )
        throws Exception {
    final ReferencedEnvelope3D envelope = lasReader.getHeader().getDataEnvelope();
    ReferencedEnvelope env2d = new ReferencedEnvelope(envelope);
    final Polygon polygon = FeatureUtilities.envelopeToPolygon(new Envelope2D(env2d));

    final SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
    b.setName("lasdataenvelope");
    b.setCRS(crs);
    b.add("the_geom", Polygon.class);
    b.add("id", String.class);
    final SimpleFeatureType type = b.buildFeatureType();

    final SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type);
    final Object[] values = new Object[]{polygon, lasFile.getName()};
    builder.addAll(values);
    final SimpleFeature feature = builder.buildFeature(null);
    ((DefaultFeatureCollection) outGeodata).add(feature);
    OmsVectorWriter.writeVector(outFile, outGeodata);
}
 
Example #10
Source File: TestScanLineRasterizer.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
private SimpleFeatureCollection doCollection( RegionMap envelopeParams ) {

        SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
        b.setName("typename");
        b.setCRS(crs);
        b.add("the_geom", Polygon.class);
        b.add("cat", Double.class);
        SimpleFeatureType type = b.buildFeatureType();
        SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type);
        Object[] values = new Object[]{polygon, 1.0};
        builder.addAll(values);
        SimpleFeature feature = builder.buildFeature(null);
        DefaultFeatureCollection newCollection = new DefaultFeatureCollection();
        newCollection.add(feature);
        return newCollection;
    }
 
Example #11
Source File: FeatureFixedBinNumericStaticticsTest.java    From geowave with Apache License 2.0 6 votes vote down vote up
private SimpleFeature create(final Double val) {
  final List<AttributeDescriptor> descriptors = schema.getAttributeDescriptors();
  final Object[] defaults = new Object[descriptors.size()];
  int p = 0;
  for (final AttributeDescriptor descriptor : descriptors) {
    defaults[p++] = descriptor.getDefaultValue();
  }

  final SimpleFeature newFeature =
      SimpleFeatureBuilder.build(schema, defaults, UUID.randomUUID().toString());

  newFeature.setAttribute("pop", val);
  newFeature.setAttribute("pid", UUID.randomUUID().toString());
  newFeature.setAttribute("when", new Date());
  newFeature.setAttribute("whennot", new Date());
  newFeature.setAttribute("geometry", factory.createPoint(new Coordinate(27.25, 41.25)));
  return newFeature;
}
 
Example #12
Source File: FeatureDataUtils.java    From geowave with Apache License 2.0 6 votes vote down vote up
public static SimpleFeature buildFeature(
    final SimpleFeatureType featureType,
    final Pair<String, Object>[] entries) {

  final List<AttributeDescriptor> descriptors = featureType.getAttributeDescriptors();
  final Object[] defaults = new Object[descriptors.size()];
  int p = 0;
  for (final AttributeDescriptor descriptor : descriptors) {
    defaults[p++] = descriptor.getDefaultValue();
  }
  final SimpleFeature newFeature =
      SimpleFeatureBuilder.build(featureType, defaults, UUID.randomUUID().toString());
  for (final Pair<String, Object> entry : entries) {
    newFeature.setAttribute(entry.getKey(), entry.getValue());
  }
  return newFeature;
}
 
Example #13
Source File: GeometryTranslator.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Builds a line feature from a dwg line.
 * 
 */
public SimpleFeature convertDwgLine( String typeName, String layerName, DwgLine line, int id ) {
    double[] p1 = line.getP1();
    double[] p2 = line.getP2();
    Point2D[] ptos = new Point2D[]{new Point2D.Double(p1[0], p1[1]),
            new Point2D.Double(p2[0], p2[1])};
    CoordinateList coordList = new CoordinateList();
    for( int j = 0; j < ptos.length; j++ ) {
        Coordinate coord = new Coordinate(ptos[j].getX(), ptos[j].getY(), 0.0);
        coordList.add(coord);
    }

    SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
    b.setName(typeName);
    b.setCRS(crs);
    b.add(THE_GEOM, LineString.class);
    b.add(LAYER, String.class);
    SimpleFeatureType type = b.buildFeatureType();
    SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type);
    Geometry lineString = gF.createLineString(coordList.toCoordinateArray());
    Object[] values = new Object[]{lineString, layerName};
    builder.addAll(values);
    return builder.buildFeature(typeName + "." + id);
}
 
Example #14
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 #15
Source File: SplitsProviderIT.java    From geowave with Apache License 2.0 6 votes vote down vote up
public static void createUniformFeatures(
    final SimpleFeatureBuilder pointBuilder,
    final Writer<SimpleFeature> writer,
    final int firstFeatureId) {

  int featureId = firstFeatureId;
  for (int longitude = -180; longitude <= 180; longitude += 1) {
    for (int latitude = -90; latitude <= 90; latitude += 1) {
      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 #16
Source File: MapUtils.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Creates a feature layer based on a map object.
 */
public static Layer createFeatureLayerFromMapObject( InternalMapObject mapObject )
{
    Style style = mapObject.getStyle();
    
    SimpleFeatureType featureType = mapObject.getFeatureType();
    SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder( featureType );
    DefaultFeatureCollection featureCollection = new DefaultFeatureCollection();
    
    featureBuilder.add( mapObject.getGeometry() );
    SimpleFeature feature = featureBuilder.buildFeature( null );

    featureCollection.add( feature );

    return new FeatureLayer( featureCollection, style );
}
 
Example #17
Source File: FeatureNumericHistogramStaticticsTest.java    From geowave with Apache License 2.0 6 votes vote down vote up
private SimpleFeature create(final Double val) {
  final List<AttributeDescriptor> descriptors = schema.getAttributeDescriptors();
  final Object[] defaults = new Object[descriptors.size()];
  int p = 0;
  for (final AttributeDescriptor descriptor : descriptors) {
    defaults[p++] = descriptor.getDefaultValue();
  }

  final SimpleFeature newFeature =
      SimpleFeatureBuilder.build(schema, defaults, UUID.randomUUID().toString());

  newFeature.setAttribute("pop", val);
  newFeature.setAttribute("pid", UUID.randomUUID().toString());
  newFeature.setAttribute("when", new Date());
  newFeature.setAttribute("whennot", new Date());
  newFeature.setAttribute("geometry", factory.createPoint(new Coordinate(27.25, 41.25)));
  return newFeature;
}
 
Example #18
Source File: GeometryTranslator.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Builds a line feature from a dwg polyline 2D.
 * 
 */
public SimpleFeature convertDwgLwPolyline( String typeName, String layerName,
        DwgLwPolyline lwPolyline, int id ) {
    Point2D[] ptos = lwPolyline.getVertices();
    if (ptos != null) {
        CoordinateList coordList = new CoordinateList();
        for( int j = 0; j < ptos.length; j++ ) {
            Coordinate coord = new Coordinate(ptos[j].getX(), ptos[j].getY(), 0.0);
            coordList.add(coord);
        }

        SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
        b.setName(typeName);
        b.setCRS(crs);
        b.add(THE_GEOM, LineString.class);
        b.add(LAYER, String.class);
        SimpleFeatureType type = b.buildFeatureType();
        SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type);
        Geometry lineString = gF.createLineString(coordList.toCoordinateArray());
        Object[] values = new Object[]{lineString, layerName};
        builder.addAll(values);
        return builder.buildFeature(typeName + "." + id);
    }
    return null;
}
 
Example #19
Source File: CentroidManagerGeoWave.java    From geowave with Apache License 2.0 6 votes vote down vote up
@Override
public SimpleFeature toSimpleFeature(final AnalyticItemWrapper<T> item) {
  final SimpleFeature newFeature = SimpleFeatureBuilder.build(type, defaults, item.getID());
  int i = 0;
  for (final Object value : ((SimpleFeature) item.getWrappedItem()).getAttributes()) {
    if (value instanceof Geometry) {
      final Geometry newValue = convert((Geometry) value, shapeClass);
      if (newValue == null) {
        return null;
      }
      newFeature.setAttribute(i++, newValue);
    } else {
      newFeature.setAttribute(i++, value);
    }
  }
  return newFeature;
}
 
Example #20
Source File: TinHandler.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
public SimpleFeatureCollection toFeatureCollectionOthers() {
    SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
    b.setName("points");
    b.setCRS(crs);

    DefaultFeatureCollection newCollection = new DefaultFeatureCollection();
    b.add("the_geom", Point.class);
    b.add("elev", Double.class);
    SimpleFeatureType type = b.buildFeatureType();
    SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type);
    for( Coordinate c : leftOverCoordinateList ) {
        Object[] values = new Object[]{gf.createPoint(c), c.z};
        builder.addAll(values);
        SimpleFeature feature = builder.buildFeature(null);
        newCollection.add(feature);
    }
    return newCollection;
}
 
Example #21
Source File: FeatureWritable.java    From geowave with Apache License 2.0 6 votes vote down vote up
@Override
public void readFields(final DataInput input) throws IOException {
  try {
    final String ns = input.readUTF();
    featureType =
        FeatureDataUtils.decodeType(
            "-".equals(ns) ? "" : ns,
            input.readUTF(),
            input.readUTF(),
            input.readUTF());
  } catch (final SchemaException e) {
    throw new IOException("Failed to parse the encoded feature type", e);
  }
  final SimpleFeatureBuilder builder = new SimpleFeatureBuilder(featureType);
  // read the fid
  final String fid = input.readUTF();
  // read the other attributes, build the feature
  for (final AttributeDescriptor ad : featureType.getAttributeDescriptors()) {
    final Object att = readAttribute(ad, input);
    builder.add(att);
  }

  // build the feature
  feature = builder.buildFeature(fid);
}
 
Example #22
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 #23
Source File: GeoToolsConverterServiceImpl.java    From geomajas-project-server with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public SimpleFeature toSimpleFeature(InternalFeature feature, SimpleFeatureType featureType) {
	SimpleFeatureBuilder builder = new SimpleFeatureBuilder(featureType);
	List<Object> attr = new ArrayList<Object>();

	for (AttributeDescriptor ads : featureType.getAttributeDescriptors()) {
		if (!ads.equals(featureType.getGeometryDescriptor())) {
			Attribute a = feature.getAttributes().get(ads.getName().getLocalPart());
			if (null != a) {
				attr.add(a.getValue());
			} else {
				attr.add(null);
			}
		} else {
			attr.add(feature.getGeometry());
		}
	}

	return builder.buildFeature(feature.getId(), attr.toArray());

}
 
Example #24
Source File: SLDEditorBufferedImageLegendGraphicBuilder.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates a sample Feature instance in the hope that it can be used in the rendering of the
 * legend graphic.
 *
 * @param schema the schema for which to create a sample Feature instance
 * @throws ServiceException
 */
private Feature createSampleFeature(FeatureType schema) throws ServiceException {
    Feature sampleFeature;
    try {
        if (schema instanceof SimpleFeatureType) {
            if (hasMixedGeometry((SimpleFeatureType) schema)) {
                // we can't create a sample for a generic Geometry type
                sampleFeature = null;
            } else {
                sampleFeature = SimpleFeatureBuilder.template((SimpleFeatureType) schema, null);
            }
        } else {
            sampleFeature = DataUtilities.templateFeature(schema);
        }
    } catch (IllegalAttributeException e) {
        throw new ServiceException(e);
    }
    return sampleFeature;
}
 
Example #25
Source File: MonitoringPoint.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Create a featurecollection from a list of monitoringpoints. Based on the position of the
 * points and some of their attributes.
 * 
 * @param monitoringPointsList
 * @return the featurecollection
 */
public SimpleFeatureCollection toFeatureCollection(
        List<MonitoringPoint> monitoringPointsList ) {

    // create the feature type
    SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
    // set the name
    b.setName("monitoringpoints");
    // add a geometry property
    b.add("the_geom", Point.class);
    // add some properties
    b.add("id", Integer.class);
    b.add("relatedid", Integer.class);
    b.add("pfaf", String.class);
    // build the type
    SimpleFeatureType type = b.buildFeatureType();
    // create the feature
    SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type);

    GeometryFactory gF = new GeometryFactory();
    /*
     * insert them in inverse order to get them out of the collection in the same order as the
     * list
     */
    DefaultFeatureCollection newCollection = new DefaultFeatureCollection();
    for( int i = 0; i < monitoringPointsList.size(); i++ ) {
        MonitoringPoint mp = monitoringPointsList.get(monitoringPointsList.size() - i - 1);

        Object[] values = new Object[]{gF.createPoint(mp.getPosition()), mp.getID(),
                mp.getRelatedID(), mp.getPfatstetterNumber().toString()};
        // add the values
        builder.addAll(values);
        // build the feature with provided ID
        SimpleFeature feature = builder.buildFeature(type.getTypeName() + "." + i);
        newCollection.add(feature);
    }

    return newCollection;
}
 
Example #26
Source File: KMeansParallelInitializeTest.java    From geowave with Apache License 2.0 5 votes vote down vote up
private SimpleFeatureBuilder getBuilder() {
  final SimpleFeatureTypeBuilder typeBuilder = new SimpleFeatureTypeBuilder();
  typeBuilder.setName("test");
  typeBuilder.setCRS(DefaultGeographicCRS.WGS84); // <- Coordinate
  // reference
  // add attributes in order
  typeBuilder.add("geom", Geometry.class);
  typeBuilder.add("name", String.class);
  typeBuilder.add("count", Long.class);

  // build the type
  return new SimpleFeatureBuilder(typeBuilder.buildFeatureType());
}
 
Example #27
Source File: TestVectorFieldRounder.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
public void testVectorFieldRounder() throws Exception {

        SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
        b.setName("test");
        b.setCRS(DefaultGeographicCRS.WGS84);
        b.add("the_geom", Point.class);
        b.add("area", Double.class);

        DefaultFeatureCollection newCollection = new DefaultFeatureCollection();
        SimpleFeatureType type = b.buildFeatureType();
        SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type);
        Point point = GeometryUtilities.gf().createPoint(new Coordinate(0, 0));
        Object[] values = new Object[]{point, 123.456789};
        builder.addAll(values);
        SimpleFeature feature = builder.buildFeature(type.getTypeName() + ".0");
        newCollection.add(feature);

        OmsVectorFieldRounder rounder = new OmsVectorFieldRounder();
        rounder.inVector = newCollection;
        rounder.fRound = "area";
        rounder.pPattern = ".##";
        rounder.process();
        SimpleFeatureCollection outFeatures = rounder.outVector;

        SimpleFeature f = FeatureUtilities.featureCollectionToList(outFeatures).get(0);
        String areaStr = f.getAttribute("area").toString();

        assertTrue(areaStr.equals("123.46"));
    }
 
Example #28
Source File: GeometryTranslator.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Builds a line feature from a dwg arc.
 */
public SimpleFeature convertDwgArc( String typeName, String layerName, DwgArc arc, int id ) {
    double[] c = arc.getCenter();
    Point2D center = new Point2D.Double(c[0], c[1]);
    double radius = (arc).getRadius();
    double initAngle = Math.toDegrees((arc).getInitAngle());
    double endAngle = Math.toDegrees((arc).getEndAngle());
    Point2D[] ptos = GisModelCurveCalculator.calculateGisModelArc(center, radius, initAngle,
            endAngle);
    CoordinateList coordList = new CoordinateList();
    for( int j = 0; j < ptos.length; j++ ) {
        Coordinate coord = new Coordinate(ptos[j].getX(), ptos[j].getY(), 0.0);
        coordList.add(coord);
    }

    SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
    b.setName(typeName);
    b.setCRS(crs);
    b.add(THE_GEOM, LineString.class);
    b.add(LAYER, String.class);
    SimpleFeatureType type = b.buildFeatureType();
    SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type);
    Geometry lineString = gF.createLineString(coordList.toCoordinateArray());
    Object[] values = new Object[]{lineString, layerName};
    builder.addAll(values);
    return builder.buildFeature(typeName + "." + id);
}
 
Example #29
Source File: GeoLifeIngestPlugin.java    From geowave with Apache License 2.0 5 votes vote down vote up
public GeoLifeIngestPlugin() {
  geolifePointType = GeoLifeUtils.createGeoLifePointDataType();
  pointKey = GeoLifeUtils.GEOLIFE_POINT_FEATURE;
  geolifePointBuilder = new SimpleFeatureBuilder(geolifePointType);

  geolifeTrackType = GeoLifeUtils.createGeoLifeTrackDataType();
  trackKey = GeoLifeUtils.GEOLIFE_TRACK_FEATURE;
  geolifeTrackBuilder = new SimpleFeatureBuilder(geolifeTrackType);
  try {
    crs = CRS.decode("EPSG:4326");
  } catch (final FactoryException e) {
    LOGGER.error("Unable to decode Coordinate Reference System authority code!", e);
  }
}
 
Example #30
Source File: GeometryTranslator.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
private SimpleFeature createPointTextFeature( String typeName, String layerName, int id,
        Coordinate coord, String textString ) {
    SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
    b.setName(typeName);
    b.setCRS(crs);
    b.add(THE_GEOM, Point.class);
    b.add("text", String.class);
    b.add(LAYER, String.class);
    SimpleFeatureType type = b.buildFeatureType();
    SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type);
    Geometry point = gF.createPoint(coord);
    Object[] values = new Object[]{point, textString, layerName};
    builder.addAll(values);
    return builder.buildFeature(typeName + "." + id);
}