本文整理了Java中org.geotools.styling.Rule
类的一些代码示例,展示了Rule
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Rule
类的具体详情如下:
包路径:org.geotools.styling.Rule
类名称:Rule
[英]A rule is used to attach a condition to, and group, the individual symbolizers used for rendering. The Title and Abstract describe the rule and may be used to generate a legend, as may the LegendGraphic. The Filter, ElseFilter, MinScale and MaxScale elements allow the selection of features and rendering scales for a rule. The scale selection works as follows. When a map is to be rendered, the scale denominator is computed and all rules in all UserStyles that have a scale outside of the request range are dropped. (This also includes Rules that have an ElseFilter.) An ElseFilter is simply an ELSE condition to the conditions (Filters) of all other rules in the same UserStyle. The exact meaning of the ElseFilter is determined after Rules have been eliminated for not fitting the rendering scale. This definition of the behaviour of ElseFilters may seem a little strange, but it allows for scale-dependent and scale-independent ELSE conditions. For the Filter, only SqlExpression is available for specification, but this is a hack and should be replaced with Filter as defined in WFS. A missing Filter element means "always true". If a set of Rules has no ElseFilters, then some features may not be rendered (which is presumably the desired behavior). The Scales are actually scale denominators (as double floats), so "10e6" would be interpreted as 1:10M. A missing MinScale means there is no lower bound to the scale-denominator range (limx->0+), and a missing MaxScale means there is no upper bound (infinity). 0.28mm
The details of this object are taken from the OGC Styled-Layer Descriptor Report (OGC 02-070) version 1.0.0.:
<xsd:element name="Rule">
<xsd:annotation>
<xsd:documentation>
A Rule is used to attach property/scale conditions to and group
the individual symbolizers used for rendering.
</xsd:documentation>
</xsd:annotation>
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="sld:Name" minOccurs="0"/>
<xsd:element ref="sld:Title" minOccurs="0"/>
<xsd:element ref="sld:Abstract" minOccurs="0"/>
<xsd:element ref="sld:LegendGraphic" minOccurs="0"/>
<xsd:choice minOccurs="0">
<xsd:element ref="ogc:Filter"/>
<xsd:element ref="sld:ElseFilter"/>
</xsd:choice>
<xsd:element ref="sld:MinScaleDenominator" minOccurs="0"/>
<xsd:element ref="sld:MaxScaleDenominator" minOccurs="0"/>
<xsd:element ref="sld:Symbolizer" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
[中]规则用于将条件附加到用于渲染的单个符号,并将其分组。标题和摘要描述了规则,并可用于生成图例,如图例。Filter、ElseFilter、MinScale和MaxScale元素允许为规则选择特征和渲染比例。比例选择的工作原理如下。在渲染地图时,将计算比例分母,并删除所有用户样式中比例超出请求范围的所有规则。(这还包括具有ElseFilter的规则。)ElseFilter只是同一用户样式中所有其他规则的条件(过滤器)的ELSE条件。消除不适合渲染比例的规则后,将确定ElseFilter的确切含义。这种对ElseFilter行为的定义似乎有点奇怪,但它考虑了与规模相关和与规模无关的其他条件。对于过滤器,只有SqlExpression可用于规范,但这是一种攻击,应该用WFS中定义的过滤器替换。缺少滤芯意味着“始终正确”。如果一组规则没有ElseFilter,则可能无法呈现某些功能(这可能是所需的行为)。刻度实际上是刻度分母(作为双浮点数),因此“10e6”将被解释为1:10M。缺少MinScale意味着刻度分母范围没有下限(lim[x->0+](x)),缺少MaxScale意味着没有上限(无穷大)。0.28毫米
此对象的详细信息取自OGC Styled-Layer Descriptor Report (OGC 02-070) version 1.0.0.:
<xsd:element name="Rule">
<xsd:annotation>
<xsd:documentation>
A Rule is used to attach property/scale conditions to and group
the individual symbolizers used for rendering.
</xsd:documentation>
</xsd:annotation>
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="sld:Name" minOccurs="0"/>
<xsd:element ref="sld:Title" minOccurs="0"/>
<xsd:element ref="sld:Abstract" minOccurs="0"/>
<xsd:element ref="sld:LegendGraphic" minOccurs="0"/>
<xsd:choice minOccurs="0">
<xsd:element ref="ogc:Filter"/>
<xsd:element ref="sld:ElseFilter"/>
</xsd:choice>
<xsd:element ref="sld:MinScaleDenominator" minOccurs="0"/>
<xsd:element ref="sld:MaxScaleDenominator" minOccurs="0"/>
<xsd:element ref="sld:Symbolizer" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
代码示例来源:origin: geoserver/geoserver
LineSymbolizer ls = styleFactory.createLineSymbolizer();
ls.setStroke(
styleFactory.createStroke(
filterFactory.literal(color), filterFactory.literal(2)));
PolygonSymbolizer ps = styleFactory.createPolygonSymbolizer();
ps.setFill(styleFactory.createFill(filterFactory.literal(color)));
Rule r = styleFactory.createRule();
r.symbolizers().add(sym);
FeatureTypeStyle fts = styleFactory.createFeatureTypeStyle();
fts.rules().add(r);
Style s = styleFactory.createStyle();
s.featureTypeStyles().add(fts);
UserLayer l = styleFactory.createUserLayer();
代码示例来源:origin: geotools/geotools
if (rule.getFilter() != null) {
Filter filter = rule.getFilter();
filterCopy = copy(filter);
Symbolizer[] symsCopy = rule.getSymbolizers();
for (int i = 0; i < symsCopy.length; i++) {
symsCopy[i] = copy(symsCopy[i]);
Graphic[] legendCopy = rule.getLegendGraphic();
for (int i = 0; i < legendCopy.length; i++) {
legendCopy[i] = copy(legendCopy[i]);
Description descCopy = rule.getDescription();
descCopy = copy(descCopy);
copy = sf.createRule();
copy.setSymbolizers(symsCopy);
copy.setDescription(descCopy);
copy.setLegendGraphic(legendCopy);
copy.setName(rule.getName());
copy.setFilter(filterCopy);
copy.setElseFilter(rule.isElseFilter());
copy.setMaxScaleDenominator(rule.getMaxScaleDenominator());
copy.setMinScaleDenominator(rule.getMinScaleDenominator());
代码示例来源:origin: geotools/geotools
List<Rule> elseRuleList = new ArrayList<Rule>();
for (Rule r : fts.rules())
if (isWithInScale(r)) {
if (r.isElseFilter()) {
elseRuleList.add(r);
} else {
if (!Filter.INCLUDE.equals(r.getFilter()) && hasEnvVariables(r.getFilter())) {
DuplicatingStyleVisitor cloner =
new DuplicatingStyleVisitor() {
r.accept(cloner);
Rule copy = (Rule) cloner.getCopy();
if (!Filter.EXCLUDE.equals(copy.getFilter())) {
ruleList.add(copy);
代码示例来源:origin: geotools/geotools
/**
* Checks if a rule can be triggered at the current scale level
*
* @param r The rule
* @return true if the scale is compatible with the rule settings
*/
private boolean isWithInScale(Rule r) {
return ((r.getMinScaleDenominator() - TOLERANCE) <= scaleDenominator)
&& ((r.getMaxScaleDenominator() + TOLERANCE) > scaleDenominator);
}
代码示例来源:origin: geotools/geotools
public RuleBuilder reset(Rule rule) {
if (rule == null) {
return unset();
}
name = rule.getName();
title = rule.getTitle();
ruleAbstract = rule.getAbstract();
minScaleDenominator = rule.getMinScaleDenominator();
maxScaleDenominator = rule.getMaxScaleDenominator();
filter = rule.getFilter();
elseFilter = rule.isElseFilter();
symbolizers.clear();
symbolizers.addAll(rule.symbolizers()); // TODO: unpack into builders in order to "copy"
symbolizerBuilder = null;
unset = false;
legend.reset(rule.getLegend());
return this;
}
代码示例来源:origin: geotools/geotools
/**
* create a simple styling rule, see the SLD Spec for more details of scaleDenominators
*
* @param symbolizers - an array of symbolizers to use
* @param minScaleDenominator - the minimim scale to draw the feature at
* @param maxScaleDenominator - the maximum scale to draw the feature at
* @return the new rule
*/
public Rule createRule(
Symbolizer[] symbolizers, double minScaleDenominator, double maxScaleDenominator) {
Rule r = sf.createRule();
r.setSymbolizers(symbolizers);
if (!Double.isNaN(maxScaleDenominator)) {
r.setMaxScaleDenominator(maxScaleDenominator);
} else {
r.setMaxScaleDenominator(Double.POSITIVE_INFINITY);
}
if (!Double.isNaN(minScaleDenominator)) {
r.setMinScaleDenominator(minScaleDenominator);
} else {
r.setMinScaleDenominator(0.0);
}
return r;
}
代码示例来源:origin: geotools/geotools
@Test
public void testColourMap() throws Exception {
String yaml =
"raster: \n"
+ " color-map:\n"
+ " type: values\n"
+ " entries:\n"
+ " - "
+ tuple("#ff0000", "1.0", "0", "start")
+ "\n"
+ " - "
+ tuple("#00ff00", "1.0", "500", "middle")
+ "\n"
+ " - "
+ tuple("#0000ff", "1.0", "1000", "end")
+ "\n"
+ "";
StyledLayerDescriptor sld = Ysld.parse(yaml);
FeatureTypeStyle fs = SLD.defaultStyle(sld).featureTypeStyles().get(0);
RasterSymbolizer symb = (RasterSymbolizer) fs.rules().get(0).symbolizers().get(0);
// need to use the geotools.styling interface as it provides the accessors for the entries.
ColorMap map = (ColorMap) symb.getColorMap();
Color colour1 = (Color) map.getColorMapEntry(0).getColor().evaluate(null);
Color colour2 = (Color) map.getColorMapEntry(1).getColor().evaluate(null);
Color colour3 = (Color) map.getColorMapEntry(2).getColor().evaluate(null);
assertThat(colour1, is(Color.RED));
assertThat(colour2, is(Color.GREEN));
assertThat(colour3, is(Color.BLUE));
}
代码示例来源: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 testRenderingTransformationSimplifyWithWMSParams() throws IOException {
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);
FeatureTypeStyle featureStyle = styleFactory.createFeatureTypeStyle();
style.featureTypeStyles().add(featureStyle);
featureStyle.setTransformation(rt);
Rule rule = styleFactory.createRule();
rule.setName("Za'Ha'Dum");
featureStyle.rules().add(rule);
代码示例来源:origin: org.geoserver/gs-kml
@Test
public void testFilteredRulesPickFirstMark() throws Exception {
Style result;
{
Filter f1 = filterFactory.less(filterFactory.property("foo"), filterFactory.literal(4));
Filter f2 =
filterFactory.greaterOrEqual(
filterFactory.property("foo"), filterFactory.literal(4));
PointSymbolizer symb1 = mark("arrow", Color.BLACK, Color.RED, 1f, 16);
PointSymbolizer symb2 = mark("arrow", Color.BLACK, Color.BLUE, 1f, 16);
Style input = styleFromRules(rule(f1, symb1), rule(f2, symb2));
Map<String, String> properties = new HashMap<String, String>();
properties.put("0.0.0", "");
result = IconPropertyInjector.injectProperties(input, properties);
}
{
FeatureTypeStyle fts = assumeSingleElement(result.featureTypeStyles());
Rule rule = assertSingleElement(fts.rules());
PointSymbolizer symb = assertSingleElement(rule.symbolizers(), PointSymbolizer.class);
Mark mark = assertSingleElement(symb.getGraphic().graphicalSymbols(), Mark.class);
assertThat(mark.getFill().getColor().evaluate(null, Color.class), is(Color.RED));
}
}
代码示例来源:origin: geotools/geotools
throws IllegalFilterException {
PropertyIsLessThan cf1 = ff.less(value, ff.literal(breaks[0]));
rules[0] = sf.createRule();
rules[0].setFilter(cf1);
rules[0].setSymbolizers(new Symbolizer[] {symb1});
LOGGER.fine("added low class " + breaks[0] + " " + colors[0]);
rules[i] = sf.createRule();
rules[i].setSymbolizers(new Symbolizer[] {symb});
rules[i].setFilter(cf);
rules[colors.length - 1] = sf.createRule();
rules[colors.length - 1].setFilter(cf2);
rules[colors.length - 1].setName(geomName);
c = this.createColor(colors[colors.length - 1]);
rules[colors.length - 1].setSymbolizers(new Symbolizer[] {symb2});
LOGGER.fine(
"added upper class "
rules[colors.length].setSymbolizers(new Symbolizer[] {elsePoly});
rules[colors.length].setElseFilter(true);
代码示例来源:origin: geotools/geotools
@Test
public void testLabelDisplacement() throws IOException {
StyleFactory sf = CommonFactoryFinder.getStyleFactory();
FilterFactory ff = CommonFactoryFinder.getFilterFactory();
StyledLayerDescriptor sld = sf.createStyledLayerDescriptor();
UserLayer layer = sf.createUserLayer();
sld.layers().add(layer);
Style style = sf.createStyle();
layer.userStyles().add(style);
FeatureTypeStyle featureStyle = sf.createFeatureTypeStyle();
style.featureTypeStyles().add(featureStyle);
Rule rule = sf.createRule();
featureStyle.rules().add(rule);
null,
null);
rule.symbolizers().add(text);
代码示例来源:origin: geotools/geotools
@Test
public void testLabelShield() throws IOException {
StyleFactory sf = CommonFactoryFinder.getStyleFactory();
FilterFactory ff = CommonFactoryFinder.getFilterFactory();
StyledLayerDescriptor sld = sf.createStyledLayerDescriptor();
UserLayer layer = sf.createUserLayer();
sld.layers().add(layer);
Style style = sf.createStyle();
layer.userStyles().add(style);
FeatureTypeStyle featureStyle = sf.createFeatureTypeStyle();
style.featureTypeStyles().add(featureStyle);
Rule rule = sf.createRule();
featureStyle.rules().add(rule);
Stroke stroke = sf.stroke(ff.literal("#555555"), null, null, null, null, null, null);
rule.symbolizers().add(sf.lineSymbolizer("line", null, null, null, stroke, null));
Mark mark = sf.mark(ff.literal("circle"), sf.fill(null, ff.literal("#995555"), null), null);
List<GraphicalSymbol> symbols = new ArrayList<GraphicalSymbol>();
null);
text.setGraphic(sf.graphic(symbols, null, null, null, null, null));
rule.symbolizers().add(text);
代码示例来源:origin: geotools/geotools
PointSymbolizer ps =
(PointSymbolizer)
style.featureTypeStyles().get(0).rules().get(0).symbolizers().get(0);
FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(null);
ps.setGeometry(ff.function("convert", ff.property("wkt"), ff.literal(Point.class)));
代码示例来源:origin: geotools/geotools
@Test
public void testLabelLinePlacement() throws IOException {
StyleFactory sf = CommonFactoryFinder.getStyleFactory();
FilterFactory ff = CommonFactoryFinder.getFilterFactory();
StyledLayerDescriptor sld = sf.createStyledLayerDescriptor();
UserLayer layer = sf.createUserLayer();
sld.layers().add(layer);
Style style = sf.createStyle();
layer.userStyles().add(style);
FeatureTypeStyle featureStyle = sf.createFeatureTypeStyle();
style.featureTypeStyles().add(featureStyle);
Rule rule = sf.createRule();
featureStyle.rules().add(rule);
LabelPlacement place = sf.createLinePlacement(ff.literal(10));
null,
null);
rule.symbolizers().add(text);
代码示例来源: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
private static Style createDefaultStyle() {
Color foreground = Color.darkGray;
int thick = 3;
// create stroke
org.geotools.styling.Stroke stroke =
sf.stroke(ff.literal(foreground), null, ff.literal(thick), null, null, null, null);
// create line symbolizer
LineSymbolizer lineSym = sf.createLineSymbolizer(stroke, null);
// create rule
Rule r = sf.createRule();
r.symbolizers().add(lineSym);
// add it to style
Style style = sf.createStyle();
FeatureTypeStyle fts = sf.createFeatureTypeStyle();
fts.rules().add(r);
style.featureTypeStyles().add(fts);
return style;
}
}
代码示例来源: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
@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
private static Style createPointStyle() {
StyleFactory sf = CommonFactoryFinder.getStyleFactory();
URL iconUrl = ScreenMapShapefileTest.class.getResource("icon.png");
ExternalGraphic icon = sf.createExternalGraphic(iconUrl, "image/png");
Graphic graphic =
sf.createGraphic(new ExternalGraphic[] {icon}, null, null, null, null, null);
PointSymbolizer symbolizer = sf.createPointSymbolizer(graphic, "the_geom");
Rule rule = sf.createRule();
rule.symbolizers().add(symbolizer);
FeatureTypeStyle fts = sf.createFeatureTypeStyle();
fts.rules().add(rule);
Style style = sf.createStyle();
style.featureTypeStyles().add(fts);
return style;
}
内容来源于网络,如有侵权,请联系作者删除!