Style parse(String dir, String file) throws IOException { StringWriter writer = new StringWriter(); transform(YsldTests.sld(dir, file), writer); // System.out.println(writer.toString()); YsldParser p = new YsldParser(new StringReader(writer.toString())); return SLD.defaultStyle(p.parse()); }
@Override protected void encode(StyledLayerDescriptor sld) { Style style = SLD.defaultStyle(sld); if (style != null) { put("name", style.getName()); put("title", style.getTitle()); put("abstract", style.getAbstract()); put("feature-styles", new FeatureStyleEncoder(style)); } } }
@Test public void testExpressionAttribute() throws Exception { String yaml = "text: \n" + " geometry: ${testAttribute}\n" + ""; StyledLayerDescriptor sld = Ysld.parse(yaml); FeatureTypeStyle fs = SLD.defaultStyle(sld).featureTypeStyles().get(0); TextSymbolizer symb = (TextSymbolizer) fs.rules().get(0).symbolizers().get(0); Expression expr = symb.getGeometry(); assertThat(expr, attribute("testAttribute")); }
@Test public void testLineOffset() throws Exception { // See GEOT-3912 String yaml = "line:\n" + " stroke-color: '#555555'\n" + " stroke-width: 1.0\n" + " offset: 5"; StyledLayerDescriptor sld = Ysld.parse(yaml); LineSymbolizer l = SLD.lineSymbolizer(SLD.defaultStyle(sld)); assertThat(l.getPerpendicularOffset(), is(literal(5))); // SLD/SE 1.1 feature that may not be supported by renderer }
@Test public void testEvilExpression1() throws Exception { String yaml = "point: \n" + " symbols: \n" + " - mark: \n" + " fill-color: \\$\\}\\\\\n"; StyledLayerDescriptor sld = Ysld.parse(yaml); PointSymbolizer p = SLD.pointSymbolizer(SLD.defaultStyle(sld)); assertThat(SLD.fill(p).getColor(), literal(equalTo("$}\\"))); }
@Test public void testFilterWithEscape() throws Exception { String yaml = "rules: \n" + "- filter: ${foo = '\\$\\}'}\n"; StyledLayerDescriptor sld = Ysld.parse(yaml); Rule r = SLD.defaultStyle(sld).featureTypeStyles().get(0).rules().get(0); Filter f = r.getFilter(); assertThat(f, Matchers.instanceOf(PropertyIsEqualTo.class)); assertThat(((PropertyIsEqualTo) f).getExpression1(), attribute("foo")); assertThat(((PropertyIsEqualTo) f).getExpression2(), literal("$}")); }
@Test public void testAnchor() throws Exception { String yaml = "blue: &blue rgb(0,0,255)\n" + "point: \n" + " symbols: \n" + " - mark: \n" + " fill-color: *blue\n"; StyledLayerDescriptor sld = Ysld.parse(yaml); PointSymbolizer p = SLD.pointSymbolizer(SLD.defaultStyle(sld)); assertEquals(Color.BLUE, SLD.color(SLD.fill(p))); }
@Test public void testMultiplyCompositeBaseOnSymbolizer() throws Exception { String yaml = "line:\n" + " x-composite-base: true\n" + ""; StyledLayerDescriptor sld = Ysld.parse(yaml); LineSymbolizer p = (LineSymbolizer) SLD.lineSymbolizer(SLD.defaultStyle(sld)); assertThat(p, hasProperty("options", hasEntry("composite-base", "true"))); }
@Test public void testNamedColor() throws Exception { String yaml = "point: \n" + " symbols: \n" + " - mark: \n" + " fill-color: blue\n"; StyledLayerDescriptor sld = Ysld.parse(yaml); PointSymbolizer p = SLD.pointSymbolizer(SLD.defaultStyle(sld)); assertEquals(Color.BLUE, SLD.color(SLD.fill(p))); }
@Test public void testUomFoot() throws Exception { String yaml = "line:\n" + " uom: foot\n" + ""; StyledLayerDescriptor sld = Ysld.parse(yaml); LineSymbolizer p = (LineSymbolizer) SLD.lineSymbolizer(SLD.defaultStyle(sld)); assertThat(p, hasProperty("unitOfMeasure", sameInstance(UomOgcMapping.FOOT.getUnit()))); }
@Test public void testDynamicColor() throws Exception { String yaml = "point: \n" + " symbols: \n" + " - mark: \n" + " fill-color: ${colourAttribute}\n"; StyledLayerDescriptor sld = Ysld.parse(yaml); PointSymbolizer p = SLD.pointSymbolizer(SLD.defaultStyle(sld)); assertThat(SLD.fill(p).getColor(), attribute("colourAttribute")); }
@Test public void testUomMetre() throws Exception { String yaml = "line:\n" + " uom: metre\n" + ""; StyledLayerDescriptor sld = Ysld.parse(yaml); LineSymbolizer p = (LineSymbolizer) SLD.lineSymbolizer(SLD.defaultStyle(sld)); assertThat(p, hasProperty("unitOfMeasure", sameInstance(UomOgcMapping.METRE.getUnit()))); }
@Test public void testUomSymbol() throws Exception { String yaml = "line:\n" + " uom: m\n" + ""; StyledLayerDescriptor sld = Ysld.parse(yaml); LineSymbolizer p = (LineSymbolizer) SLD.lineSymbolizer(SLD.defaultStyle(sld)); assertThat(p, hasProperty("unitOfMeasure", sameInstance(UomOgcMapping.METRE.getUnit()))); }
@Test public void testUomPixel() throws Exception { String yaml = "line:\n" + " uom: pixel\n" + ""; StyledLayerDescriptor sld = Ysld.parse(yaml); LineSymbolizer p = (LineSymbolizer) SLD.lineSymbolizer(SLD.defaultStyle(sld)); assertThat(p, hasProperty("unitOfMeasure", sameInstance(UomOgcMapping.PIXEL.getUnit()))); }
@Test public void testRasterBandSelectionGray() throws Exception { String yaml = "raster:\n" + " channels:\n" + " gray:\n" + " name: foo\n"; StyledLayerDescriptor sld = Ysld.parse(yaml); RasterSymbolizer r = SLD.rasterSymbolizer(SLD.defaultStyle(sld)); SelectedChannelType grayChannel = r.getChannelSelection().getGrayChannel(); assertThat(grayChannel.getChannelName().evaluate(null, String.class), equalTo("foo")); assertThat(grayChannel.getContrastEnhancement(), nullContrast()); }
@Test public void testRasterBandSelectionGrayTerse() throws Exception { String yaml = "raster:\n" + " channels:\n" + " gray: 1\n"; StyledLayerDescriptor sld = Ysld.parse(yaml); RasterSymbolizer r = SLD.rasterSymbolizer(SLD.defaultStyle(sld)); SelectedChannelType grayChannel = r.getChannelSelection().getGrayChannel(); assertThat(grayChannel.getChannelName().evaluate(null, String.class), equalTo("1")); assertThat(grayChannel.getContrastEnhancement(), nullContrast()); }
@SuppressWarnings("unchecked") @Test public void testTextDisplacement() throws Exception { String yaml = "text: \n" + " displacement: " + tuple(10, 42) + "\n"; StyledLayerDescriptor sld = Ysld.parse(yaml); TextSymbolizer p = SLD.textSymbolizer(SLD.defaultStyle(sld)); assertThat( ((PointPlacement) p.getLabelPlacement()).getDisplacement(), allOf( hasProperty("displacementX", literal(10)), hasProperty("displacementY", literal(42)))); }
@Test public void testTextPlacementType() throws Exception { String yaml = "text: \n" + " placement: line\n" + " offset: 4\n"; StyledLayerDescriptor sld = Ysld.parse(yaml); TextSymbolizer t = SLD.textSymbolizer(SLD.defaultStyle(sld)); assertThat(t.getLabelPlacement(), instanceOf(LinePlacement.class)); Expression e = ((LinePlacement) t.getLabelPlacement()).getPerpendicularOffset(); assertThat(((LinePlacement) t.getLabelPlacement()).getPerpendicularOffset(), literal(4)); }
@Test public void testUomSEURL() throws Exception { String yaml = "line:\n" + " uom: " + UomOgcMapping.FOOT.getSEString() + "\n" + ""; StyledLayerDescriptor sld = Ysld.parse(yaml); LineSymbolizer p = (LineSymbolizer) SLD.lineSymbolizer(SLD.defaultStyle(sld)); assertThat(p, hasProperty("unitOfMeasure", sameInstance(UomOgcMapping.FOOT.getUnit()))); }
@Test public void testColorSexegesimal() throws Exception { String yaml = "point: \n" + " symbols: \n" + " - mark: \n" + " fill-color: 1:17:40:20:15\n"; StyledLayerDescriptor sld = Ysld.parse(yaml); PointSymbolizer p = SLD.pointSymbolizer(SLD.defaultStyle(sld)); assertThat(SLD.fill(p).getColor(), literal(isColor("FFFFFF"))); }