private SimpleFeatureCollection filteredCollection( Geometry currentGeom, SimpleFeatureCollection subFeatureCollection) { FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(null); Filter intersectFilter = ff.intersects(ff.property(dataGeomName), ff.literal(currentGeom)); SimpleFeatureCollection subFeatureCollectionIntersection = this.subFeatureCollection.subCollection(intersectFilter); if (subFeatureCollectionIntersection.size() == 0) { subFeatureCollectionIntersection = subFeatureCollection; } return subFeatureCollectionIntersection; } }
protected Filter intersection(Filter a, Filter b) { if (a == null) return b; if (b == null) return a; if (a == Filter.INCLUDE && b == Filter.INCLUDE) { return Filter.INCLUDE; } else if (a == Filter.EXCLUDE || b == Filter.EXCLUDE) { return Filter.EXCLUDE; } else { return factory.and(a, b); } }
Object cloneFilter( BinarySpatialOperator bso, Object extraData, Expression ex1, Expression ex2) { return ff.equal(ex1, ex2); } }.transform(filter, extraData);
@Override public Object visit(Id filter, Object extraData) { Set<Identifier> identifiers = filter.getIdentifiers(); Set<Identifier> renamedIdentifiers = identifiers .stream() .map( id -> { String name = id.getID().toString(); if (name.startsWith(prefix)) { name = name.substring(prefix.length()); } return getFactory(extraData).featureId(name); }) .collect(Collectors.toSet()); return getFactory(extraData).id(renamedIdentifiers); } }
@Test public void testFilter() throws Exception { FilterFactory2 filterFactory = CommonFactoryFinder.getFilterFactory2(); StyleFactory styleFactory = CommonFactoryFinder.getStyleFactory(); StyledLayerDescriptor sld = styleFactory.createStyledLayerDescriptor(); UserLayer layer = styleFactory.createUserLayer(); sld.layers().add(layer); Style style = styleFactory.createStyle(); layer.userStyles().add(style); Rule rule = styleFactory.createRule(); rule.setFilter(filterFactory.less(filterFactory.property("foo"), filterFactory.literal(2))); style.featureTypeStyles().add(styleFactory.createFeatureTypeStyle()); style.featureTypeStyles().get(0).rules().add(rule); PointSymbolizer p = styleFactory.createPointSymbolizer(); rule.symbolizers().add((Symbolizer) p); StringWriter out = new StringWriter(); Ysld.encode(sld, out); YamlMap obj = new YamlMap(YamlUtil.getSafeYaml().load(out.toString())); YamlMap result = obj.seq("feature-styles").map(0).seq("rules").map(0); assertThat(result, yHasEntry("filter", equalTo("${foo < 2}"))); }
private Style createEnvMinMaxCoverageStyle(String bandName) { StyleFactory sf = CommonFactoryFinder.getStyleFactory(null); FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(null); ContrastEnhancement ce = sf.contrastEnhancement(ff.literal(1.0), ContrastMethod.NORMALIZE); ce.addOption("algorithm", ff.literal("StretchToMinimumMaximum")); ce.addOption("minValue", ff.function("env", ff.literal("range_min"), ff.literal(0))); ce.addOption("maxValue", ff.function("env", ff.literal("range_max"), ff.literal(220))); SelectedChannelType sct = sf.createSelectedChannelType(bandName, ce); RasterSymbolizer sym = sf.getDefaultRasterSymbolizer(); ChannelSelection sel = sf.channelSelection(sct); sym.setChannelSelection(sel); return SLD.wrapSymbolizers(sym); } }
@Test public void testAndDisjoint() { Coordinate[] coords = new Coordinate[] {new Coordinate(0, 0), new Coordinate(10, 10)}; LineString lineString = new GeometryFactory().createLineString(coords); Filter filter = ff.disjoint(ff.property("name"), ff.literal(lineString)); filter = ff.and(filter, ff.bbox(ff.property("geom"), 50, 50, 150, 150, null)); Envelope env = (Envelope) filter.accept(visitor, null); assertEquals(new Envelope(50, 150, 50, 150), env); }
protected Expression optimize(Expression expression, Object extraData, Class targetType) { if (expression instanceof Literal && targetType != null) { // perform the conversion and return the optimized literal Object converted = expression.evaluate(null, targetType); if (converted != null) { return ff.literal(converted); } } // in case we could not optimize, just duplicate return visit(expression, extraData); }
public void testIdFinderFilterVisitor() { Filter filter = ff.isNull(ff.property("name")); boolean found = (Boolean) filter.accept(new IdFinderFilterVisitor(), null); assertFalse(found); filter = ff.id(Collections.singleton(ff.featureId("eclesia"))); found = (Boolean) filter.accept(new IdFinderFilterVisitor(), null); assertTrue(found); }
@Test public void testEmbededExpressionEscapeExpression() throws Exception { PointSymbolizer p = CommonFactoryFinder.getStyleFactory().createPointSymbolizer(); Expression expression = CommonFactoryFinder.getFilterFactory2() .function( "strEndsWith", CommonFactoryFinder.getFilterFactory2().property("attribute1"), CommonFactoryFinder.getFilterFactory2().literal("}")); p.setGeometry(expression); StringWriter out = new StringWriter(); Ysld.encode(sld(p), out); YamlMap obj = new YamlMap(YamlUtil.getSafeYaml().load(out.toString())); String result = obj.seq("feature-styles") .map(0) .seq("rules") .map(0) .seq("symbolizers") .map(0) .map("point") .str("geometry"); assertThat(result, equalTo("${strEndsWith(attribute1,'\\}')}")); }
@Test public void testIntersects() { ff.intersects(ff.property("geom"), ff.literal(null)).accept(visitor, null); assertTrue(visitor.hasSpatialFilter); }
@Test public void testNonNameExpressionAttribute() throws Exception { PointSymbolizer p = CommonFactoryFinder.getStyleFactory().createPointSymbolizer(); Expression expression = CommonFactoryFinder.getFilterFactory2().property("test"); p.setGeometry(expression); StringWriter out = new StringWriter(); Ysld.encode(sld(p), out); YamlMap obj = new YamlMap(YamlUtil.getSafeYaml().load(out.toString())); String result = obj.seq("feature-styles") .map(0) .seq("rules") .map(0) .seq("symbolizers") .map(0) .map("point") .str("geometry"); assertThat(result, equalTo("${test}")); }
@Test public void testFunction() throws Exception { Function fe = ff.function( "strIndexOf", ff.property("/measurement/determinand_description"), ff.literal("determinand_description_1")); List unrolledExpressions = (List) fe.accept(visitor, null); Expression unmapped = (Expression) unrolledExpressions.get(0); assertTrue(unmapped instanceof Function); List params = ((Function) unmapped).getParameters(); assertEquals(2, params.size()); assertTrue(params.get(0) instanceof PropertyName); assertEquals("determinand_description", ((PropertyName) params.get(0)).getPropertyName()); }
@Test public void testAndTemporalBetween() throws Exception { final Instant start = instant("2016-01-01T00:00:00.000-0500"); final Instant end = instant("2106-01-02T00:00:00.000-0500"); final Filter f = ff.and( ff.bbox("geom", -10, -10, 10, 10, null), ff.between(ff.literal("someDate"), ff.literal(start), ff.literal(end))); final Envelope env = (Envelope) f.accept(visitor, null); assertEquals(new Envelope(-10, 10, -10, 10), env); }
@BeforeClass public static void setUpBeforeClass() throws Exception { ff = CommonFactoryFinder.getFilterFactory2(null); filters = new Filters(ff); a = ff.greater(ff.property("zone"), ff.literal(7)); b = ff.like(ff.property("suburb"), "N%"); c = ff.equals(ff.property("Subject"), ff.literal("foo")); d = ff.equals(ff.property("Subject"), ff.literal("bar")); }