Search in sources :

Example 11 with DefaultFeatureCollection

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"));
}
Also used : SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) FeatureVisitor(org.opengis.feature.FeatureVisitor) Point(com.vividsolutions.jts.geom.Point) GeometryBuilder(org.geotools.geometry.jts.GeometryBuilder) SimpleFeature(org.opengis.feature.simple.SimpleFeature) Feature(org.opengis.feature.Feature) DefaultFeatureCollection(org.geotools.feature.DefaultFeatureCollection) SimpleFeature(org.opengis.feature.simple.SimpleFeature) SimpleFeatureBuilder(org.geotools.feature.simple.SimpleFeatureBuilder)

Example 12 with DefaultFeatureCollection

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())));
}
Also used : SimpleFeatureImpl(org.geotools.feature.simple.SimpleFeatureImpl) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) DefaultFeatureCollection(org.geotools.feature.DefaultFeatureCollection)

Example 13 with DefaultFeatureCollection

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;
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) FeatureToGeoJsonJacksonMapper(eu.europa.ec.fisheries.uvms.commons.geometry.mapper.FeatureToGeoJsonJacksonMapper) IOException(java.io.IOException) DefaultFeatureCollection(org.geotools.feature.DefaultFeatureCollection) SimpleFeature(org.opengis.feature.simple.SimpleFeature)

Example 14 with DefaultFeatureCollection

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);
}
Also used : Serializable(java.io.Serializable) GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) ShapefileDataStore(org.geotools.data.shapefile.ShapefileDataStore) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) HashMap(java.util.HashMap) ShapefileDataStoreFactory(org.geotools.data.shapefile.ShapefileDataStoreFactory) File(java.io.File) DefaultFeatureCollection(org.geotools.feature.DefaultFeatureCollection)

Example 15 with DefaultFeatureCollection

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);
}
Also used : FeatureLayer(org.geotools.map.FeatureLayer) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) Style(org.geotools.styling.Style) DefaultFeatureCollection(org.geotools.feature.DefaultFeatureCollection) SimpleFeature(org.opengis.feature.simple.SimpleFeature) SimpleFeatureBuilder(org.geotools.feature.simple.SimpleFeatureBuilder)

Aggregations

DefaultFeatureCollection (org.geotools.feature.DefaultFeatureCollection)15 SimpleFeature (org.opengis.feature.simple.SimpleFeature)8 SimpleFeatureBuilder (org.geotools.feature.simple.SimpleFeatureBuilder)6 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)6 ParseException (com.vividsolutions.jts.io.ParseException)4 RyaStatement (org.apache.rya.api.domain.RyaStatement)4 Literal (org.openrdf.model.Literal)4 Statement (org.openrdf.model.Statement)4 Geometry (com.vividsolutions.jts.geom.Geometry)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 Identifier (org.opengis.filter.identity.Identifier)3 GeometryFactory (com.vividsolutions.jts.geom.GeometryFactory)2 Serializable (java.io.Serializable)2 ArrayList (java.util.ArrayList)2 ShapefileDataStore (org.geotools.data.shapefile.ShapefileDataStore)2 ShapefileDataStoreFactory (org.geotools.data.shapefile.ShapefileDataStoreFactory)2 GeometryBuilder (org.geotools.geometry.jts.GeometryBuilder)2 Filter (org.opengis.filter.Filter)2 FilterFactory (org.opengis.filter.FilterFactory)2