Search in sources :

Example 6 with DefaultFeatureCollection

use of org.geotools.feature.DefaultFeatureCollection in project OpenTripPlanner by opentripplanner.

the class SimpleIsochrone method makePointFeatures.

private SimpleFeatureCollection makePointFeatures() throws Exception {
    Map<Vertex, Double> points = makePoints();
    /* Stage the point features in memory */
    DefaultFeatureCollection featureCollection = new DefaultFeatureCollection(null, pointSchema);
    SimpleFeatureBuilder fbuilder = new SimpleFeatureBuilder(pointSchema);
    GeometryFactory gf = new GeometryFactory();
    for (Map.Entry<Vertex, Double> entry : points.entrySet()) {
        Vertex vertex = entry.getKey();
        Double travelTime = entry.getValue();
        fbuilder.add(gf.createPoint(vertex.getCoordinate()));
        fbuilder.add(travelTime);
        featureCollection.add(fbuilder.buildFeature(null));
    }
    return featureCollection;
}
Also used : StreetVertex(org.opentripplanner.routing.vertextype.StreetVertex) Vertex(org.opentripplanner.routing.graph.Vertex) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) Map(java.util.Map) HashMap(java.util.HashMap) DefaultFeatureCollection(org.geotools.feature.DefaultFeatureCollection) SimpleFeatureBuilder(org.geotools.feature.simple.SimpleFeatureBuilder)

Example 7 with DefaultFeatureCollection

use of org.geotools.feature.DefaultFeatureCollection in project OpenTripPlanner by opentripplanner.

the class SimpleIsochrone method makeContourFeatures.

private SimpleFeatureCollection makeContourFeatures() throws Exception {
    Map<Integer, Geometry> contours = makeContours();
    /* Stage the features in memory, in order from bottom to top, biggest to smallest */
    DefaultFeatureCollection featureCollection = new DefaultFeatureCollection(null, contourSchema);
    SimpleFeatureBuilder fbuilder = new SimpleFeatureBuilder(contourSchema);
    List<Integer> thresholds = new ArrayList<Integer>(contours.keySet());
    Collections.sort(thresholds);
    // Collections.reverse(thresholds);
    for (Integer threshold : thresholds) {
        Geometry contour = contours.get(threshold);
        fbuilder.add(contour);
        fbuilder.add(threshold);
        featureCollection.add(fbuilder.buildFeature(null));
    }
    return featureCollection;
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) ArrayList(java.util.ArrayList) DefaultFeatureCollection(org.geotools.feature.DefaultFeatureCollection) SimpleFeatureBuilder(org.geotools.feature.simple.SimpleFeatureBuilder)

Example 8 with DefaultFeatureCollection

use of org.geotools.feature.DefaultFeatureCollection in project incubator-rya by apache.

the class GeoMesaGeoIndexer method storeStatements.

@Override
public void storeStatements(final Collection<RyaStatement> ryaStatements) throws IOException {
    // create a feature collection
    final DefaultFeatureCollection featureCollection = new DefaultFeatureCollection();
    for (final RyaStatement ryaStatement : ryaStatements) {
        final Statement statement = RyaToRdfConversions.convertStatement(ryaStatement);
        // if the predicate list is empty, accept all predicates.
        // Otherwise, make sure the predicate is on the "valid" list
        final boolean isValidPredicate = validPredicates.isEmpty() || validPredicates.contains(statement.getPredicate());
        if (isValidPredicate && (statement.getObject() instanceof Literal)) {
            try {
                final SimpleFeature feature = createFeature(featureType, statement);
                featureCollection.add(feature);
            } catch (final ParseException e) {
                logger.warn("Error getting geo from statement: " + statement.toString(), e);
            }
        }
    }
    // write this feature collection to the store
    if (!featureCollection.isEmpty()) {
        featureStore.addFeatures(featureCollection);
    }
}
Also used : RyaStatement(org.apache.rya.api.domain.RyaStatement) Statement(org.openrdf.model.Statement) Literal(org.openrdf.model.Literal) RyaStatement(org.apache.rya.api.domain.RyaStatement) ParseException(com.vividsolutions.jts.io.ParseException) DefaultFeatureCollection(org.geotools.feature.DefaultFeatureCollection) SimpleFeature(org.opengis.feature.simple.SimpleFeature)

