本文整理了Java中org.geotools.styling.Rule.setFilter
方法的一些代码示例,展示了Rule.setFilter
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Rule.setFilter
方法的具体详情如下:
包路径:org.geotools.styling.Rule
类名称:Rule
方法名:setFilter
[英]Filter used to select content for this rule to display.
This filter is only consulted if isElseFilter is false.
[中]用于选择要显示此规则的内容的筛选器。
只有当isElseFilter为false时,才会参考此筛选器。
代码示例来源:origin: geotools/geotools
/**
* Reprojects spatial filters so that they match the feature source native CRS, and assuming all
* literal geometries are specified in the specified declaredCRS
*/
private Rule reprojectSpatialFilters(
Rule rule, CoordinateReferenceSystem declaredCRS, FeatureType schema) {
// NPE avoidance
Filter filter = rule.getFilter();
if (filter == null) {
return rule;
}
// try to reproject the filter
Filter reprojected = reprojectSpatialFilter(declaredCRS, schema, filter);
if (reprojected == filter) {
return rule;
}
// clone the rule (the style can be reused over and over, we cannot alter it) and set the
// new filter
Rule rr = new RuleImpl(rule);
rr.setFilter(reprojected);
return rr;
}
代码示例来源:origin: geotools/geotools
} else if (childName.equalsIgnoreCase("Filter")) {
Filter filter = parseFilter(child);
rule.setFilter(filter);
} else if (childName.equalsIgnoreCase("ElseFilter")) {
rule.setElseFilter(true);
代码示例来源:origin: geotools/geotools
rule.setFilter(filters.get(0));
} else if (filters.size() > 1) {
rule.setFilter(ff.or(filters));
代码示例来源:origin: geotools/geotools
public Rule build() {
if (unset) {
return null;
}
if (symbolizerBuilder == null && symbolizers.size() == 0) {
symbolizerBuilder = new PointSymbolizerBuilder();
}
if (symbolizerBuilder != null) {
symbolizers.add(symbolizerBuilder.build());
}
Rule rule = sf.createRule();
rule.setName(name);
// TODO: rule's description cannot be set
rule.setTitle(title);
rule.setAbstract(ruleAbstract);
rule.setMinScaleDenominator(minScaleDenominator);
rule.setMaxScaleDenominator(maxScaleDenominator);
rule.setFilter(filter);
rule.setElseFilter(elseFilter);
rule.symbolizers().addAll(symbolizers);
GraphicLegend gl = legend.build();
if (gl != null) {
rule.setLegend(gl);
}
if (parent == null) {
reset();
}
return rule;
}
代码示例来源:origin: geotools/geotools
@Test
public void testSpatialDefaulterForceEPSG() throws Exception {
// a spatial filter in the same SRS as the geometry... but with a different axis order
// interpretation, if we assume lat/lon we should pick point.4
StyleBuilder sb = new StyleBuilder();
Symbolizer ps = sb.createPointSymbolizer();
Style style = sb.createStyle(ps);
Rule rule = style.featureTypeStyles().get(0).rules().get(0);
rule.setFilter(ff.bbox("geom", 5, 1, 7, 3, null));
// force EPSG axis order interpretation
renderer.setRendererHints(
Collections.singletonMap(StreamingRenderer.FORCE_EPSG_AXIS_ORDER_KEY, true));
content.addLayer(new FeatureLayer(pointFS, style));
RendererBaseTest.showRender("Spatial in EPSG order", renderer, TIME, bounds);
assertEquals(1, renderedIds.size());
assertEquals("point.4", renderedIds.iterator().next());
}
代码示例来源:origin: geotools/geotools
@Test
public void testSpatialDefaulter() throws Exception {
// a spatial filter in the same SRS as the geometry
StyleBuilder sb = new StyleBuilder();
PolygonSymbolizer ps = sb.createPolygonSymbolizer();
Style style = sb.createStyle(ps);
Rule rule = style.featureTypeStyles().get(0).rules().get(0);
rule.setFilter(ff.bbox("geom", 1, 1, 4, 4, null));
content.addLayer(new FeatureLayer(squareFS, style));
RendererBaseTest.showRender("Spatial without CRS", renderer, TIME, bounds);
assertEquals(2, renderedIds.size());
}
代码示例来源:origin: geotools/geotools
@Test
public void testSpatialNoReprojection() throws Exception {
// a spatial filter in the same SRS as the geometry
StyleBuilder sb = new StyleBuilder();
PolygonSymbolizer ps = sb.createPolygonSymbolizer();
Style style = sb.createStyle(ps);
Rule rule = style.featureTypeStyles().get(0).rules().get(0);
rule.setFilter(ff.bbox("geom", 1, 1, 4, 4, "EPSG:4326"));
content.addLayer(new FeatureLayer(squareFS, style));
RendererBaseTest.showRender("Spatial with default CRS", renderer, TIME, bounds);
assertEquals(2, renderedIds.size());
}
代码示例来源:origin: geotools/geotools
@Test
public void testReprojectedPolygon() throws Exception {
// a spatial filter in a different SRS
CoordinateReferenceSystem utm31n = CRS.decode("EPSG:32631");
CoordinateReferenceSystem wgs84 = CRS.decode("EPSG:4326");
ReferencedEnvelope envWgs84 = new ReferencedEnvelope(1, 3, 5, 7, wgs84);
ReferencedEnvelope envUTM31N = envWgs84.transform(utm31n, true);
StyleBuilder sb = new StyleBuilder();
Symbolizer ps = sb.createPointSymbolizer();
Style style = sb.createStyle(ps);
Rule rule = style.featureTypeStyles().get(0).rules().get(0);
Polygon polygon = JTS.toGeometry(envUTM31N);
polygon.setUserData(utm31n);
rule.setFilter(ff.intersects(ff.property("geom"), ff.literal(polygon)));
content.addLayer(new FeatureLayer(pointFS, style));
RendererBaseTest.showRender("Reprojected polygon", renderer, TIME, bounds);
assertEquals(1, renderedIds.size());
assertEquals("point.4", renderedIds.iterator().next());
}
代码示例来源:origin: geotools/geotools
@Test
public void testReprojectedBBOX() throws Exception {
// a spatial filter in a different SRS
CoordinateReferenceSystem utm31n = CRS.decode("EPSG:32631");
CoordinateReferenceSystem wgs84 = CRS.decode("EPSG:4326");
ReferencedEnvelope envWgs84 = new ReferencedEnvelope(1, 3, 5, 7, wgs84);
ReferencedEnvelope envUTM31N = envWgs84.transform(utm31n, true);
StyleBuilder sb = new StyleBuilder();
Symbolizer ps = sb.createPointSymbolizer();
Style style = sb.createStyle(ps);
Rule rule = style.featureTypeStyles().get(0).rules().get(0);
rule.setFilter(
ff.bbox(
"geom",
envUTM31N.getMinX(),
envUTM31N.getMinY(),
envUTM31N.getMaxX(),
envUTM31N.getMaxY(),
"EPSG:32631"));
// force EPSG axis order interpretation
renderer.setRendererHints(
Collections.singletonMap(StreamingRenderer.FORCE_EPSG_AXIS_ORDER_KEY, true));
content.addLayer(new FeatureLayer(pointFS, style));
RendererBaseTest.showRender("Spatial in EPSG order", renderer, TIME, bounds);
assertEquals(1, renderedIds.size());
assertEquals("point.4", renderedIds.iterator().next());
}
代码示例来源:origin: geotools/geotools
copy.setLegendGraphic(legendCopy);
copy.setName(rule.getName());
copy.setFilter(filterCopy);
copy.setElseFilter(rule.isElseFilter());
copy.setMaxScaleDenominator(rule.getMaxScaleDenominator());
代码示例来源:origin: geotools/geotools
@Test
public void testPlainFilter() {
Filter f = ff.greater(ff.property("attribute"), ff.literal(10));
Rule r = sb.createRule(sb.createPointSymbolizer());
r.setFilter(f);
StyleAttributeExtractor extractor = new StyleAttributeExtractor();
r.accept(extractor);
Set<String> atts = extractor.getAttributeNameSet();
assertTrue(atts.contains("attribute"));
assertEquals(1, atts.size());
assertTrue(extractor.getDefaultGeometryUsed());
}
代码示例来源:origin: geotools/geotools
@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}")));
}
代码示例来源:origin: geotools/geotools
@Test
public void testFilterEscape() 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("}$")));
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 < '\\}\\$'}")));
}
代码示例来源:origin: geotools/geotools
rule.setFilter((Filter) node.getChildValue(Filter.class));
} else if (node.hasChild("ElseFilter")) {
rule.setIsElseFilter(true);
代码示例来源:origin: geotools/geotools
@Test
public void testFunction() throws Exception {
StyleFactory styleFactory = CommonFactoryFinder.getStyleFactory();
FilterFactory filterFactory = CommonFactoryFinder.getFilterFactory();
StyledLayerDescriptor sld = styleFactory.createStyledLayerDescriptor();
UserLayer layer = styleFactory.createUserLayer();
sld.layers().add(layer);
Style style = styleFactory.createStyle();
layer.userStyles().add(style);
Rule rule = styleFactory.createRule();
style.featureTypeStyles().add(styleFactory.createFeatureTypeStyle());
style.featureTypeStyles().get(0).rules().add(rule);
Function func =
filterFactory.function(
"strEndsWith", filterFactory.property("foo"), filterFactory.literal("bar"));
rule.setFilter(filterFactory.equal(func, filterFactory.literal(true), false));
StringWriter out = new StringWriter();
Ysld.encode(sld, out);
YamlMap obj = new YamlMap(YamlUtil.getSafeYaml().load(out.toString()));
String filter = obj.seq("feature-styles").map(0).seq("rules").map(0).str("filter");
assertEquals("${strEndsWith(foo,'bar') = true}", filter);
}
代码示例来源:origin: geotools/geotools
rule.setFilter(ECQL.toFilter(Util.removeExpressionBrackets(r.str("filter"))));
} catch (CQLException e) {
throw new RuntimeException("Error parsing filter", e);
代码示例来源:origin: geotools/geotools
public void testFeatureTypeStyle() throws Exception {
FeatureTypeStyle fts = styleFactory.createFeatureTypeStyle();
fts.setFeatureTypeName("feature-type");
Rule rule1;
rule1 = styleFactory.createRule();
rule1.setName("rule1");
rule1.setFilter(filterFactory.id(Collections.singleton(filterFactory.featureId("FID"))));
Rule rule2 = styleFactory.createRule();
rule2.setIsElseFilter(true);
rule2.setName("rule2");
fts.addRule(rule1);
fts.addRule(rule2);
FeatureTypeStyle clone = (FeatureTypeStyle) ((Cloneable) fts).clone();
assertClone(fts, clone);
rule1 = styleFactory.createRule();
rule1.setName("rule1");
rule1.setFilter(filterFactory.id(Collections.singleton(filterFactory.featureId("FID"))));
FeatureTypeStyle notEq = styleFactory.createFeatureTypeStyle();
notEq.setName("fts-not-equal");
notEq.addRule(rule1);
assertEqualsContract(clone, notEq, fts);
}
代码示例来源:origin: geotools/geotools
PropertyIsEqualTo filter = ff.equals(func, ff.literal("test"));
Rule r = sb.createRule(ps);
r.setFilter(filter);
代码示例来源:origin: geotools/geotools
public void testFeatureTypeStyle() throws Exception {
FeatureTypeStyle fts = sf.createFeatureTypeStyle();
fts.setFeatureTypeName("feature-type");
fts.getOptions().put("key", "value");
Rule rule1;
rule1 = sf.createRule();
rule1.setName("rule1");
rule1.setFilter(ff.id(Collections.singleton(ff.featureId("FID"))));
Rule rule2 = sf.createRule();
rule2.setIsElseFilter(true);
rule2.setName("rule2");
fts.addRule(rule1);
fts.addRule(rule2);
fts.accept(visitor);
FeatureTypeStyle clone = (FeatureTypeStyle) visitor.getCopy();
// assertClone(fts, clone);
assertEqualsContract(fts, clone);
rule1 = sf.createRule();
rule1.setName("rule1");
rule1.setFilter(ff.id(Collections.singleton(ff.featureId("FID"))));
FeatureTypeStyle notEq = sf.createFeatureTypeStyle();
notEq.setName("fts-not-equal");
notEq.addRule(rule1);
assertEqualsContract(clone, notEq, fts);
fts.setTransformation(ff.literal("transformation"));
fts.setOnlineResource(new OnLineResourceImpl());
fts.accept(visitor);
clone = (FeatureTypeStyle) visitor.getCopy();
assertEqualsContract(fts, clone);
}
代码示例来源:origin: geotools/geotools
rule.setFilter(filter);
rule.setTitle(title);
rule.setName(getRuleName(i + 1));
内容来源于网络,如有侵权,请联系作者删除!