本文整理了Java中org.geotools.ysld.YamlUtil
类的一些代码示例,展示了YamlUtil
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。YamlUtil
类的具体详情如下:
包路径:org.geotools.ysld.YamlUtil
类名称:YamlUtil
[英]Factory for Yaml instances.
[中]
代码示例来源:origin: geotools/geotools
public static Yaml getSafeYaml() {
return getSafeYaml(new DumperOptions());
}
代码示例来源:origin: geotools/geotools
public static Yaml getSafeYaml(DumperOptions dumperOptions) {
return getSafeYaml(new Representer(), dumperOptions);
}
代码示例来源:origin: geotools/geotools
/**
* Yaml representation.
*
* @return Yaml representation
*/
@Override
public String toString() {
StringWriter w = new StringWriter();
DumperOptions dumperOpts = new DumperOptions();
dumperOpts.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
dumperOpts.setDefaultScalarStyle(DumperOptions.ScalarStyle.PLAIN);
YamlUtil.getSafeYaml(dumperOpts).dump(raw, w);
return w.toString();
}
}
代码示例来源:origin: geotools/geotools
/**
* Encode the passed {@link StyledLayerDescriptor} as YSLD.
*
* @param sld
* @throws IOException
*/
public void encode(StyledLayerDescriptor sld) throws IOException {
DumperOptions dumpOpts = new DumperOptions();
dumpOpts.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
Yaml yaml = YamlUtil.getSafeYaml(new YsldRepresenter(uomMapper), dumpOpts);
yaml.dumpAll(new RootEncoder(sld), out);
}
}
代码示例来源:origin: geotools/geotools
/**
* Parse the yaml provided to this instance using the provided {@link YamlParseHandler}.
*
* @param root The {@link YamlParseHandler} that handles the root of the parsed {@link
* YamlObject}.
* @param hints
* @return The root {@link YamlParseHandler}, once it has finished handling the parsed {@link
* YamlObject}..
* @throws IOException
*/
@SuppressWarnings("PMD.EmptyWhileStmt")
public <T extends YamlParseHandler> T parse(T root, Map<String, Object> hints)
throws IOException {
Object parsed = YamlUtil.getSafeYaml().load(yaml);
YamlParseContext context = new YamlParseContext();
context.mergeDocHints(hints);
context.push(YamlObject.create(parsed), root);
while (context.next()) ;
return root;
}
}
代码示例来源:origin: geotools/geotools
YamlMap yaml(SldTransformer transformer) throws Exception {
String yaml = ((StringWriter) transformer.context().output()).toString();
return new YamlMap(YamlUtil.getSafeYaml().load(yaml));
}
代码示例来源:origin: geotools/geotools
@Test
public void testFTSVendorOption() throws Exception {
PointSymbolizer p = CommonFactoryFinder.getStyleFactory().createPointSymbolizer();
FeatureTypeStyle fts = fts(p);
fts.getOptions().put("foo", "bar");
StringWriter out = new StringWriter();
Ysld.encode(sld(fts), out);
System.out.append(out.toString());
YamlMap obj = new YamlMap(YamlUtil.getSafeYaml().load(out.toString()));
YamlMap result = obj.seq("feature-styles").map(0);
assertThat(result.str("x-foo"), equalTo("bar"));
}
代码示例来源:origin: geotools/geotools
YamlMap encode(String dirname, String filename) throws Exception {
SLDParser sldParser = new SLDParser(CommonFactoryFinder.getStyleFactory());
sldParser.setInput(YsldTests.sld(dirname, filename));
StyledLayerDescriptor sld = sldParser.parseSLD();
StringWriter w = new StringWriter();
YsldEncoder ysldEncoder = new YsldEncoder(w, new UomMapper());
ysldEncoder.encode(sld);
// System.out.println(w.toString());
return new YamlMap(YamlUtil.getSafeYaml().load(new StringReader(w.toString())));
}
}
代码示例来源:origin: geotools/geotools
for (Event evt : YamlUtil.getSafeYaml().parse(input)) {
YsldValidateHandler h = context.peek();
代码示例来源:origin: geotools/geotools
@Test
public void testSymbolizerVendorOption() throws Exception {
PointSymbolizer p = CommonFactoryFinder.getStyleFactory().createPointSymbolizer();
FeatureTypeStyle fts = fts(p);
p.getOptions().put("foo", "bar");
StringWriter out = new StringWriter();
Ysld.encode(sld(fts), out);
System.out.append(out.toString());
YamlMap obj = new YamlMap(YamlUtil.getSafeYaml().load(out.toString()));
YamlMap result =
obj.seq("feature-styles")
.map(0)
.seq("rules")
.map(0)
.seq("symbolizers")
.map(0)
.map("point");
assertThat(result.str("x-foo"), equalTo("bar"));
}
代码示例来源:origin: geotools/geotools
@Test
public void testSymbolizerUoMMetre() throws Exception {
PointSymbolizer p = CommonFactoryFinder.getStyleFactory().createPointSymbolizer();
FeatureTypeStyle fts = fts(p);
p.setUnitOfMeasure(UomOgcMapping.METRE.getUnit());
StringWriter out = new StringWriter();
Ysld.encode(sld(fts), out);
System.out.append(out.toString());
YamlMap obj = new YamlMap(YamlUtil.getSafeYaml().load(out.toString()));
YamlMap result =
obj.seq("feature-styles")
.map(0)
.seq("rules")
.map(0)
.seq("symbolizers")
.map(0)
.map("point");
assertThat(result.str("uom"), equalTo("metre"));
}
代码示例来源:origin: geotools/geotools
@Test
public void testSymbolizerUoMPixel() throws Exception {
PointSymbolizer p = CommonFactoryFinder.getStyleFactory().createPointSymbolizer();
FeatureTypeStyle fts = fts(p);
p.setUnitOfMeasure(UomOgcMapping.PIXEL.getUnit());
StringWriter out = new StringWriter();
Ysld.encode(sld(fts), out);
System.out.append(out.toString());
YamlMap obj = new YamlMap(YamlUtil.getSafeYaml().load(out.toString()));
YamlMap result =
obj.seq("feature-styles")
.map(0)
.seq("rules")
.map(0)
.seq("symbolizers")
.map(0)
.map("point");
assertThat(result.str("uom"), equalTo("pixel"));
}
代码示例来源:origin: geotools/geotools
@Test
public void testSymbolizerUoMFoot() throws Exception {
PointSymbolizer p = CommonFactoryFinder.getStyleFactory().createPointSymbolizer();
FeatureTypeStyle fts = fts(p);
p.setUnitOfMeasure(UomOgcMapping.FOOT.getUnit());
StringWriter out = new StringWriter();
Ysld.encode(sld(fts), out);
System.out.append(out.toString());
YamlMap obj = new YamlMap(YamlUtil.getSafeYaml().load(out.toString()));
YamlMap result =
obj.seq("feature-styles")
.map(0)
.seq("rules")
.map(0)
.seq("symbolizers")
.map(0)
.map("point");
assertThat(result.str("uom"), equalTo("foot"));
}
代码示例来源: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 testEmptyColorMap() throws Exception {
StyleFactory styleFactory = CommonFactoryFinder.getStyleFactory();
StyledLayerDescriptor sld = sld(styleFactory.createRasterSymbolizer());
StringWriter out = new StringWriter();
Ysld.encode(sld, out);
YamlMap obj = new YamlMap(YamlUtil.getSafeYaml().load(out.toString()));
YamlMap symbMap =
obj.seq("feature-styles")
.map(0)
.seq("rules")
.map(0)
.seq("symbolizers")
.map(0)
.map("raster");
assertThat(symbMap, not(yHasEntry("color-map")));
}
代码示例来源: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
@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}"));
}
代码示例来源:origin: geotools/geotools
@Test
public void testEmptyContrastEnhancement() throws Exception {
StyleFactory styleFactory = CommonFactoryFinder.getStyleFactory();
StyledLayerDescriptor sld = sld(styleFactory.createRasterSymbolizer());
StringWriter out = new StringWriter();
Ysld.encode(sld, out);
YamlMap obj = new YamlMap(YamlUtil.getSafeYaml().load(out.toString()));
YamlMap symbMap =
obj.seq("feature-styles")
.map(0)
.seq("rules")
.map(0)
.seq("symbolizers")
.map(0)
.map("raster");
assertFalse(symbMap.has("contrast-enhancement"));
}
代码示例来源:origin: geotools/geotools
Ysld.encode(sld, out);
YamlMap yaml = new YamlMap(YamlUtil.getSafeYaml().load(out.toString()));
代码示例来源: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);
}
内容来源于网络,如有侵权,请联系作者删除!