protected Expression rescaleGraphicSize(Graphic gr) { return rescale(gr.getSize()); }
/** * Retrieves the size of the point's graphic, if found. * * <p>If you are using something fun like symbols you will need to do your own thing. * * @param symbolizer Point symbolizer information. * @return size of the graphic or {@linkplain #NOTFOUND} */ public static int pointSize(PointSymbolizer symbolizer) { if (symbolizer == null) { return NOTFOUND; } Graphic g = symbolizer.getGraphic(); if (g == null) { return NOTFOUND; } Expression exp = g.getSize(); return Filters.asInt(exp); }
size = Graphic.DEFAULT.getSize();
@Override protected Expression rescaleGraphicSize(Graphic gr) { Expression size = gr.getSize(); if (size == null || size == Expression.NIL) { PointSymbolizer symbolizer = sf.createPointSymbolizer(gr, null); Style2D style = ssf.createStyle(null, symbolizer, INFINITE_RANGE); if (style instanceof IconStyle2D) { IconStyle2D is = (IconStyle2D) style; size = ff.literal(is.getIcon().getIconHeight()); } else if (style instanceof GraphicStyle2D) { GraphicStyle2D gs = (GraphicStyle2D) style; size = ff.literal(gs.getImage().getHeight()); } else if (style instanceof MarkStyle2D) { MarkStyle2D ms = (MarkStyle2D) style; size = ff.literal(ms.getSize()); } } return rescale(size); } }
/** @see org.geotools.styling.StyleVisitor#visit(org.geotools.styling.Graphic) */ public void visit(Graphic gr) { if (gr.getSymbols() != null) { Symbol[] symbols = gr.getSymbols(); for (int i = 0; i < symbols.length; i++) { Symbol symbol = symbols[i]; symbol.accept(this); } } if (gr.getOpacity() != null) { gr.getOpacity().accept(this, null); } if (gr.getRotation() != null) { gr.getRotation().accept(this, null); } if (gr.getSize() != null) { gr.getSize().accept(this, null); } if (gr.getDisplacement() != null) gr.getDisplacement().accept(this); if (gr.getAnchorPoint() != null) gr.getAnchorPoint().accept(this); }
@Test public void testResizeExternalGraphic() throws IOException { File imageFile = new File("./src/test/resources/org/geotools/renderer/lite/test-data/draw.png") .getCanonicalFile(); assertTrue(imageFile.exists()); String fileUrl = URLs.fileToUrl(imageFile).toExternalForm(); PointSymbolizer ps = sb.createPointSymbolizer( sb.createGraphic( null, null, sb.createExternalGraphic(fileUrl, "image/png"))); GraphicsAwareDpiRescaleStyleVisitor visitor = new GraphicsAwareDpiRescaleStyleVisitor(2); ps.accept(visitor); PointSymbolizer resized = (PointSymbolizer) visitor.getCopy(); Expression size = resized.getGraphic().getSize(); assertTrue(size instanceof Literal); // original image height was 22 assertEquals(44, size.evaluate(null, Integer.class).intValue()); }
public void visit(Graphic gr) { Graphic copy = null; Displacement displacementCopy = copy(gr.getDisplacement()); ExternalGraphic[] externalGraphicsCopy = copy(gr.getExternalGraphics()); Mark[] marksCopy = copy(gr.getMarks()); Expression opacityCopy = copy(gr.getOpacity()); Expression rotationCopy = copy(gr.getRotation()); Expression sizeCopy = copy(gr.getSize()); AnchorPoint anchorCopy = copy(gr.getAnchorPoint()); // Looks like Symbols are a "view" of marks and external graphics? // Symbol[] symbolCopys = copy( gr.getSymbols() ); copy = sf.createDefaultGraphic(); copy.setDisplacement(displacementCopy); copy.setAnchorPoint(anchorCopy); copy.setExternalGraphics(externalGraphicsCopy); copy.setMarks(marksCopy); copy.setOpacity(opacityCopy); copy.setRotation(rotationCopy); copy.setSize(sizeCopy); // copy.setSymbols(symbolCopys); if (STRICT) { if (!copy.equals(gr)) { throw new IllegalStateException("Was unable to duplicate provided Graphic:" + gr); } } pages.push(copy); }
protected void visitPointSymbolizerTest(double scaleMetersToPixel, Unit<Length> uom) { try { UomRescaleStyleVisitor visitor = null; double size = 100; double expectedRescaledSize = computeExpectedRescaleSize(size, scaleMetersToPixel, uom); StyleBuilder styleBuilder = new StyleBuilder(); PointSymbolizerImpl pointSymb = (PointSymbolizerImpl) styleBuilder.createPointSymbolizer(); pointSymb.setUnitOfMeasure(uom); FilterFactory2 filterFactory = new FilterFactoryImpl(); pointSymb.getGraphic().setSize(filterFactory.literal(size)); visitor = new UomRescaleStyleVisitor(scaleMetersToPixel); pointSymb.accept(visitor); PointSymbolizer rescaledPointSymb = (PointSymbolizer) visitor.getCopy(); double rescaledSize = rescaledPointSymb.getGraphic().getSize().evaluate(null, Double.class); assertEquals(Math.round(expectedRescaledSize), Math.round(rescaledSize)); assertNotSame(rescaledPointSymb, pointSymb); } catch (Exception e2) { java.util.logging.Logger.getGlobal().log(java.util.logging.Level.INFO, "", e2); fail(e2.getClass().getSimpleName() + " should not be thrown."); } }
@Test public void testResizeMark() { PointSymbolizer ps = sb.createPointSymbolizer(sb.createGraphic(null, sb.createMark("square"), null)); GraphicsAwareDpiRescaleStyleVisitor visitor = new GraphicsAwareDpiRescaleStyleVisitor(2); ps.accept(visitor); PointSymbolizer resized = (PointSymbolizer) visitor.getCopy(); Expression size = resized.getGraphic().getSize(); assertTrue(size instanceof Literal); assertEquals(32, size.evaluate(null, Integer.class).intValue()); }
public void visit(Graphic gr) { start("Graphic"); // encodeGeometryProperty(gr.getGeometryPropertyName()); Symbol[] symbols = gr.getSymbols(); for (int i = 0; i < symbols.length; i++) { symbols[i].accept(this); } element("Opacity", gr.getOpacity(), 1.0); element("Size", gr.getSize()); element("Rotation", gr.getRotation(), 0.0); if (gr.getAnchorPoint() != null) { visit(gr.getAnchorPoint()); } if (gr.getDisplacement() != null) { visit(gr.getDisplacement()); } end("Graphic"); }
@Test public void testPointWithGraphic() throws Exception { // <UserStyle> // <Title>GeoServer SLD Cook Book: Point as graphic</Title> // <FeatureTypeStyle> // <Rule> // <PointSymbolizer> // <Graphic> // <ExternalGraphic> // <OnlineResource // xlink:type="simple" // xlink:href="smileyface.png" /> // <Format>image/png</Format> // </ExternalGraphic> // <Size>32</Size> // </Graphic> // </PointSymbolizer> // </Rule> // </FeatureTypeStyle> // </UserStyle> Style style = parse("point", "graphic.sld"); Graphic graphic = SLD.graphic(SLD.pointSymbolizer(style)); assertEquals(32, Filters.asInt(graphic.getSize())); ExternalGraphic external = (ExternalGraphic) graphic.graphicalSymbols().get(0); assertEquals("smileyface.png", external.getLocation().getPath()); assertEquals("image/png", external.getFormat()); }
double size = evalToDouble(fill.getGraphicFill().getSize(), feature, 0); if (isVectorRenderingEnabled() || size > MAX_RASTERIZATION_SIZE) {
assertEquals("file:colorblocks.png", external.getLocation().toString()); assertEquals("image/png", external.getFormat()); assertEquals(93, Filters.asInt(g.getSize()));
@Override protected void encode(Graphic g) { if (!flatten) push("graphic"); inline(new AnchorPointEncoder(g.getAnchorPoint())); inline(new DisplacementEncoder(g.getDisplacement())); put("gap", nullIf(g.getGap(), 0d), nullIf(g.getInitialGap(), 0d)); put("opacity", nullIf(g.getOpacity(), 1)); put("size", g.getSize()); put("rotation", nullIf(g.getRotation(), 0d)); put("symbols", new SymbolsEncoder(g)); } }
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); } } } } }
/** * Tests size calculation of dynamically sized feature, using real-world units combined with * DPI-based resizing. */ @Test public void testCombinedResizingDpiUom() { // given: Point with dynamic size in real-world units int sizeNum = 10; double scaleDpi = 2; double scaleUom = 3; PointSymbolizer symbolizer = sb.createPointSymbolizer(); Graphic graphic = sb.createGraphic(); graphic.setSize(ff.function("strConcat", ff.property("size"), ff.literal("m"))); symbolizer.setGraphic(graphic); // when: DPI based resizing is applied RescaleStyleVisitor dpiVisitor = new GraphicsAwareDpiRescaleStyleVisitor(scaleDpi); symbolizer.accept(dpiVisitor); symbolizer = (PointSymbolizer) dpiVisitor.getCopy(); // and: UOM resizing is applied UomRescaleStyleVisitor uomVisitor = new UomRescaleStyleVisitor(scaleUom); uomVisitor.visit(symbolizer); symbolizer = (PointSymbolizer) uomVisitor.getCopy(); SimpleFeature feature = createFeatureSized(sizeNum); // then: only the UOM resizing must have an effect Double size = symbolizer.getGraphic().getSize().evaluate(feature, Double.class); assertEquals(sizeNum * scaleUom, size.doubleValue(), 0d); }
assertEquals(1, SLD.width(mark.getStroke())); assertEquals(12, Filters.asInt(g.getSize()));
assertEquals(1, SLD.width(mark.getStroke())); assertEquals(16, Filters.asInt(poly.getFill().getGraphicFill().getSize()));
assertEquals(5, Filters.asInt(g.getSize()));
"Graphic of TextSymbolizer2 has not been correctly duplicated", gr.getSize(), copy.getGraphic().getSize()); assertEquals( "Snippet of TextSymbolizer2 has not been correctly duplicated",