Search in sources :

Example 6 with Query

use of org.geotools.data.Query in project GeoGig by boundlessgeo.

the class GeoGigFeatureSourceTest method testGetFeaturesFilter.

@Test
public void testGetFeaturesFilter() throws Exception {
    SimpleFeatureCollection collection;
    Set<List<Object>> actual;
    Set<List<Object>> expected;
    Filter filter;
    filter = ff.id(Collections.singleton(ff.featureId(RepositoryTestCase.idP2)));
    collection = pointsSource.getFeatures(new Query(pointsName, filter));
    actual = Sets.newHashSet();
    for (SimpleFeature f : toList(collection)) {
        actual.add(f.getAttributes());
    }
    expected = Collections.singleton(((SimpleFeature) points2).getAttributes());
    assertEquals(expected, actual);
    ReferencedEnvelope queryBounds = boundsOf(points1, points2);
    Polygon geometry = JTS.toGeometry(queryBounds);
    filter = ff.intersects(ff.property(pointsType.getGeometryDescriptor().getLocalName()), ff.literal(geometry));
    collection = pointsSource.getFeatures(new Query(pointsName, filter));
    actual = Sets.newHashSet();
    for (SimpleFeature f : toList(collection)) {
        actual.add(f.getAttributes());
    }
    expected = ImmutableSet.of(((SimpleFeature) points1).getAttributes(), ((SimpleFeature) points2).getAttributes());
    assertEquals(expected, actual);
    ReferencedEnvelope transformedQueryBounds;
    CoordinateReferenceSystem queryCrs = CRS.decode("EPSG:3857");
    transformedQueryBounds = queryBounds.transform(queryCrs, true);
    geometry = JTS.toGeometry(transformedQueryBounds);
    geometry.setUserData(queryCrs);
    filter = ff.intersects(ff.property(pointsType.getGeometryDescriptor().getLocalName()), ff.literal(geometry));
    collection = pointsSource.getFeatures(new Query(pointsName, filter));
    actual = Sets.newHashSet();
    for (SimpleFeature f : toList(collection)) {
        actual.add(f.getAttributes());
    }
    expected = ImmutableSet.of(((SimpleFeature) points1).getAttributes(), ((SimpleFeature) points2).getAttributes());
    assertEquals(expected.size(), actual.size());
    assertEquals(expected, actual);
    filter = ECQL.toFilter("sp = 'StringProp2_3' OR ip = 2000");
    collection = linesSource.getFeatures(new Query(linesName, filter));
    actual = Sets.newHashSet();
    for (SimpleFeature f : toList(collection)) {
        actual.add(f.getAttributes());
    }
    expected = ImmutableSet.of(((SimpleFeature) lines2).getAttributes(), ((SimpleFeature) lines3).getAttributes());
    assertEquals(expected, actual);
}
Also used : ReferencedEnvelope(org.geotools.geometry.jts.ReferencedEnvelope) Query(org.geotools.data.Query) Filter(org.opengis.filter.Filter) List(java.util.List) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) Polygon(com.vividsolutions.jts.geom.Polygon) SimpleFeature(org.opengis.feature.simple.SimpleFeature) SimpleFeatureCollection(org.geotools.data.simple.SimpleFeatureCollection) Test(org.junit.Test)

Example 7 with Query

use of org.geotools.data.Query in project GeoGig by boundlessgeo.

the class ImportOp method insert.

private void insert(final WorkingTree workTree, final String path, @SuppressWarnings("rawtypes") final FeatureSource featureSource, final ProgressListener taskProgress) {
    final Query query = new Query();
    CoordinateSequenceFactory coordSeq = new PackedCoordinateSequenceFactory();
    query.getHints().add(new Hints(Hints.JTS_COORDINATE_SEQUENCE_FACTORY, coordSeq));
    workTree.insert(path, featureSource, query, taskProgress);
}
Also used : Query(org.geotools.data.Query) Hints(org.geotools.factory.Hints) CoordinateSequenceFactory(com.vividsolutions.jts.geom.CoordinateSequenceFactory) PackedCoordinateSequenceFactory(com.vividsolutions.jts.geom.impl.PackedCoordinateSequenceFactory) PackedCoordinateSequenceFactory(com.vividsolutions.jts.geom.impl.PackedCoordinateSequenceFactory)

Aggregations

Query (org.geotools.data.Query)7 Test (org.junit.Test)5 Polygon (com.vividsolutions.jts.geom.Polygon)3 ReferencedEnvelope (org.geotools.geometry.jts.ReferencedEnvelope)3 SimpleFeature (org.opengis.feature.simple.SimpleFeature)3 Filter (org.opengis.filter.Filter)3 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)3 FeatureSource (org.geotools.data.FeatureSource)2 ForwardingFeatureSource (org.locationtech.geogig.api.data.ForwardingFeatureSource)2 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)2 CoordinateSequenceFactory (com.vividsolutions.jts.geom.CoordinateSequenceFactory)1 Geometry (com.vividsolutions.jts.geom.Geometry)1 LineString (com.vividsolutions.jts.geom.LineString)1 PackedCoordinateSequenceFactory (com.vividsolutions.jts.geom.impl.PackedCoordinateSequenceFactory)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 List (java.util.List)1 DefaultTransaction (org.geotools.data.DefaultTransaction)1 QueryCapabilities (org.geotools.data.QueryCapabilities)1 Transaction (org.geotools.data.Transaction)1