Java Code Examples for org.geotools.styling.PolygonSymbolizer#setFill()
The following examples show how to use
org.geotools.styling.PolygonSymbolizer#setFill() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SimpleFillSymbol.java From sldeditor with GNU General Public License v3.0 | 6 votes |
@Override public List<Symbolizer> convertToFill(String layerName, JsonElement element, int transparency) { if(element == null) return null; JsonObject obj = element.getAsJsonObject(); List<Symbolizer> symbolizerList = new ArrayList<Symbolizer>(); Expression fillColour = getColour(obj.get(SimpleFillSymbolKeys.FILL_COLOUR)); Expression transparencyExpression = getTransparency(transparency); Fill fill = null; if(fillColour != null) { fill = styleFactory.createFill(fillColour, transparencyExpression); } PolygonSymbolizer polygon = styleFactory.createPolygonSymbolizer(); polygon.setStroke(null); polygon.setFill(fill); symbolizerList.add(polygon); return symbolizerList; }
Example 2
Source File: FeatureLayerConfigurationPersistencyTest.java From snap-desktop with GNU General Public License v3.0 | 6 votes |
@SuppressWarnings({"deprecation"}) private static Style createStyle() { StyleFactory styleFactory = CommonFactoryFinder.getStyleFactory(null); FilterFactory filterFactory = CommonFactoryFinder.getFilterFactory(null); PolygonSymbolizer symbolizer = styleFactory.createPolygonSymbolizer(); Fill fill = styleFactory.createFill( filterFactory.literal("#FFAA00"), filterFactory.literal(0.5) ); symbolizer.setFill(fill); Rule rule = styleFactory.createRule(); rule.setSymbolizers(new Symbolizer[]{symbolizer}); FeatureTypeStyle fts = styleFactory.createFeatureTypeStyle(); fts.setRules(new Rule[]{rule}); Style style = styleFactory.createStyle(); style.addFeatureTypeStyle(fts); return style; }
Example 3
Source File: ShapefileLoader.java From snap-desktop with GNU General Public License v3.0 | 6 votes |
private static Style createPolygonStyle() { PolygonSymbolizer symbolizer = styleFactory.createPolygonSymbolizer(); Fill fill = styleFactory.createFill( filterFactory.literal("#FFAA00"), filterFactory.literal(0.5) ); final Stroke stroke = styleFactory.createStroke(filterFactory.literal(Color.BLACK), filterFactory.literal(1)); symbolizer.setFill(fill); symbolizer.setStroke(stroke); Rule rule = styleFactory.createRule(); rule.symbolizers().add(symbolizer); FeatureTypeStyle fts = styleFactory.createFeatureTypeStyle(); fts.rules().add(rule); Style style = styleFactory.createStyle(); style.featureTypeStyles().add(fts); return style; }
Example 4
Source File: RuleRenderVisitor.java From sldeditor with GNU General Public License v3.0 | 6 votes |
/** * (non-Javadoc) * * @see * org.geotools.styling.visitor.DuplicatingStyleVisitor#visit(org.geotools.styling.PolygonSymbolizer) */ 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); }
Example 5
Source File: ExtractAttributes.java From sldeditor with GNU General Public License v3.0 | 6 votes |
/** * (non-Javadoc) * * @see * org.geotools.styling.visitor.DuplicatingStyleVisitor#visit(org.geotools.styling.PolygonSymbolizer) */ @Override public void visit(PolygonSymbolizer poly) { PolygonSymbolizer copy = sf.createPolygonSymbolizer(); copy.setFill(copy(poly.getFill())); copy.setGeometry(copy(MultiPolygon.class, 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); }
Example 6
Source File: PictureFillSymbol.java From sldeditor with GNU General Public License v3.0 | 6 votes |
@Override public List<Symbolizer> convertToFill(String layerName, JsonElement element, int transparency) { if(element == null) return null; JsonObject obj = element.getAsJsonObject(); List<Symbolizer> symbolizerList = new ArrayList<Symbolizer>(); Fill fill = getFill(layerName, obj, transparency); PolygonSymbolizer polygon = styleFactory.createPolygonSymbolizer(); polygon.setStroke(null); polygon.setFill(fill); symbolizerList.add(polygon); return symbolizerList; }
Example 7
Source File: DefaultSymbols.java From sldeditor with GNU General Public License v3.0 | 5 votes |
/** * Creates the default polygon symbolizer. * * @return the polygon symbolizer */ public static PolygonSymbolizer createDefaultPolygonSymbolizer() { Stroke stroke = styleFactory.createStroke(ff.literal(DEFAULT_LINE_COLOUR), ff.literal(2)); Fill fill = styleFactory.getDefaultFill(); PolygonSymbolizer polygonSymbolizer = styleFactory.createPolygonSymbolizer(); polygonSymbolizer.setStroke(stroke); polygonSymbolizer.setFill(fill); return polygonSymbolizer; }
Example 8
Source File: SLDTreeLeafPolygon.java From sldeditor with GNU General Public License v3.0 | 5 votes |
@Override public void createFill(Symbolizer symbolizer) { if (symbolizer instanceof PolygonSymbolizer) { PolygonSymbolizer polygon = (PolygonSymbolizer) symbolizer; polygon.setFill(styleFactory.getDefaultFill()); } }
Example 9
Source File: SLDTreeLeafPolygon.java From sldeditor with GNU General Public License v3.0 | 5 votes |
@Override public void removeFill(Symbolizer symbolizer) { if (symbolizer instanceof PolygonSymbolizer) { PolygonSymbolizer polygon = (PolygonSymbolizer) symbolizer; polygon.setFill(null); } }
Example 10
Source File: SLDTreeLeafPolygonTest.java From sldeditor with GNU General Public License v3.0 | 5 votes |
/** * Test method for {@link * com.sldeditor.common.tree.leaf.SLDTreeLeafPolygon#hasFill(org.opengis.style.Symbolizer)}. */ @Test public void testHasFill() { SLDTreeLeafPolygon leaf = new SLDTreeLeafPolygon(); assertFalse(leaf.hasFill(null)); assertFalse(leaf.hasFill(DefaultSymbols.createDefaultPointSymbolizer())); PolygonSymbolizer polygonSymbolizer = DefaultSymbols.createDefaultPolygonSymbolizer(); assertTrue(leaf.hasFill(polygonSymbolizer)); polygonSymbolizer.setFill(null); assertFalse(leaf.hasFill(polygonSymbolizer)); }
Example 11
Source File: SLDTreeLeafPolygonTest.java From sldeditor with GNU General Public License v3.0 | 5 votes |
/** * Test method for {@link * com.sldeditor.common.tree.leaf.SLDTreeLeafPolygon#createFill(org.opengis.style.Symbolizer)}. */ @Test public void testCreateFill() { SLDTreeLeafPolygon leaf = new SLDTreeLeafPolygon(); PolygonSymbolizer polygonSymbolizer = DefaultSymbols.createDefaultPolygonSymbolizer(); polygonSymbolizer.setFill(null); leaf.createFill(polygonSymbolizer); assertTrue(polygonSymbolizer.getFill() != null); }
Example 12
Source File: StyleUtilities.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
/** * Creates a default {@link Rule} for a polygon. * * @return the default rule. */ public static Rule createDefaultPolygonRule() { PolygonSymbolizer polygonSymbolizer = sf.createPolygonSymbolizer(); Fill fill = createDefaultFill(); polygonSymbolizer.setFill(fill); polygonSymbolizer.setStroke(createDefaultStroke()); Rule rule = sf.createRule(); rule.setName("New rule"); rule.symbolizers().add(polygonSymbolizer); return rule; }
Example 13
Source File: PolygonSymbolizerWrapper.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
private void checkFillExists() { if (fill == null) { if (fillColor == null) { fillColor = DEFAULT_COLOR; } fill = sf.createFill(ff.literal(fillColor)); PolygonSymbolizer polygonSymbolizer = (PolygonSymbolizer) getSymbolizer(); polygonSymbolizer.setFill(fill); fillGraphicFill = fill.getGraphicFill(); } }
Example 14
Source File: PolygonFillDetailsTest.java From sldeditor with GNU General Public License v3.0 | 4 votes |
/** * Test method for {@link * com.sldeditor.ui.detail.PolygonFillDetailsTest#PolygonFillDetailsTest(java.lang.Class, * com.sldeditor.filter.v2.function.FunctionNameInterface)}. */ @Test public void testFillDetailsPolygon() { StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory(); FilterFactory ff = CommonFactoryFinder.getFilterFactory(); PolygonFillDetails panel = new PolygonFillDetails(); panel.populate(null); // Set up test data StyledLayerDescriptor sld = DefaultSymbols.createNewSLD(); SelectedSymbol.getInstance().createNewSLD(sld); NamedLayer namedLayer = DefaultSymbols.createNewNamedLayer(); String expectedNameLayerValue = "named layer test value"; namedLayer.setName(expectedNameLayerValue); Style style = DefaultSymbols.createNewStyle(); String expectedNameStyleValue = "style test value"; style.setName(expectedNameStyleValue); namedLayer.addStyle(style); FeatureTypeStyle fts = DefaultSymbols.createNewFeatureTypeStyle(); String expectedNameFTSValue = "feature type style test value"; fts.setName(expectedNameFTSValue); style.featureTypeStyles().add(fts); Rule rule = DefaultSymbols.createNewRule(); String expectedNameValue = "rule test value"; rule.setName(expectedNameValue); PolygonSymbolizer symbolizer = DefaultSymbols.createDefaultPolygonSymbolizer(); rule.symbolizers().add(symbolizer); fts.rules().add(rule); sld.layers().add(namedLayer); SelectedSymbol.getInstance().addNewStyledLayer(namedLayer); SelectedSymbol.getInstance().setStyledLayer(namedLayer); SelectedSymbol.getInstance().setStyle(style); SelectedSymbol.getInstance().setFeatureTypeStyle(fts); SelectedSymbol.getInstance().setRule(rule); SelectedSymbol.getInstance().setSymbolizer(symbolizer); panel.populate(SelectedSymbol.getInstance()); GraphicPanelFieldManager fieldDataManager = panel.getFieldDataManager(); assertNotNull(fieldDataManager); double expectedAngle = 14.5; FieldConfigDouble angleField = (FieldConfigDouble) fieldDataManager.get(FieldIdEnum.ANGLE); angleField.populateField(expectedAngle); FieldConfigSlider opacityField = (FieldConfigSlider) fieldDataManager.get(FieldIdEnum.OVERALL_OPACITY); double opacity = 0.15; opacityField.populateField(opacity); panel.dataChanged(FieldIdEnum.UNKNOWN); double actualValue = angleField.getDoubleValue(); assertTrue(Math.abs(actualValue - expectedAngle) < 0.01); assertTrue(panel.isDataPresent()); actualValue = opacityField.getDoubleValue(); assertTrue(Math.abs(actualValue - opacity) < 0.01); // Reset to default value panel.preLoadSymbol(); actualValue = angleField.getDoubleValue(); assertTrue(Math.abs(actualValue - 0.0) < 0.01); actualValue = opacityField.getDoubleValue(); assertTrue(Math.abs(actualValue - 1.0) < 0.01); // Increase the coverage, set the fill Fill fill = styleFactory.createFill(ff.literal("#123456")); Graphic graphic = styleFactory.createDefaultGraphic(); fill.setGraphicFill(graphic); symbolizer.setFill(fill); panel.populate(SelectedSymbol.getInstance()); Graphic graphic2 = styleFactory.createDefaultGraphic(); graphic2.setDisplacement(styleFactory.createDisplacement(ff.literal(6.0), ff.literal(7.0))); graphic2.setAnchorPoint(styleFactory.anchorPoint(ff.literal(6.0), ff.literal(7.0))); Fill fill2 = styleFactory.createFill(ff.literal("#123456")); fill2.setGraphicFill(graphic2); symbolizer.setFill(fill2); panel.populate(SelectedSymbol.getInstance()); symbolizer.setFill(null); panel.populate(SelectedSymbol.getInstance()); }
Example 15
Source File: SelectedSymbolTest.java From sldeditor with GNU General Public License v3.0 | 4 votes |
/** Test method for {@link com.sldeditor.common.data.SelectedSymbol#getGraphic()}. */ @Test public void testGetGraphic() { SelectedSymbol.destroyInstance(); SelectedSymbol instance = SelectedSymbol.getInstance(); // CHECKSTYLE:OFF Rule rule = DefaultSymbols.createNewRule(); FeatureTypeStyle fts = DefaultSymbols.createNewFeatureTypeStyle(); Style style = DefaultSymbols.createNewStyle(); NamedLayer namedLayer = DefaultSymbols.createNewNamedLayer(); StyledLayerDescriptor sld = DefaultSymbols.createNewSLD(); PolygonSymbolizer symbolizer = DefaultSymbols.createDefaultPolygonSymbolizer(); // CHECKSTYLE:ON instance.createNewSLD(sld); instance.setSld(sld); System.out.println("Select named layer"); instance.addNewStyledLayer(namedLayer); instance.setStyledLayer(namedLayer); instance.addNewStyle(style); instance.setStyle(style); instance.addNewFeatureTypeStyle(fts); instance.setFeatureTypeStyle(fts); instance.addNewRule(rule); instance.setRule(rule); instance.addSymbolizerToRule(symbolizer); instance.setSymbolizer(symbolizer); Graphic graphic = getGraphic(symbolizer); assertNull(graphic); Fill graphicFill = DefaultSymbols.createDefaultGraphicFill(); PolygonSymbolizer newSymbolizer = DefaultSymbols.createDefaultPolygonSymbolizer(); newSymbolizer.setFill(graphicFill); instance.addSymbolizerToRule(newSymbolizer); instance.setSymbolizer(newSymbolizer); graphic = getGraphic(newSymbolizer); assertNotNull(graphic); assertTrue(instance.hasFill()); assertTrue(instance.hasStroke()); LineSymbolizer lineSymbolizer = DefaultSymbols.createDefaultLineSymbolizer(); instance.addSymbolizerToRule(lineSymbolizer); instance.setSymbolizer(lineSymbolizer); graphic = getGraphic(lineSymbolizer); assertNull(graphic); assertFalse(instance.hasFill()); assertTrue(instance.hasStroke()); PointSymbolizer pointSymbolizer = DefaultSymbols.createDefaultPointSymbolizer(); instance.addSymbolizerToRule(pointSymbolizer); instance.setSymbolizer(pointSymbolizer); graphic = getGraphic(pointSymbolizer); assertNotNull(graphic); assertTrue(instance.hasFill()); assertFalse(instance.hasStroke()); }
Example 16
Source File: LineFillSymbol.java From sldeditor with GNU General Public License v3.0 | 4 votes |
/** * Convert to fill. * * @param layerName the layer name * @param element the element * @param transparency the transparency * @return the list */ /* (non-Javadoc) * @see com.sldeditor.convert.esri.symbols.EsriFillSymbolInterface#convertToFill(java.lang.String, com.google.gson.JsonElement, int) */ @Override public List<Symbolizer> convertToFill(String layerName, JsonElement element, int transparency) { if (layerName == null) { return null; } if (element == null) { return null; } List<Symbolizer> symbolizerList = new ArrayList<Symbolizer>(); JsonObject obj = element.getAsJsonObject(); Expression size = ff.literal(getDouble(obj, LineFillSymbolKeys.SEPARATION)); Expression opacity = null; double lineAngle = normaliseAngle(getDouble(obj, CommonSymbolKeys.ANGLE)); Expression rotation = null; AnchorPoint anchorPoint = null; Displacement displacement = null; Expression fillColour = getColour(obj.get(LineFillSymbolKeys.FILL_COLOUR)); Expression fillColourOpacity = null; Expression join = null; Expression cap = null; float[] dashes = null; Expression offset = null; Expression width = ff.literal(1.0); Stroke outlineStroke = null; List<Stroke> strokeList = SymbolManager.getInstance().getStrokeList(obj.get(LineFillSymbolKeys.OUTLINE)); // TODO if((strokeList != null) && (strokeList.size() == 1)) { outlineStroke = strokeList.get(0); width = outlineStroke.getWidth(); } Expression wellKnownName = null; if(isDoubleEqual(lineAngle, 0.0) || isDoubleEqual(lineAngle, 180.0)) { wellKnownName = ff.literal("shape://horline"); } else if(isDoubleEqual(lineAngle, 90.0) || isDoubleEqual(lineAngle, 270.0)) { wellKnownName = ff.literal("shape://vertline"); } else if(isDoubleEqual(lineAngle, 45.0) || isDoubleEqual(lineAngle, 225.0)) { wellKnownName = ff.literal("shape://slash"); } else if(isDoubleEqual(lineAngle, 135.0) || isDoubleEqual(lineAngle, 315.0)) { wellKnownName = ff.literal("shape://backslash"); } else { wellKnownName = ff.literal("shape://vertline"); rotation = ff.literal(lineAngle); } Fill fill = null; Stroke markStroke = styleFactory.stroke(fillColour, fillColourOpacity, width, join, cap, dashes, offset); Mark mark = styleFactory.createMark(wellKnownName, markStroke, fill, size, rotation); List<GraphicalSymbol> symbolList = new ArrayList<GraphicalSymbol>(); symbolList.add(mark); GraphicFill graphicFill = styleFactory.graphicFill(symbolList, opacity, size, rotation, anchorPoint, displacement); Fill completeFill = styleFactory.fill(graphicFill, null, null); PolygonSymbolizer polygonSymbolizer = styleFactory.createPolygonSymbolizer(); polygonSymbolizer.setFill(completeFill); polygonSymbolizer.setStroke(outlineStroke); symbolizerList.add(polygonSymbolizer); return symbolizerList; }
Example 17
Source File: SLDExternalImagesTest.java From sldeditor with GNU General Public License v3.0 | 2 votes |
/** * Creates the test polygon. * * @param url the url * @return the styled layer descriptor */ private StyledLayerDescriptor createTestPolygon(URL url) { StyleBuilder sb = new StyleBuilder(); StyleFactory styleFactory = sb.getStyleFactory(); StyledLayerDescriptor sld = styleFactory.createStyledLayerDescriptor(); NamedLayer namedLayer = styleFactory.createNamedLayer(); sld.addStyledLayer(namedLayer); Style style = styleFactory.createStyle(); namedLayer.addStyle(style); List<FeatureTypeStyle> ftsList = style.featureTypeStyles(); FeatureTypeStyle fts = styleFactory.createFeatureTypeStyle(); ftsList.add(fts); Rule rule = styleFactory.createRule(); fts.rules().add(rule); PolygonSymbolizer polygon = styleFactory.createPolygonSymbolizer(); rule.symbolizers().add(polygon); Graphic graphicFill1 = createGraphic(url, styleFactory); Graphic graphicFill2 = createGraphic(url, styleFactory); Graphic graphicStroke = createGraphic(url, styleFactory); Fill fill = styleFactory.createFill(null, null, null, graphicFill1); polygon.setFill(fill); Stroke stroke = styleFactory.createStroke( null, null, null, null, null, null, null, graphicFill2, graphicStroke); polygon.setStroke(stroke); return sld; }