Example 9 with DefaultFeatureCollection

use of org.geotools.feature.DefaultFeatureCollection in project incubator-rya by apache.

the class GeoWaveGeoIndexer method storeStatements.

@Override
public void storeStatements(final Collection<RyaStatement> ryaStatements) throws IOException {
    // create a feature collection
    final DefaultFeatureCollection featureCollection = new DefaultFeatureCollection();
    for (final RyaStatement ryaStatement : ryaStatements) {
        final Statement statement = RyaToRdfConversions.convertStatement(ryaStatement);
        // if the predicate list is empty, accept all predicates.
        // Otherwise, make sure the predicate is on the "valid" list
        final boolean isValidPredicate = validPredicates.isEmpty() || validPredicates.contains(statement.getPredicate());
        if (isValidPredicate && (statement.getObject() instanceof Literal)) {
            try {
                final SimpleFeature feature = createFeature(featureType, statement);
                featureCollection.add(feature);
            } catch (final ParseException e) {
                logger.warn("Error getting geo from statement: " + statement.toString(), e);
            }
        }
    }
    // write this feature collection to the store
    if (!featureCollection.isEmpty()) {
        featureStore.addFeatures(featureCollection);
    }
}
Also used : RyaStatement(org.apache.rya.api.domain.RyaStatement) Statement(org.openrdf.model.Statement) Literal(org.openrdf.model.Literal) RyaStatement(org.apache.rya.api.domain.RyaStatement) ParseException(com.vividsolutions.jts.io.ParseException) DefaultFeatureCollection(org.geotools.feature.DefaultFeatureCollection) SimpleFeature(org.opengis.feature.simple.SimpleFeature)

Example 10 with DefaultFeatureCollection

use of org.geotools.feature.DefaultFeatureCollection in project incubator-rya by apache.

the class GeoWaveGeoIndexer method deleteStatements.

private void deleteStatements(final Collection<RyaStatement> ryaStatements) throws IOException {
    // create a feature collection
    final DefaultFeatureCollection featureCollection = new DefaultFeatureCollection();
    for (final RyaStatement ryaStatement : ryaStatements) {
        final Statement statement = RyaToRdfConversions.convertStatement(ryaStatement);
        // if the predicate list is empty, accept all predicates.
        // Otherwise, make sure the predicate is on the "valid" list
        final boolean isValidPredicate = validPredicates.isEmpty() || validPredicates.contains(statement.getPredicate());
        if (isValidPredicate && (statement.getObject() instanceof Literal)) {
            try {
                final SimpleFeature feature = createFeature(featureType, statement);
                featureCollection.add(feature);
            } catch (final ParseException e) {
                logger.warn("Error getting geo from statement: " + statement.toString(), e);
            }
        }
    }
    // remove this feature collection from the store
    if (!featureCollection.isEmpty()) {
        final Set<Identifier> featureIds = new HashSet<Identifier>();
        final FilterFactory filterFactory = CommonFactoryFinder.getFilterFactory(null);
        final Set<String> stringIds = DataUtilities.fidSet(featureCollection);
        for (final String id : stringIds) {
            featureIds.add(filterFactory.featureId(id));
        }
        final String filterString = stringIds.stream().collect(Collectors.joining("','", "'", "'"));
        Filter filter = null;
        try {
            filter = ECQL.toFilter(GEO_ID_ATTRIBUTE + " IN (" + filterString + ")", filterFactory);
        } catch (final CQLException e) {
            logger.error("Unable to generate filter for deleting the statement.", e);
        }
        featureStore.removeFeatures(filter);
    }
}
Also used : RyaStatement(org.apache.rya.api.domain.RyaStatement) Statement(org.openrdf.model.Statement) RyaStatement(org.apache.rya.api.domain.RyaStatement) SimpleFeature(org.opengis.feature.simple.SimpleFeature) FilterFactory(org.opengis.filter.FilterFactory) Identifier(org.opengis.filter.identity.Identifier) Filter(org.opengis.filter.Filter) Literal(org.openrdf.model.Literal) ParseException(com.vividsolutions.jts.io.ParseException) CQLException(org.geotools.filter.text.cql2.CQLException) DefaultFeatureCollection(org.geotools.feature.DefaultFeatureCollection) HashSet(java.util.HashSet)

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