/** * Returns the feature collection for the features which match the specified filter. * * <p>This method calls through to {@link #getFeatures(Query)}. */ public final ContentFeatureCollection getFeatures(Filter filter) throws IOException { return getFeatures(new Query(getSchema().getTypeName(), filter)); }
public void testGetFeaturesWithInvalidFilter() throws Exception { FilterFactory ff = CommonFactoryFinder.getFilterFactory(null); PropertyIsEqualTo f = ff.equals(ff.property("invalidAttribute"), ff.literal(5)); // make sure a complaint related to the invalid filter is thrown here try (SimpleFeatureIterator fi = featureSource.getFeatures(f).features()) { fail("This query should have failed, it contains an invalid filter"); } catch (Exception e) { java.util.logging.Logger.getGlobal().log(java.util.logging.Level.INFO, "", e); // fine } }
public void testBboxFilterDefault() throws Exception { FilterFactory ff = CommonFactoryFinder.getFilterFactory(null); // should match only "r2" BBOX bbox = ff.bbox("", 2, 3, 4, 5, "EPSG:4326"); FeatureCollection features = dataStore.getFeatureSource(tname("road")).getFeatures(bbox); checkSingleResult(features, "r2"); }
public void testBboxFilter() throws Exception { FilterFactory ff = CommonFactoryFinder.getFilterFactory(null); // should match only "r2" BBOX bbox = ff.bbox(aname("geom"), 2, 3, 4, 5, "EPSG:4326"); FeatureCollection features = dataStore.getFeatureSource(tname("road")).getFeatures(bbox); checkSingleResult(features, "r2"); }
public void testNaturalSortingAsc() throws Exception { Query q = new Query(featureSource.getSchema().getTypeName()); q.setSortBy(new SortBy[] {SortBy.NATURAL_ORDER}); try (SimpleFeatureIterator features = featureSource.getFeatures(q).features()) { String prevId = null; while (features.hasNext()) { String currId = features.next().getID(); if (prevId != null) assertTrue(prevId.compareTo(currId) <= 0); prevId = currId; } } }
public void testNaturalSortingdesc() throws Exception { Query q = new Query(featureSource.getSchema().getTypeName()); q.setSortBy(new SortBy[] {SortBy.REVERSE_ORDER}); try (SimpleFeatureIterator features = featureSource.getFeatures(q).features()) { String prevId = null; while (features.hasNext()) { String currId = features.next().getID(); if (prevId != null) assertTrue(prevId.compareTo(currId) >= 0); prevId = currId; } } }
public void testGetFeaturesWithInvalidQuery() { FilterFactory ff = CommonFactoryFinder.getFilterFactory(null); PropertyIsEqualTo f = ff.equals(ff.property("invalidAttribute"), ff.literal(5)); // make sure a complaint related to the invalid filter is thrown here try (SimpleFeatureIterator fi = featureSource.getFeatures(new Query("ft1", f)).features()) { fail("This query should have failed, it contains an invalid filter"); } catch (Exception e) { // e.printStackTrace(); // fine } }
private SimpleFeatureCollection createLineFeatureCollection() throws Exception { AttributeDescriptor[] types = new AttributeDescriptor[2]; GeometryFactory geomFac = new GeometryFactory(); CoordinateReferenceSystem crs = DefaultGeographicCRS.WGS84; MemoryDataStore data = new MemoryDataStore(); data.addFeature(createLineFeature("LongLabel1", crs, geomFac, 10, 0, 0, 10)); data.addFeature(createLineFeature("LongLabel2", crs, geomFac, 10, 10, 0, 0)); // data.addFeature(createPointFeature(0,2,"LongLabel3",crs, geomFac, types)); // data.addFeature(createPointFeature(2,0,"Label4",crs, geomFac, types)); // data.addFeature(createPointFeature(0,4,"LongLabel6",crs, geomFac, types)); return data.getFeatureSource(Rendering2DTest.LINE).getFeatures(); }
public void testBBOX3DOutsideLine() throws Exception { // a bbox 3d well outside the line footprint BBOX3D bbox3d = FF.bbox("", new ReferencedEnvelope3D(2, 3, 1, 2, 100, 101, crs)); SimpleFeatureCollection fc = dataStore.getFeatureSource(tname(getLine3d())).getFeatures(bbox3d); assertEquals(0, fc.size()); }
private void assertDWithinFilter(int expectedMatches, double distance, String unit) throws IOException { FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(null); final PropertyName geomProperty = ff.property(aname("geometry")); final ContentFeatureSource features = dataStore.getFeatureSource(tname("ft1")); // too short distance DWithin filter = ff.dwithin(geomProperty, ff.literal(REFERENCE_POINT), distance, unit); FeatureCollection fc = features.getFeatures(filter); assertEquals(expectedMatches, fc.size()); }
public void testReadFeatures() throws Exception { SimpleFeatureCollection fc = dataStore.getFeatureSource(tname(LAKESVIEW)).getFeatures(); assertEquals(1, fc.size()); try (SimpleFeatureIterator fr = fc.features()) { assertTrue(fr.hasNext()); SimpleFeature f = fr.next(); assertFalse(fr.hasNext()); } }
private SimpleFeatureCollection createPointFeatureCollection() throws Exception { AttributeDescriptor[] types = new AttributeDescriptor[2]; GeometryFactory geomFac = new GeometryFactory(); CoordinateReferenceSystem crs = DefaultGeographicCRS.WGS84; MemoryDataStore data = new MemoryDataStore(); data.addFeature(createPointFeature(2, 2, "LongLabel1", crs, geomFac, types)); data.addFeature(createPointFeature(4, 4, "LongLabel2", crs, geomFac, types)); data.addFeature(createPointFeature(0, 4, "LongLabel3", crs, geomFac, types)); // data.addFeature(createPointFeature(2,0,"Label4",crs, geomFac, types)); data.addFeature(createPointFeature(2, 6, "LongLabel6", crs, geomFac, types)); return data.getFeatureSource(Rendering2DTest.POINT).getFeatures(); }
public void testEqualsFilter() throws Exception { FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(null); // should match only "r3" GeometryFactory gf = new GeometryFactory(); Geometry g = gf.createGeometry((Geometry) td.roadFeatures[2].getDefaultGeometry()); Equals cs = ff.equal(ff.literal(g), ff.property(aname("geom"))); FeatureCollection features = dataStore.getFeatureSource(tname("road")).getFeatures(cs); checkSingleResult(features, "r3"); }
public void testReadPoint() throws Exception { SimpleFeatureCollection fc = dataStore.getFeatureSource(tname(getPoint3d())).getFeatures(); try (SimpleFeatureIterator fr = fc.features()) { assertTrue(fr.hasNext()); Point p = (Point) fr.next().getDefaultGeometry(); assertTrue(new Coordinate(1, 1, 1).equals(p.getCoordinate())); } }
public void testTouchesFilter() throws Exception { FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(null); // should match only "r1" GeometryFactory gf = new GeometryFactory(); PackedCoordinateSequenceFactory sf = new PackedCoordinateSequenceFactory(); LineString ls = gf.createLineString(sf.create(new double[] {1, 1, 1, 3}, 2)); Touches is = ff.touches(ff.property(aname("geom")), ff.literal(ls)); FeatureCollection features = dataStore.getFeatureSource(tname("road")).getFeatures(is); checkSingleResult(features, "r1"); }
public void testIntersectsRingFilter() throws Exception { FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(null); // should match only "r1" GeometryFactory gf = new GeometryFactory(); PackedCoordinateSequenceFactory sf = new PackedCoordinateSequenceFactory(); LineString ls = gf.createLinearRing(sf.create(new double[] {2, 1, 2, 3, 0, 3, 2, 1}, 2)); Intersects is = ff.intersects(ff.property(aname("geom")), ff.literal(ls)); FeatureCollection features = dataStore.getFeatureSource(tname("road")).getFeatures(is); checkSingleResult(features, "r1"); }
public void testWriteFeatures() throws Exception { try (FeatureWriter fw = dataStore.getFeatureWriterAppend(tname(PERSON), Transaction.AUTO_COMMIT)) { SimpleFeature f = (SimpleFeature) fw.next(); f.setAttribute(aname("name"), "Joe"); f.setAttribute(aname("age"), 27); fw.write(); } FeatureCollection fc = dataStore.getFeatureSource(tname(PERSON)).getFeatures(); assertEquals(3, fc.size()); } }
public void testRead() throws Exception { SimpleFeatureType type = dataStore.getSchema(tname("udt")); SimpleFeatureCollection features = dataStore.getFeatureSource(tname("udt")).getFeatures(); try (SimpleFeatureIterator fi = features.features()) { assertTrue(fi.hasNext()); assertEquals("12ab", fi.next().getAttribute(aname("ut"))); assertFalse(fi.hasNext()); } }
public void testReadFeatures() throws Exception { SimpleFeatureCollection fc = dataStore.getFeatureSource(tname(PERSON)).getFeatures(); assertEquals(2, fc.size()); try (SimpleFeatureIterator fr = fc.features()) { assertTrue(fr.hasNext()); SimpleFeature f = fr.next(); assertTrue(fr.hasNext()); f = fr.next(); assertFalse(fr.hasNext()); } }
public void testContainsFilter() throws Exception { FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(null); // should match only "r2" GeometryFactory gf = new GeometryFactory(); PackedCoordinateSequenceFactory sf = new PackedCoordinateSequenceFactory(); LinearRing shell = gf.createLinearRing(sf.create(new double[] {2, -1, 2, 5, 4, 5, 4, -1, 2, -1}, 2)); Polygon polygon = gf.createPolygon(shell, null); Contains cs = ff.contains(ff.literal(polygon), ff.property(aname("geom"))); FeatureCollection features = dataStore.getFeatureSource(tname("road")).getFeatures(cs); checkSingleResult(features, "r2"); }