/** * Retrieves the Fill from a PolygonSymbolizer. * * @param sym the symbolizer * @return the Fill or null if not found. */ public static Fill fill(PolygonSymbolizer sym) { if (sym == null) { return null; } return sym.getFill(); }
@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); }
@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); }
/** * Retrieves the fill opacity from the first PolygonSymbolizer. * * <p>If you are using something fun like rules you will need to do your own thing. * * @param symbolizer Polygon symbolizer information. * @return double of the polygon's fill opacity, or NaN if unavailable. */ public static double polyFillOpacity(PolygonSymbolizer symbolizer) { if (symbolizer == null) { return Double.NaN; } Fill fill = symbolizer.getFill(); return opacity(fill); }
/** Computes and returns the fill composite based on the feature and the symbolizer */ public Composite getFillComposite() { Fill fill = ps.getFill(); if (fill == null) { return null; } // get the opacity and prepare the composite float opacity = ((Float) fill.getOpacity().evaluate(feature, Float.class)).floatValue(); if (opacity == 1) { return null; } return AlphaComposite.getInstance(AlphaComposite.SRC_OVER, opacity); } }
/** * Retrieves the fill colour from a PolygonSymbolizer. * * <p>If you are using something fun like rules you will need to do your own thing. * * @param symbolizer Polygon symbolizer information. * @return Color of the polygon's fill, or null if unavailable. */ public static Color polyFill(PolygonSymbolizer symbolizer) { if (symbolizer == null) { return null; } Fill fill = symbolizer.getFill(); if (fill == null) { return null; } return color(fill.getColor()); }
/** @see org.geotools.styling.StyleVisitor#visit(org.geotools.styling.PolygonSymbolizer) */ public void visit(PolygonSymbolizer poly) { if (symbolizerGeometriesVisitEnabled) { if (poly.getGeometry() != null) { poly.getGeometry().accept(this, null); } else { this.defaultGeometryUsed = true; // they want the default geometry (see GEOS-469) } } if (poly.getStroke() != null) { poly.getStroke().accept(this); } if (poly.getFill() != null) { poly.getFill().accept(this); } }
public void visit(PolygonSymbolizer poly) { PolygonSymbolizer copy = sf.createPolygonSymbolizer(); copy.setFill(copy(poly.getFill())); copy.setGeometry(copy(poly.getGeometry())); copy.setUnitOfMeasure(poly.getUnitOfMeasure()); copy.setStroke(copy(poly.getStroke())); copy.getOptions().putAll(poly.getOptions()); if (STRICT && !copy.equals(poly)) { throw new IllegalStateException( "Was unable to duplicate provided PolygonSymbolizer:" + poly); } pages.push(copy); }
@Override public void visit(PolygonSymbolizer poly) { super.visit(poly); PolygonSymbolizer copy = (PolygonSymbolizer) pages.peek(); Unit<Length> uom = copy.getUnitOfMeasure(); rescaleStroke(copy.getStroke(), uom); rescaleFill(copy.getFill(), uom); scaleIntArrayOption(copy.getOptions(), PolygonSymbolizer.GRAPHIC_MARGIN_KEY, uom); copy.setUnitOfMeasure(Units.PIXEL); }
@Override public void visit(PolygonSymbolizer poly) { if (poly.getDescription() != null) { poly.getDescription().accept(this); } if (poly.getDisplacement() != null) { poly.getDisplacement().accept(this); } if (poly.getFill() != null) { poly.getFill().accept(this); } if (poly.getStroke() != null) { poly.getStroke().accept(this); } }
/** Computes and returns the fill based on the feature and the symbolizer */ public java.awt.Paint getFill() { Fill fill = ps.getFill(); if (fill == null) { return null; } Paint fillPaint = (Color) fill.getColor().evaluate(feature, Color.class); // if a graphic fill is to be used, prepare the paint accordingly.... org.geotools.styling.Graphic gr = fill.getGraphicFill(); if (gr != null) { SLDStyleFactory fac = new SLDStyleFactory(); fillPaint = fac.getTexturePaint(gr, feature, ps); } return fillPaint; }
public PolygonSymbolizerBuilder reset(PolygonSymbolizer symbolizer) { if (symbolizer == null) { return unset(); } stroke.reset(symbolizer.getStroke()); fill.reset(symbolizer.getFill()); uom = symbolizer.getUnitOfMeasure(); geometry = symbolizer.getGeometry(); unset = false; return this; }
public void visit(PolygonSymbolizer poly) { // adds the uom attribute according to the OGC SE specification AttributesImpl atts = new AttributesImpl(); Unit<Length> uom = poly.getUnitOfMeasure(); if (uom != null) atts.addAttribute("", "uom", "uom", "", UomOgcMapping.get(uom).getSEString()); start("PolygonSymbolizer", atts); encodeGeometryExpression(poly.getGeometry()); if (poly.getFill() != null) { poly.getFill().accept(this); } if (poly.getStroke() != null) { poly.getStroke().accept(this); } if (poly.getOptions() != null) { encodeVendorOptions(poly.getOptions()); } end("PolygonSymbolizer"); }
@Override protected void encode(PolygonSymbolizer sym) { inline(new StrokeEncoder(sym.getStroke())); inline(new FillEncoder(sym.getFill())); put("offset", sym.getPerpendicularOffset()); inline(new DisplacementEncoder(sym.getDisplacement())); super.encode(sym); } }
/** * Sets the colour to use for outline (stroke) and fill in a polygon symbolizer * * @param symbolizer the polygon symbolizer * @param colour the colour for polygon outlines and fill */ public static void setPolyColour(PolygonSymbolizer symbolizer, Color colour) { if (symbolizer == null || colour == null) { return; } Expression colourExp = ff.literal(colour); Stroke stroke = symbolizer.getStroke(); if (stroke == null) { stroke = sf.createStroke(colourExp, Stroke.DEFAULT.getWidth()); symbolizer.setStroke(stroke); } else { stroke.setColor(ff.literal(colour)); } Fill fill = symbolizer.getFill(); if (fill != null) { fill.setColor(colourExp); } }
@Test public void testPolygonSimple() throws Exception { // <UserStyle> // <Title>SLD Cook Book: Simple polygon</Title> // <FeatureTypeStyle> // <Rule> // <PolygonSymbolizer> // <Fill> // <CssParameter name="fill">#000080</CssParameter> // </Fill> // </PolygonSymbolizer> // </Rule> // </FeatureTypeStyle> // </UserStyle> Style style = parse("poly", "simple.sld"); PolygonSymbolizer poly = SLD.polySymbolizer(style); assertEquals(color("000080"), SLD.color(poly.getFill())); }
@Test public void testVisitPolygonSymbolizer_NullStroke() { try { UomRescaleStyleVisitor visitor = null; StyleBuilder styleBuilder = new StyleBuilder(); Fill fill = styleBuilder.createFill(Color.RED); PolygonSymbolizerImpl polySymb = (PolygonSymbolizerImpl) styleBuilder.createPolygonSymbolizer(null, fill); visitor = new UomRescaleStyleVisitor(10); polySymb.accept(visitor); PolygonSymbolizer rescaledPolySymb = (PolygonSymbolizer) visitor.getCopy(); assertEquals(polySymb.getFill(), rescaledPolySymb.getFill()); assertNull(rescaledPolySymb.getStroke()); assertNotSame(rescaledPolySymb, polySymb); } 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 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)); } }
@Test public void testPolygonWithStroke() throws Exception { // <UserStyle> // <Title>SLD Cook Book: Simple polygon with stroke</Title> // <FeatureTypeStyle> // <Rule> // <PolygonSymbolizer> // <Fill> // <CssParameter name="fill">#000080</CssParameter> // </Fill> // <Stroke> // <CssParameter name="stroke">#FFFFFF</CssParameter> // <CssParameter name="stroke-width">2</CssParameter> // </Stroke> // </PolygonSymbolizer> // </Rule> // </FeatureTypeStyle> // </UserStyle> Style style = parse("poly", "stroke.sld"); PolygonSymbolizer poly = SLD.polySymbolizer(style); assertEquals(color("000080"), SLD.color(poly.getFill())); assertEquals(color("FFFFFF"), SLD.color(poly.getStroke())); assertEquals(2, SLD.width(poly.getStroke())); }