org.geotools.styling.Symbolizer Java Examples
The following examples show how to use
org.geotools.styling.Symbolizer.
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: SLDEditorBufferedImageLegendGraphicBuilder.java From sldeditor with GNU General Public License v3.0 | 6 votes |
/** * Returns a sample feature for the given rule, with the following criteria: - if a sample is * given in input is returned in output - if a sample is not given in input, scan the rule * symbolizers to find the one with the max dimensionality, and return a sample for that * dimensionality. * * @param featureType featureType used to create a sample, if none is given as input * @param sample feature sample to be returned as is in output, if defined * @param rule rule containing symbolizers to scan for max dimensionality */ private Feature getSampleFeatureForRule( FeatureType featureType, Feature sample, final Rule rule) { Symbolizer[] symbolizers = rule.getSymbolizers(); // if we don't have a sample as input, we need to create a sampleFeature // looking at the requested symbolizers (we chose the one with the max // dimensionality and create a congruent sample) if (sample == null) { int dimensionality = 1; for (int sIdx = 0; sIdx < symbolizers.length; sIdx++) { final Symbolizer symbolizer = symbolizers[sIdx]; if (LineSymbolizer.class.isAssignableFrom(symbolizer.getClass())) { dimensionality = 2; } if (PolygonSymbolizer.class.isAssignableFrom(symbolizer.getClass())) { dimensionality = 3; } } return createSampleFeature(featureType, dimensionality); } else { return sample; } }
Example #2
Source File: StyleUtilities.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
/** * Get the offset from a {@link Symbolizer}. * * @param symbolizer the symbolizer. * @return the offset. */ @SuppressWarnings("rawtypes") public static Point2D getOffset( Symbolizer symbolizer ) { Expression geometry = symbolizer.getGeometry(); if (geometry != null) { if (geometry instanceof FilterFunction_offset) { FilterFunction_offset offsetFunction = (FilterFunction_offset) geometry; List parameters = offsetFunction.getParameters(); Expression xOffsetExpr = (Expression) parameters.get(1); Expression yOffsetExpr = (Expression) parameters.get(2); Double xOffsetDouble = xOffsetExpr.evaluate(null, Double.class); Double yOffsetDouble = yOffsetExpr.evaluate(null, Double.class); if (xOffsetDouble != null && yOffsetDouble != null) { Point2D.Double point = new Point2D.Double(xOffsetDouble, yOffsetDouble); return point; } } } return null; }
Example #3
Source File: NewRasterSLDTest.java From sldeditor with GNU General Public License v3.0 | 6 votes |
/** Test new point sld. */ @Test public void testNewRasterSLD() { NewRasterSLD newData = new NewRasterSLD(); StyledLayerDescriptor sld = newData.create(); assertTrue(sld.layers().size() == 1); StyledLayer styledLayer = sld.layers().get(0); NamedLayer namedLayer = (NamedLayer) styledLayer; Symbolizer symbolizer = namedLayer .styles() .get(0) .featureTypeStyles() .get(0) .rules() .get(0) .symbolizers() .get(0); assertTrue(symbolizer instanceof RasterSymbolizer); }
Example #4
Source File: MultiLayerMarkerSymbol.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; List<Symbolizer> symbolizerList = null; JsonArray layerList = element.getAsJsonArray(); if (layerList.size() > 0) { symbolizerList = new ArrayList<Symbolizer>(); for (int index = 0; index < layerList.size(); index++) { JsonElement layerElement = layerList.get(index); symbolizerList.addAll(SymbolManager.getInstance().getFillSymbol(layerName, layerElement, transparency)); } } return symbolizerList; }
Example #5
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 #6
Source File: NewPolygonSLDTest.java From sldeditor with GNU General Public License v3.0 | 6 votes |
/** Test new polygon sld. */ @Test public void testNewPolygonSLD() { NewPolygonSLD newData = new NewPolygonSLD(); StyledLayerDescriptor sld = newData.create(); assertTrue(sld.layers().size() == 1); StyledLayer styledLayer = sld.layers().get(0); NamedLayer namedLayer = (NamedLayer) styledLayer; Symbolizer symbolizer = namedLayer .styles() .get(0) .featureTypeStyles() .get(0) .rules() .get(0) .symbolizers() .get(0); assertTrue(symbolizer instanceof PolygonSymbolizer); }
Example #7
Source File: NewPointSLDTest.java From sldeditor with GNU General Public License v3.0 | 6 votes |
/** Test new point sld. */ @Test public void testNewPointSLD() { NewPointSLD newData = new NewPointSLD(); StyledLayerDescriptor sld = newData.create(); assertTrue(sld.layers().size() == 1); StyledLayer styledLayer = sld.layers().get(0); NamedLayer namedLayer = (NamedLayer) styledLayer; Symbolizer symbolizer = namedLayer .styles() .get(0) .featureTypeStyles() .get(0) .rules() .get(0) .symbolizers() .get(0); assertTrue(symbolizer instanceof PointSymbolizer); }
Example #8
Source File: SymbolizerFilterVisitorTest.java From geomajas-project-server with GNU Affero General Public License v3.0 | 6 votes |
@Test public void testGeometries() throws IOException{ SymbolizerFilterVisitor visitor = new SymbolizerFilterVisitor(); visitor.setIncludeGeometry(true); visitor.setIncludeText(false); SLDParser parser = new SLDParser(styleFactory); parser.setInput(getClass().getResource("point_pointwithdefaultlabel.sld")); Style[] styles = parser.readXML(); Assert.assertEquals(1, styles.length); visitor.visit(styles[0]); Style copy = (Style) visitor.getCopy(); FeatureTypeStyle featureTypeStyle = copy.featureTypeStyles().iterator().next(); Rule rule = featureTypeStyle.rules().iterator().next(); Iterator<Symbolizer> it = rule.symbolizers().iterator(); Assert.assertTrue(it.next() instanceof PointSymbolizer); Assert.assertFalse(it.hasNext()); }
Example #9
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 #10
Source File: NewLineSLDTest.java From sldeditor with GNU General Public License v3.0 | 6 votes |
/** Test new line sld. */ @Test public void testNewLineSLD() { NewLineSLD newData = new NewLineSLD(); StyledLayerDescriptor sld = newData.create(); assertTrue(sld.layers().size() == 1); StyledLayer styledLayer = sld.layers().get(0); NamedLayer namedLayer = (NamedLayer) styledLayer; Symbolizer symbolizer = namedLayer .styles() .get(0) .featureTypeStyles() .get(0) .rules() .get(0) .symbolizers() .get(0); assertTrue(symbolizer instanceof LineSymbolizer); }
Example #11
Source File: SymbolizerFilterVisitorTest.java From geomajas-project-server with GNU Affero General Public License v3.0 | 6 votes |
@Test public void testLabels() throws IOException { SymbolizerFilterVisitor visitor = new SymbolizerFilterVisitor(); visitor.setIncludeGeometry(false); visitor.setIncludeText(true); SLDParser parser = new SLDParser(styleFactory); parser.setInput(getClass().getResource("point_pointwithdefaultlabel.sld")); Style[] styles = parser.readXML(); Assert.assertEquals(1, styles.length); visitor.visit(styles[0]); Style copy = (Style) visitor.getCopy(); FeatureTypeStyle featureTypeStyle = copy.featureTypeStyles().iterator().next(); Rule rule = featureTypeStyle.rules().iterator().next(); Iterator<Symbolizer> it = rule.symbolizers().iterator(); Assert.assertTrue(it.next() instanceof TextSymbolizer); Assert.assertFalse(it.hasNext()); }
Example #12
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 #13
Source File: StrokeTreeItemTest.java From sldeditor with GNU General Public License v3.0 | 6 votes |
/** * Test method for {@link * com.sldeditor.ui.tree.item.StrokeTreeItem#itemSelected(javax.swing.tree.DefaultMutableTreeNode, * java.lang.Object)}. */ @Test public void testItemSelected() { StrokeTreeItem item = new StrokeTreeItem(); item.itemSelected(null, null); Symbolizer symbolizer = DefaultSymbols.createDefaultLineSymbolizer(); DefaultMutableTreeNode parentNode = new DefaultMutableTreeNode(); parentNode.setUserObject(symbolizer); DefaultMutableTreeNode node = new DefaultMutableTreeNode(); parentNode.add(node); item.itemSelected(node, symbolizer); // Get the code coverage stats up item.itemSelected(parentNode, symbolizer); parentNode.setUserObject(item); item.itemSelected(node, null); }
Example #14
Source File: SimpleLineSymbol.java From sldeditor with GNU General Public License v3.0 | 6 votes |
@Override public void convert(Rule rule, JsonElement element, String layerName, int transparency) { if(element == null) return; if(rule == null) return; JsonObject obj = element.getAsJsonObject(); @SuppressWarnings("unused") int style = getInt(obj, CommonSymbolKeys.STYLE); List<Symbolizer> symbolizerList = rule.symbolizers(); List<Stroke> strokeList = convert(obj); Stroke stroke = null; if(!strokeList.isEmpty()) { stroke = strokeList.get(0); } LineSymbolizer lineSymbolizer = styleFactory.createLineSymbolizer(stroke, null); symbolizerList.add(lineSymbolizer); }
Example #15
Source File: SimpleMarkerSymbol.java From sldeditor with GNU General Public License v3.0 | 6 votes |
@Override public void convert(Rule rule, JsonElement element, String layerName, int transparency) { if(element == null) return; if(rule == null) return; List<Symbolizer> symbolizerList = rule.symbolizers(); List<Graphic> markerList = convert(element); if(markerList != null) { for(Graphic marker : markerList) { PointSymbolizer pointSymbolizer = styleFactory.createPointSymbolizer(marker, null); symbolizerList.add(pointSymbolizer); } } }
Example #16
Source File: RuleWrapper.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
/** * Returns the type of geometry/raster that the {@link SymbolizerWrapper} represents. * * @return the symbolizer type. */ public EGeometryType getType() { SymbolizerWrapper geometrySymbolizersWrapper = getGeometrySymbolizersWrapper(); if (geometrySymbolizersWrapper == null) { return null; } Symbolizer symbolizer = geometrySymbolizersWrapper.getSymbolizer(); if (symbolizer instanceof PointSymbolizer) { return EGeometryType.POINT; } else if (symbolizer instanceof LineSymbolizer) { return EGeometryType.LINESTRING; } else if (symbolizer instanceof PolygonSymbolizer) { return EGeometryType.POLYGON; } else if (symbolizer instanceof RasterSymbolizer) { throw new RuntimeException("Not implemented yet!"); } return null; }
Example #17
Source File: RuleWrapper.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
/** * Remove the {@link TextSymbolizerWrapper} from the ruleWrapper. */ public void removeTextSymbolizersWrapper() { List<SymbolizerWrapper> removeSW = new ArrayList<SymbolizerWrapper>(); List<Symbolizer> removeS = new ArrayList<Symbolizer>(); List<Symbolizer> symbolizers = rule.symbolizers(); for( SymbolizerWrapper symbolizerWrapper : symbolizersWrapperList ) { if (symbolizerWrapper.isTextSymbolizer()) { Symbolizer symbolizer = symbolizerWrapper.getSymbolizer(); removeSW.add(symbolizerWrapper); removeS.add(symbolizer); } } symbolizersWrapperList.removeAll(removeSW); symbolizers.removeAll(removeS); }
Example #18
Source File: RuleWrapper.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
private SymbolizerWrapper getWrapper( Symbolizer symbolizer ) { SymbolizerWrapper symbolizerWrapper = null; if (symbolizer instanceof PointSymbolizer) { symbolizerWrapper = new PointSymbolizerWrapper(symbolizer, this); } else if (symbolizer instanceof LineSymbolizer) { symbolizerWrapper = new LineSymbolizerWrapper(symbolizer, this); } else if (symbolizer instanceof PolygonSymbolizer) { symbolizerWrapper = new PolygonSymbolizerWrapper(symbolizer, this); } else if (symbolizer instanceof TextSymbolizer) { symbolizerWrapper = new TextSymbolizerWrapper(symbolizer, this, getType()); } else if (symbolizer instanceof RasterSymbolizer) { symbolizerWrapper = new RasterSymbolizerWrapper(symbolizer, this); } return symbolizerWrapper; }
Example #19
Source File: CheckBoxNodeEditor.java From sldeditor with GNU General Public License v3.0 | 6 votes |
public boolean isCellEditable(EventObject event) { boolean returnValue = false; if (event instanceof MouseEvent) { MouseEvent mouseEvent = (MouseEvent) event; TreePath path = tree.getPathForLocation(mouseEvent.getX(), mouseEvent.getY()); if (path != null) { Object node = path.getLastPathComponent(); if (node instanceof DefaultMutableTreeNode) { DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) node; if (treeNode.getParent() != null) { Object parentUserObject = ((DefaultMutableTreeNode) treeNode.getParent()).getUserObject(); if (parentUserObject instanceof PolygonSymbolizer) { symbolizer = (Symbolizer) parentUserObject; userObject = treeNode.getUserObject(); returnValue = treeNode.isLeaf(); } } } } } return returnValue; }
Example #20
Source File: SelectedSymbol.java From sldeditor with GNU General Public License v3.0 | 6 votes |
/** * Checks if the selected Style contains a raster symbol. * * @return true, if is raster symbol */ public boolean isRasterSymbol() { Style style = getStyle(); if (style != null) { for (FeatureTypeStyle fts : style.featureTypeStyles()) { for (Rule rule : fts.rules()) { for (Symbolizer symbolizer : rule.symbolizers()) { if (symbolizer instanceof RasterSymbolizer) { return true; } } } } } return false; }
Example #21
Source File: RuleWrapper.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
public RuleWrapper( Rule rule, FeatureTypeStyleWrapper parent ) { this.rule = rule; this.parent = parent; name = rule.getName(); try { maxScale = String.valueOf(rule.getMaxScaleDenominator()); minScale = String.valueOf(rule.getMinScaleDenominator()); } catch (Exception e) { maxScale = DEFAULT_MAXSCALE; minScale = DEFAULT_MINSCALE; } List<Symbolizer> symbolizers = rule.symbolizers(); for( Symbolizer symbolizer : symbolizers ) { SymbolizerWrapper wrapper = getWrapper(symbolizer); symbolizersWrapperList.add(wrapper); } }
Example #22
Source File: SymbolizerFilterVisitorTest.java From geomajas-project-server with GNU Affero General Public License v3.0 | 6 votes |
@Test public void testTransformation() throws IOException{ SymbolizerFilterVisitor visitor = new SymbolizerFilterVisitor(); visitor.setIncludeGeometry(true); visitor.setIncludeText(true); SLDParser parser = new SLDParser(styleFactory); parser.setInput(getClass().getResource("heatmap.sld")); Style[] styles = parser.readXML(); Assert.assertEquals(1, styles.length); visitor.visit(styles[0]); Style copy = (Style) visitor.getCopy(); FeatureTypeStyle featureTypeStyle = copy.featureTypeStyles().iterator().next(); Assert.assertNotNull(featureTypeStyle.getTransformation()); Rule rule = featureTypeStyle.rules().iterator().next(); Iterator<Symbolizer> it = rule.symbolizers().iterator(); Assert.assertTrue(it.next() instanceof RasterSymbolizer); Assert.assertFalse(it.hasNext()); }
Example #23
Source File: SymbolizerTreeItem.java From sldeditor with GNU General Public License v3.0 | 6 votes |
/** * Default string. * * @param symbol the symbol * @return the string */ private String defaultString(Symbolizer symbol) { String name = ""; if (symbol instanceof PointSymbolizer) { name = DEFAULT_MARKER_NAME; } else if (symbol instanceof TextSymbolizer) { name = DEFAULT_TEXT_NAME; } else if (symbol instanceof LineSymbolizer) { name = DEFAULT_LINE_NAME; } else if (symbol instanceof PolygonSymbolizer) { name = DEFAULT_POLYGON_NAME; } else if (symbol instanceof RasterSymbolizer) { name = DEFAULT_RASTER_NAME; } return name; }
Example #24
Source File: SelectedSymbol.java From sldeditor with GNU General Public License v3.0 | 6 votes |
/** * Removes the symbolizer. * * @param symbolizerToDelete the symbolizer to delete */ public void removeSymbolizer(Symbolizer symbolizerToDelete) { List<Symbolizer> symbolizerList = this.symbolData.getRule().symbolizers(); int indexFound = -1; int index = 0; for (Symbolizer symbolizer : symbolizerList) { if (symbolizer == symbolizerToDelete) { indexFound = index; break; } else { index++; } } if (indexFound > -1) { symbolizerList.remove(indexFound); } }
Example #25
Source File: SLDTree.java From sldeditor with GNU General Public License v3.0 | 6 votes |
/** * Populate styles. * * @param styledLayerTreeNode the styled layer tree node * @param styleList the style list */ private void populateStyles(DefaultMutableTreeNode styledLayerTreeNode, List<Style> styleList) { for (Style style : styleList) { DefaultMutableTreeNode styleTreeNode = addObject(styledLayerTreeNode, style, true); for (FeatureTypeStyle fts : style.featureTypeStyles()) { DefaultMutableTreeNode ftsTreeNode = addObject(styleTreeNode, fts, true); for (Rule rule : fts.rules()) { DefaultMutableTreeNode ruleTreeNode = addObject(ftsTreeNode, rule, true); for (Symbolizer symbolizer : rule.symbolizers()) { populateSymbolizer(ruleTreeNode, symbolizer); } } } } }
Example #26
Source File: SLDTree.java From sldeditor with GNU General Public License v3.0 | 6 votes |
/** * Populate symbolizer. * * @param ruleTreeNode the rule tree node * @param symbolizer the symbolizer */ private void populateSymbolizer(DefaultMutableTreeNode ruleTreeNode, Symbolizer symbolizer) { DefaultMutableTreeNode symbolizerTreeNode = addObject(ruleTreeNode, symbolizer, true); if ((symbolizer instanceof PointSymbolizer) || (symbolizer instanceof PolygonSymbolizer)) { addObject( symbolizerTreeNode, SLDTreeLeafFactory.getInstance().getFill(symbolizer), true); } if ((symbolizer instanceof PolygonSymbolizer) || (symbolizer instanceof LineSymbolizer)) { addObject( symbolizerTreeNode, SLDTreeLeafFactory.getInstance().getStroke(symbolizer), true); } if (symbolizer instanceof RasterSymbolizer) { handleRasterSymbolizer(symbolizer, symbolizerTreeNode); } }
Example #27
Source File: LineSymbolizerWrapper.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
private void initEndPointSymbolizers() { for( Symbolizer x : super.getParent().getRule().getSymbolizers() ) { if (x instanceof PointSymbolizer) { PointSymbolizer pnt = (PointSymbolizer) x; Expression ex = pnt.getGeometry(); boolean endpnt = ex instanceof FilterFunction_endPoint; boolean startpnt = ex instanceof FilterFunction_startPoint; if (endpnt || startpnt) { GraphicalSymbol gs = pnt.getGraphic().graphicalSymbols().get(0); if (gs instanceof Mark) { String name = ((Mark) gs).getWellKnownName().evaluate(null, String.class); if (StyleUtilities.lineEndStyles.values().contains(name)) { if (endpnt) { endPointStyle = new PointSymbolizerWrapper(pnt, super.getParent()); } else if (startpnt) { startPointStyle = new PointSymbolizerWrapper(pnt, super.getParent()); } } } } } } }
Example #28
Source File: SLDTreeTools.java From sldeditor with GNU General Public License v3.0 | 6 votes |
/** * Gets the rule tree node. * * @return the rule tree node */ private DefaultMutableTreeNode getRuleTreeNode() { if (symbolTree != null) { TreePath path = symbolTree.getSelectionPath(); DefaultMutableTreeNode lastNode = (DefaultMutableTreeNode) path.getLastPathComponent(); Object obj = lastNode.getUserObject(); if (obj instanceof Symbolizer) { return (DefaultMutableTreeNode) lastNode.getParent(); } else if (obj instanceof Rule) { return lastNode; } } return rootNode; }
Example #29
Source File: SLDUtils.java From sldeditor with GNU General Public License v3.0 | 6 votes |
/** * Traverse symbolizers. * * @param sld the sld * @param traverseSymbolizersInterface the traverse symbolizers interface */ public static void traverseSymbolizers( StyledLayerDescriptor sld, TraverseSymbolizersInterface traverseSymbolizersInterface) { List<StyledLayer> styledLayerList = sld.layers(); for (StyledLayer styledLayer : styledLayerList) { List<Style> styleList = SLDUtils.getStylesList(styledLayer); for (Style style : styleList) { for (FeatureTypeStyle fts : style.featureTypeStyles()) { for (Rule rule : fts.rules()) { for (org.opengis.style.Symbolizer symbolizer : rule.symbolizers()) { processSymbolizer(symbolizer, traverseSymbolizersInterface); } } } } } }
Example #30
Source File: SelectedSymbolTest.java From sldeditor with GNU General Public License v3.0 | 6 votes |
/** * Gets the graphic. * * @param symbolizer the symbolizer * @return the graphic */ private Graphic getGraphic(Symbolizer symbolizer) { Graphic graphic = null; if (symbolizer instanceof PointSymbolizerImpl) { PointSymbolizer pointSymbolizer = (PointSymbolizer) symbolizer; graphic = pointSymbolizer.getGraphic(); } else if (symbolizer instanceof PolygonSymbolizerImpl) { PolygonSymbolizer polygonSymbolizer = (PolygonSymbolizer) symbolizer; if (polygonSymbolizer != null) { Fill fill = polygonSymbolizer.getFill(); if (fill != null) { graphic = fill.getGraphicFill(); } } } return graphic; }