gpt4 book ai didi

org.geotools.ysld.Ysld.encode()方法的使用及代码示例

转载 作者:知者 更新时间:2024-03-14 12:07:31 26 4
gpt4 key购买 nike

本文整理了Java中org.geotools.ysld.Ysld.encode()方法的一些代码示例,展示了Ysld.encode()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Ysld.encode()方法的具体详情如下:
包路径:org.geotools.ysld.Ysld
类名称:Ysld
方法名:encode

Ysld.encode介绍

[英]Encodes a GeoTools style object as Ysld.
[中]将GeoTools样式的对象编码为Ysld。

代码示例

代码示例来源:origin: geotools/geotools

/**
 * Encodes a GeoTools style object as Ysld.
 *
 * @param sld The sld to encode.
 * @param output The output object, anything accepted by {@link #writer(Object)}
 */
public static void encode(StyledLayerDescriptor sld, Object output) throws IOException {
  encode(sld, output, new UomMapper());
}

代码示例来源:origin: geotools/geotools

/**
 * Transforms an SLD stream to Ysld.
 *
 * @param sld SLD xml reader.
 * @param ysld Ysld writer.
 */
public static void transform(InputStream sld, Writer ysld) throws IOException {
  SLDParser parser = new SLDParser(CommonFactoryFinder.getStyleFactory(), sld);
  StyledLayerDescriptor style = parser.parseSLD();
  Ysld.encode(style, ysld);
}

代码示例来源: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

@Test
public void testExpressionNil() throws Exception {
  PointSymbolizer p = CommonFactoryFinder.getStyleFactory().createPointSymbolizer();
  p.getGraphic().setSize(Expression.NIL);
  StringWriter out = new StringWriter();
  Ysld.encode(sld(p), out);
  // System.out.println(out.toString());
}

代码示例来源:origin: geotools/geotools

@Test
public void testSymbolizerUoMOther() throws Exception {
  PointSymbolizer p = CommonFactoryFinder.getStyleFactory().createPointSymbolizer();
  FeatureTypeStyle fts = fts(p);
  p.setUnitOfMeasure(USCustomary.LIGHT_YEAR);
  StringWriter out = new StringWriter();
  exception.expect(IllegalArgumentException.class);
  Ysld.encode(sld(fts), out);
}

代码示例来源: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 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 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

@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

@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 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

@Test
public void testNonNameExpressionLiteral() throws Exception {
  PointSymbolizer p = CommonFactoryFinder.getStyleFactory().createPointSymbolizer();
  Expression expression = CommonFactoryFinder.getFilterFactory2().literal("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 testEmbededExpressionEscapeLiteral() throws Exception {
  PointSymbolizer p = CommonFactoryFinder.getStyleFactory().createPointSymbolizer();
  Expression expression = 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("\\$\\}\\\\"));
}

代码示例来源:origin: geotools/geotools

@Test
public void testTextSymbolizerPriority() throws Exception {
  StyleFactory styleFactory = CommonFactoryFinder.getStyleFactory();
  FilterFactory filterFactory = CommonFactoryFinder.getFilterFactory();
  TextSymbolizer symb = styleFactory.createTextSymbolizer();
  symb.setPriority(filterFactory.property("foo"));
  StringWriter out = new StringWriter();
  Ysld.encode(sld(symb), out);
  YamlMap obj = new YamlMap(YamlUtil.getSafeYaml().load(out.toString()));
  YamlMap text =
      obj.seq("feature-styles")
          .map(0)
          .seq("rules")
          .map(0)
          .seq("symbolizers")
          .map(0)
          .map("text");
  assertEquals("${foo}", text.str("priority"));
}

代码示例来源:origin: geotools/geotools

@Test
public void testNameExpressionAttribute() throws Exception {
  PointSymbolizer p = CommonFactoryFinder.getStyleFactory().createPointSymbolizer();
  Expression nameExpression = CommonFactoryFinder.getFilterFactory2().property("test");
  Mark mark = CommonFactoryFinder.getStyleFactory().createMark();
  mark.setWellKnownName(nameExpression);
  p.getGraphic().graphicalSymbols().add(mark);
  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")
          .seq("symbols")
          .map(0)
          .map("mark")
          .str("shape");
  assertThat(result, equalTo("${test}"));
}

代码示例来源:origin: geotools/geotools

@Test
public void testEmbededExpression() throws Exception {
  PointSymbolizer p = CommonFactoryFinder.getStyleFactory().createPointSymbolizer();
  Expression expression =
      CommonFactoryFinder.getFilterFactory2()
          .function(
              "Concatenate",
              CommonFactoryFinder.getFilterFactory2().literal("literal0"),
              CommonFactoryFinder.getFilterFactory2().property("attribute1"),
              CommonFactoryFinder.getFilterFactory2().literal("literal2"));
  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("literal0${attribute1}literal2"));
}

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com