use of org.geotools.feature.DefaultFeatureCollection in project polymap4-core by Polymap4.
the class RFeatureStoreTests method testCreateSimpleSchemaAndFeature.
public void testCreateSimpleSchemaAndFeature() throws Exception {
log.debug("creating schema...");
SimpleFeatureType schema = createSimpleSchema();
ds.createSchema(schema);
RFeatureStore fs = (RFeatureStore) ds.getFeatureSource(schema.getName());
assertEquals(0, Iterables.size(iterable(fs.getFeatures())));
// add feature
SimpleFeatureBuilder fb = new SimpleFeatureBuilder(schema);
Point point = new GeometryBuilder().point(10, 100);
fb.set("name", "value");
fb.set("geom", point);
DefaultFeatureCollection features = new DefaultFeatureCollection();
features.add(fb.buildFeature(null));
fs.addFeatures(features);
// check size
assertEquals(1, Iterables.size(iterable(fs.getFeatures())));
// check properties
fs.getFeatures().accepts(new FeatureVisitor() {
public void visit(Feature feature) {
log.debug("Feature: " + feature);
assertEquals("value", ((SimpleFeature) feature).getAttribute("name"));
assertEquals(point, ((SimpleFeature) feature).getAttribute("geom"));
assertEquals(point, ((SimpleFeature) feature).getDefaultGeometry());
}
}, null);
// modify property
Feature feature = Iterables.getOnlyElement(iterable(fs.getFeatures()));
fs.modifyFeatures((AttributeDescriptor) feature.getProperty("name").getDescriptor(), "changed", ff.id(Collections.singleton(feature.getIdentifier())));
Feature feature2 = Iterables.getOnlyElement(iterable(fs.getFeatures()));
assertEquals("changed", ((SimpleFeature) feature2).getAttribute("name"));
}
use of org.geotools.feature.DefaultFeatureCollection in project polymap4-core by Polymap4.
the class RFeatureStoreTests method testCreateSimpleSchemaAndFeatureWithoutId.
public void testCreateSimpleSchemaAndFeatureWithoutId() throws Exception {
log.debug("creating schema...");
SimpleFeatureType schema = createSimpleSchema();
ds.createSchema(schema);
RFeatureStore fs = (RFeatureStore) ds.getFeatureSource(schema.getName());
assertEquals(0, Iterables.size(iterable(fs.getFeatures())));
// add feature
// SimpleFeatureBuilder always creates a default id
DefaultFeatureCollection features = new DefaultFeatureCollection();
features.add(new SimpleFeatureImpl(Lists.newArrayList("value", null), schema, null));
fs.addFeatures(features);
// check size
assertEquals(1, Iterables.size(iterable(fs.getFeatures())));
}
use of org.geotools.feature.DefaultFeatureCollection in project UVMS-ActivityModule-APP by UnionVMS.
the class FishingTripToGeoJsonMapper method toJson.
// Convert Geometry list into GEO JSON format
public static ObjectNode toJson(List<Geometry> geoList) {
ObjectNode rootNode = null;
DefaultFeatureCollection trips = new DefaultFeatureCollection(null, build());
for (Geometry geo : geoList) {
SimpleFeature feature = toFeature(geo);
trips.add(feature);
}
try {
rootNode = new FeatureToGeoJsonJacksonMapper().convert(trips);
} catch (IOException e) {
log.error("Error while trying to convert fishing trips to Geo JSON", e);
}
return rootNode;
}
use of org.geotools.feature.DefaultFeatureCollection in project tutorials by eugenp.
the class ShapeFile method main.
public static void main(String[] args) throws Exception {
DefaultFeatureCollection collection = new DefaultFeatureCollection();
GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory(null);
SimpleFeatureType TYPE = DataUtilities.createType("Location", "location:Point:srid=4326," + "name:String");
SimpleFeatureType CITY = createFeatureType();
addLocations(CITY, collection);
File shapeFile = getNewShapeFile();
ShapefileDataStoreFactory dataStoreFactory = new ShapefileDataStoreFactory();
Map<String, Serializable> params = new HashMap<String, Serializable>();
ShapefileDataStore dataStore = setDataStoreParams(dataStoreFactory, params, shapeFile, CITY);
writeToFile(dataStore, collection);
}
use of org.geotools.feature.DefaultFeatureCollection in project dhis2-core by dhis2.
the class MapUtils method createFeatureLayerFromMapObject.
/**
* 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);
}
Aggregations