@Test public void testParsedStyle() throws IOException { File styleDir = new File(dataDir.root(), "styles"); styleDir.mkdir(); // Copy the sld to the temp style dir File styleFile = new File(styleDir, "external.sld"); Files.copy(this.getClass().getResourceAsStream("external.sld"), styleFile.toPath()); File iconFile = new File(styleDir, "icon.png"); assertFalse(iconFile.exists()); StyleInfoImpl si = new StyleInfoImpl(null); si.setName(""); si.setId(""); si.setFormat("sld"); si.setFormatVersion(new Version("1.0.0")); si.setFilename(styleFile.getName()); Style s = dataDir.parsedStyle(si); // Verify style is actually parsed correctly Symbolizer symbolizer = s.featureTypeStyles().get(0).rules().get(0).symbolizers().get(0); assertTrue(symbolizer instanceof PointSymbolizer); GraphicalSymbol graphic = ((PointSymbolizer) symbolizer).getGraphic().graphicalSymbols().get(0); assertTrue(graphic instanceof ExternalGraphic); assertEquals(((ExternalGraphic) graphic).getLocation(), iconFile.toURI().toURL()); // GEOS-7025: verify the icon file is not created if it doesn't already exist assertFalse(iconFile.exists()); }
assertTrue(symbolizer instanceof PointSymbolizer); GraphicalSymbol graphic = ((PointSymbolizer) symbolizer).getGraphic().graphicalSymbols().get(0); assertTrue(graphic instanceof ExternalGraphic); assertEquals(
@Test public void testSEStyleWithRelativePathProtocol() throws IOException { StyleInfo si = getCatalog().getStyleByName("relative_protocol"); assertNotNull(si); Style style = si.getStyle(); PolygonSymbolizer ps = (PolygonSymbolizer) style.featureTypeStyles().get(0).rules().get(0).symbolizers().get(0); ExternalGraphic eg = (ExternalGraphic) ps.getFill().getGraphicFill().graphicalSymbols().get(0); URI uri = eg.getOnlineResource().getLinkage(); assertNotNull(uri); File actual = URLs.urlToFile(uri.toURL()).getCanonicalFile(); assertEquals(rockFillSymbolFile, actual); }
@Test public void testSEStyleWithRelativePath() throws IOException { StyleInfo si = getCatalog().getStyleByName("relative"); assertNotNull(si); Style style = si.getStyle(); PolygonSymbolizer ps = (PolygonSymbolizer) style.featureTypeStyles().get(0).rules().get(0).symbolizers().get(0); ExternalGraphic eg = (ExternalGraphic) ps.getFill().getGraphicFill().graphicalSymbols().get(0); URI uri = eg.getOnlineResource().getLinkage(); assertNotNull(uri); File actual = URLs.urlToFile(uri.toURL()).getCanonicalFile(); assertEquals(rockFillSymbolFile, actual); }
assertTrue(symbolizer instanceof PointSymbolizer); GraphicalSymbol graphic = ((PointSymbolizer) symbolizer).getGraphic().graphicalSymbols().get(0); assertTrue(graphic instanceof ExternalGraphic); assertEquals(
/** * Retrieves the first Mark object from the given Graphic object. * * @param graphic the Graphic object. * @return a Mark object or null if unavailable. */ public static Mark mark(Graphic graphic) { if (graphic == null) { return null; } for (GraphicalSymbol gs : graphic.graphicalSymbols()) { if (gs != null && gs instanceof Mark) { return (Mark) gs; } } return null; }
@Override protected void externalGraphic(ExternalGraphic externalGraphic) { g.graphicalSymbols().add(externalGraphic); } });
@Override protected void mark(Mark mark) { g.graphicalSymbols().add(mark); } });
public SymbolsEncoder(Graphic g) { super(g.graphicalSymbols().iterator()); }
ps.getGraphic().graphicalSymbols().add(mark);
private Paint getStrokePaint(org.geotools.styling.Stroke stroke, Object feature) { if (stroke == null) { return null; } // the foreground color Paint contourPaint = evalToColor(stroke.getColor(), feature, Color.BLACK); // if a graphic fill is to be used, prepare the paint accordingly.... org.geotools.styling.Graphic gr = stroke.getGraphicFill(); if (gr != null && gr.graphicalSymbols() != null && gr.graphicalSymbols().size() > 0) { contourPaint = getTexturePaint(gr, feature, null); } return contourPaint; }
protected Paint getPaint(Fill fill, Object feature, Symbolizer symbolizer) { if (fill == null) { return null; } // get fill color Paint fillPaint = evalToColor(fill.getColor(), feature, null); // if a graphic fill is to be used, prepare the paint accordingly.... org.geotools.styling.Graphic gr = fill.getGraphicFill(); if (gr != null && gr.graphicalSymbols() != null && gr.graphicalSymbols().size() > 0) { fillPaint = getTexturePaint(gr, feature, symbolizer); } return fillPaint; }
/** Checks if creating a Graphic with an ExternalGraphics works. */ public void testWithExternalGraphics() throws Exception { StyleBuilder sb = new StyleBuilder(); URL urlExternal = getClass().getResource("/data/sld/blob.gif"); ExternalGraphic extg = sb.createExternalGraphic(urlExternal, "image/svg+xml"); Graphic graphic = sb.createGraphic(extg, null, null); assertEquals(1, graphic.graphicalSymbols().size()); }
public void testFallbackGraphicMark() throws Exception { PointSymbolizer symb = sf.createPointSymbolizer(); ExternalGraphic eg = sf.createExternalGraphic("http://foo.com/invalid_or_missing_image_url", null); symb.getGraphic().graphicalSymbols().add(eg); Style2D icon = sld.createPointStyle(feature, symb, range); assertNotNull(icon); }
public void testResizeExternalGraphic() throws Exception { URL url = StreamingRenderer.class.getResource("test-data/"); PointSymbolizer symb = sf.createPointSymbolizer(); ExternalGraphic eg = sf.createExternalGraphic(url + "icon64.png", "image/png"); symb.getGraphic().graphicalSymbols().add(eg); symb.getGraphic().setSize(ff.literal(20)); GraphicStyle2D gs = (GraphicStyle2D) sld.createPointStyle(feature, symb, range); BufferedImage img = gs.getImage(); assertEquals(20, img.getHeight()); assertEquals(20, img.getWidth()); }
private void rescale(Graphic graphic, Unit<Length> unit) { if (graphic != null) { graphic.setSize(rescale(graphic.getSize(), unit)); graphic.setGap(rescale(graphic.getGap(), unit)); Displacement disp = graphic.getDisplacement(); if (disp != null) { disp.setDisplacementX(rescale(disp.getDisplacementX(), unit)); disp.setDisplacementY(rescale(disp.getDisplacementY(), unit)); graphic.setDisplacement(disp); } if (graphic.graphicalSymbols() != null) { for (GraphicalSymbol gs : graphic.graphicalSymbols()) { if (gs instanceof Mark) { Mark mark = (Mark) gs; rescaleStroke(mark.getStroke(), unit); rescaleFill(mark.getFill(), unit); } } } } }
@Test public void testMarkOpacity() throws Exception { String yaml = "point: \n" + " symbols: \n" + " - mark: \n" + " fill-color: '#FF0000'\n" + " fill-opacity: 0.5\n"; // Not just 'opacity' StyledLayerDescriptor sld = Ysld.parse(yaml); PointSymbolizer p = SLD.pointSymbolizer(SLD.defaultStyle(sld)); assertThat( ((Mark) p.getGraphic().graphicalSymbols().get(0)).getFill().getOpacity(), literal(lexEqualTo(0.5d))); }
public void testMarkSizeCalculation() throws Exception { assertFalse(MarkStyle2D.isMaxMarkSizeEnabled()); PointSymbolizer symb = sf.createPointSymbolizer(); Mark myMark = sf.createMark(); myMark.setWellKnownName(ff.literal("square")); symb.getGraphic().graphicalSymbols().add(myMark); MarkStyle2D ms = (MarkStyle2D) sld.createPointStyle(feature, symb, range); assertFalse(MarkStyle2D.isMaxMarkSizeEnabled()); MarkStyle2D.setMaxMarkSizeEnabled(true); ms = (MarkStyle2D) sld.createPointStyle(feature, symb, range); assertTrue(MarkStyle2D.isMaxMarkSizeEnabled()); }
@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}")); }
@Test public void testRescalePolygonMargin() throws Exception { // create a graphic that needs rescaling StyleBuilder sb = new StyleBuilder(); // a graphic fill Fill fill = sb.createFill(); fill.setColor(null); fill.setGraphicFill( sb.createGraphic(null, sb.createMark("square", null, sb.createStroke(2)), null)); // a polygon and line symbolizer using them PolygonSymbolizer polygonSymbolizer = sb.createPolygonSymbolizer(sb.createStroke(), fill); polygonSymbolizer.getOptions().put(PolygonSymbolizer.GRAPHIC_MARGIN_KEY, "1 2 3 4"); // rescale it polygonSymbolizer.accept(visitor); PolygonSymbolizer rps = (PolygonSymbolizer) visitor.getCopy(); Mark rm = (Mark) rps.getFill().getGraphicFill().graphicalSymbols().get(0); assertEquals(4.0, rm.getStroke().getWidth().evaluate(null, Double.class), 0d); assertEquals("2 4 6 8", rps.getOptions().get(PolygonSymbolizer.GRAPHIC_MARGIN_KEY)); } }