org.geotools.styling.StyleFactory Java Examples
The following examples show how to use
org.geotools.styling.StyleFactory.
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: ImageDataLoader.java From gama with GNU General Public License v3.0 | 7 votes |
private static Style createStyle(int band, double min, double max) { FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(); StyleFactory sf = CommonFactoryFinder.getStyleFactory(); RasterSymbolizer sym = sf.getDefaultRasterSymbolizer(); ColorMap cMap = sf.createColorMap(); ColorMapEntry start = sf.createColorMapEntry(); start.setColor(ff.literal("#ff0000")); start.setQuantity(ff.literal(min)); ColorMapEntry end = sf.createColorMapEntry(); end.setColor(ff.literal("#0000ff")); end.setQuantity(ff.literal(max)); cMap.addColorMapEntry(start); cMap.addColorMapEntry(end); sym.setColorMap(cMap); Style style = SLD.wrapSymbolizers(sym); return style; }
Example #2
Source File: StyleGenerator.java From constellation with Apache License 2.0 | 6 votes |
private static Rule makeFillRule() { final FilterFactory filterFactory = CommonFactoryFinder.getFilterFactory(); final StyleFactory styleFactory = CommonFactoryFinder.getStyleFactory(); // create a partially opaque outline stroke final Stroke stroke = styleFactory.createStroke( filterFactory.literal(Color.BLACK), filterFactory.literal(1), filterFactory.literal(.5) ); // create a partially opaque fill Fill fill = styleFactory.createFill( filterFactory.literal(COLORS.next()), filterFactory.literal(.5) ); // setting the geometryPropertyName arg to null signals that we want to draw the default geometry of features final PolygonSymbolizer sym = styleFactory.createPolygonSymbolizer(stroke, fill, null); final Rule rule = styleFactory.createRule(); rule.symbolizers().add(sym); return rule; }
Example #3
Source File: SLDUtils.java From sldeditor with GNU General Public License v3.0 | 6 votes |
/** * Creates a StyledLayerDescriptor object containing a SLD by reading the contents of a file. * * @param file the file * @return the styled layer descriptor */ public static StyledLayerDescriptor readSLDFile(File file) { StyledLayerDescriptor sld = null; if (file != null) { StyleFactory styleFactory = CommonFactoryFinder.getStyleFactory(); try { // By using URL here allows external graphics to loaded properly URL url = file.toURI().toURL(); SLDParser styleReader = new SLDParser(styleFactory, url); setResourcelocator(styleReader, file.toURI().toURL()); sld = styleReader.parseSLD(); } catch (IOException e) { ConsoleManager.getInstance().exception(SLDUtils.class, e); } } return sld; }
Example #4
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 #5
Source File: DistributedRenderCallback.java From geowave with Apache License 2.0 | 6 votes |
private static FeatureTypeStyle getDirectRasterStyle( final String geometryPropertyName, final Expression transformation) { final StyleFactory styleFactory = CommonFactoryFinder.getStyleFactory(); final FeatureTypeStyle style = styleFactory.createFeatureTypeStyle(); final Rule rule = styleFactory.createRule(); rule.setName("distributed render - direct raster"); rule.setTitle("Distributed Render - Direct Raster"); final RasterSymbolizer symbolizer = styleFactory.createRasterSymbolizer(); symbolizer.setGeometryPropertyName(geometryPropertyName); rule.symbolizers().add(symbolizer); style.rules().add(rule); style.setTransformation(transformation); return style; }
Example #6
Source File: StyleGenerator.java From constellation with Apache License 2.0 | 5 votes |
private static Style createPolygonStyle() { final StyleFactory styleFactory = CommonFactoryFinder.getStyleFactory(); final FilterFactory filterFactory = CommonFactoryFinder.getFilterFactory(); // create a partially opaque outline stroke final Stroke stroke = styleFactory.createStroke( filterFactory.literal(Color.BLACK), filterFactory.literal(1), filterFactory.literal(.5) ); // create a partially opaque fill final Fill fill = styleFactory.createFill( filterFactory.literal(COLORS.next()), filterFactory.literal(.5) ); // setting the geometryPropertyName arg to null signals that we want to draw the default geometry of features final PolygonSymbolizer sym = styleFactory.createPolygonSymbolizer(stroke, fill, null); // make rule final Rule rule = styleFactory.createRule(); rule.symbolizers().add(sym); final FeatureTypeStyle fts = styleFactory.createFeatureTypeStyle(new Rule[]{rule}); final Style style = styleFactory.createStyle(); style.getDescription().setTitle("Polygon Style"); style.featureTypeStyles().add(fts); return style; }
Example #7
Source File: StyleGenerator.java From constellation with Apache License 2.0 | 5 votes |
private static Style createPolygonStyle(final SimpleFeatureCollection features) { // get name based rule names final List<Rule> ruleList = new ArrayList<>(); final Set<String> nameSet = new HashSet<>(); // setup custom rules for polygons final SimpleFeatureIterator featureIterator = features.features(); while (featureIterator.hasNext()) { final SimpleFeature feature = featureIterator.next(); if (nameSet.add((String) feature.getAttribute(ATTRIBUTE))) { ruleList.add(makeFillRule(feature)); } } // create a partially opaque outline stroke final Rule defaultRule = makeFillRule(); defaultRule.setElseFilter(true); defaultRule.setName("Default Rule"); ruleList.add(defaultRule); // Create rule defined style final Rule[] rules = ruleList.toArray(new Rule[ruleList.size()]); final StyleFactory styleFactory = CommonFactoryFinder.getStyleFactory(); final FeatureTypeStyle featureTypeStyle = styleFactory.createFeatureTypeStyle(rules); final StyleBuilder builder = new StyleBuilder(); final Style style = builder.createStyle(); style.getDescription().setTitle("Polygon Style"); style.featureTypeStyles().add(featureTypeStyle); return style; }
Example #8
Source File: StyleGenerator.java From constellation with Apache License 2.0 | 5 votes |
private static Style createLineStyle() { final StyleFactory styleFactory = CommonFactoryFinder.getStyleFactory(); final FilterFactory filterFactory = CommonFactoryFinder.getFilterFactory(); // create a partially opaque outline stroke final Stroke stroke = styleFactory.createStroke( filterFactory.literal(Color.WHITE), filterFactory.literal(1), filterFactory.literal(.5) ); // create a partially opaque fill final Fill fill = styleFactory.createFill( filterFactory.literal(Color.RED), filterFactory.literal(.25) ); // setting the geometryPropertyName arg to null signals that we want to draw the default geometry of features final PolygonSymbolizer sym = styleFactory.createPolygonSymbolizer(stroke, fill, null); // make rule final Rule rule = styleFactory.createRule(); rule.symbolizers().add(sym); final FeatureTypeStyle fts = styleFactory.createFeatureTypeStyle(new Rule[]{rule}); final Style style = styleFactory.createStyle(); style.getDescription().setTitle("Line Style"); style.featureTypeStyles().add(fts); return style; }
Example #9
Source File: StyleGenerator.java From constellation with Apache License 2.0 | 5 votes |
private static Style createPointStyle() { final StyleFactory styleFactory = CommonFactoryFinder.getStyleFactory(); org.opengis.filter.FilterFactory filterFactory = CommonFactoryFinder.getFilterFactory(); final Mark mark = styleFactory.getCircleMark(); mark.setStroke(styleFactory.createStroke(filterFactory.literal(Color.BLUE), filterFactory.literal(1))); mark.setFill(styleFactory.createFill(filterFactory.literal(Color.CYAN))); final Graphic gr = styleFactory.getDefaultGraphic(); gr.graphicalSymbols().clear(); gr.graphicalSymbols().add(mark); gr.setSize(filterFactory.literal(5)); // setting the geometryPropertyName arg to null signals that we want to draw the default geometry of features final PointSymbolizer sym = styleFactory.createPointSymbolizer(gr, null); // make rule final Rule rule = styleFactory.createRule(); rule.symbolizers().add(sym); final FeatureTypeStyle fts = styleFactory.createFeatureTypeStyle(new Rule[]{rule}); final Style style = styleFactory.createStyle(); style.getDescription().setTitle("Point Style"); style.featureTypeStyles().add(fts); return style; }
Example #10
Source File: SLDUtils.java From sldeditor with GNU General Public License v3.0 | 5 votes |
/** * Creates a StyledLayerDescriptor object containing a SLD from a string. * * @param sldData the sld data * @return the styled layer descriptor */ public static StyledLayerDescriptor createSLDFromString(SLDDataInterface sldData) { if ((sldData == null) || (sldData.getSld() == null)) { return null; } StyleFactory styleFactory = CommonFactoryFinder.getStyleFactory(); Charset fileEncoding = PrefManager.getInstance().getPrefData().getFileEncoding(); InputStream stream = new ByteArrayInputStream(sldData.getSld().getBytes(fileEncoding)); SLDParser styleReader = new SLDParser(styleFactory, stream); URL resourceLocator = getResourceLocator(sldData); sldData.setResourceLocator(resourceLocator); setResourcelocator(styleReader, resourceLocator); StyledLayerDescriptor sld = null; try { sld = styleReader.parseSLD(); } catch (RuntimeException e) { String errorMessage = String.format("SLD Parser error : %s", sldData.getStyle().toString()); ConsoleManager.getInstance().error(SLDUtils.class, errorMessage); ConsoleManager.getInstance().error(SLDUtils.class, e.getMessage()); } return sld; }
Example #11
Source File: SLDExternalImagesTest.java From sldeditor with GNU General Public License v3.0 | 5 votes |
/** * Creates the graphic. * * @param url the url * @param styleFactory the style factory * @return the graphic */ private Graphic createGraphic(URL url, StyleFactory styleFactory) { List<GraphicalSymbol> symbolList = new ArrayList<GraphicalSymbol>(); ExternalGraphic externalGraphic = styleFactory.createExternalGraphic(url, "image/png"); symbolList.add(externalGraphic); Graphic graphicFill = styleFactory.graphicFill(symbolList, null, null, null, null, null); return graphicFill; }
Example #12
Source File: FieldConfigMarkerTest.java From sldeditor with GNU General Public License v3.0 | 4 votes |
/** * Test method for {@link * com.sldeditor.ui.detail.config.symboltype.FieldConfigMarker#accept(org.opengis.style.GraphicalSymbol)}. */ @Test public void testAccept() { boolean valueOnly = true; FieldConfigMarker field = new FieldConfigMarker( new FieldConfigCommonData( String.class, FieldIdEnum.NAME, "test label", valueOnly, false), null, null, null); assertFalse(field.accept(null)); StyleBuilder styleBuilder = new StyleBuilder(); ExternalGraphicImpl externalGraphic = (ExternalGraphicImpl) styleBuilder.createExternalGraphic("test.tmp", "png"); assertFalse(field.accept(externalGraphic)); Mark marker = styleBuilder.createMark("triangle"); assertFalse(field.accept(marker)); List<ValueComboBoxData> dataList = new ArrayList<ValueComboBoxData>(); dataList.add(new ValueComboBoxData("star", "Star", this.getClass())); dataList.add(new ValueComboBoxData("square", "Square", this.getClass())); dataList.add(new ValueComboBoxData("triangle", "Triangle", this.getClass())); List<ValueComboBoxDataGroup> groupList = new ArrayList<ValueComboBoxDataGroup>(); groupList.add(new ValueComboBoxDataGroup(dataList)); field.populateSymbolList(String.class, groupList); field.populateSymbolList(PointFillDetails.class, groupList); assertTrue(field.accept(marker)); field.populateSymbolList(PointFillDetails.class, groupList); assertTrue(field.accept(marker)); // Try some invalid values StyleFactory sf = CommonFactoryFinder.getStyleFactory(); FilterFactory ff = CommonFactoryFinder.getFilterFactory(); marker = sf.createMark(); marker.setWellKnownName(ff.property("testproperty")); assertFalse(field.accept(marker)); marker = sf.createMark(); marker.setWellKnownName(ff.literal(12)); assertFalse(field.accept(marker)); }
Example #13
Source File: OmsCoverageViewer.java From hortonmachine with GNU General Public License v3.0 | 4 votes |
@Execute public void viewCoverage() throws Exception { StyleFactory sf = CommonFactoryFinder.getStyleFactory(null); // RasterSymbolizer sym = sf.getDefaultRasterSymbolizer(); // Style rasterStyle = SLD.wrapSymbolizers(sym); StyleBuilder sB = new StyleBuilder(sf); RasterSymbolizer rasterSym = sf.createRasterSymbolizer(); ColorMap colorMap = sf.createColorMap(); RenderedImage renderedImage = raster.getRenderedImage(); double max = Double.NEGATIVE_INFINITY; double min = Double.POSITIVE_INFINITY; RectIter iter = RectIterFactory.create(renderedImage, null); do { do { double value = iter.getSampleDouble(); if (value > max) { max = value; } if (value < min) { min = value; } } while( !iter.nextPixelDone() ); iter.startPixels(); } while( !iter.nextLineDone() ); // red to blue Color fromColor = Color.blue; Color toColor = Color.red; Expression fromColorExpr = sB .colorExpression(new java.awt.Color(fromColor.getRed(), fromColor.getGreen(), fromColor.getBlue(), 255)); Expression toColorExpr = sB .colorExpression(new java.awt.Color(toColor.getRed(), toColor.getGreen(), toColor.getBlue(), 255)); Expression fromExpr = sB.literalExpression(min); Expression toExpr = sB.literalExpression(max); ColorMapEntry entry = sf.createColorMapEntry(); entry.setQuantity(fromExpr); entry.setColor(fromColorExpr); colorMap.addColorMapEntry(entry); entry = sf.createColorMapEntry(); entry.setQuantity(toExpr); entry.setColor(toColorExpr); colorMap.addColorMapEntry(entry); rasterSym.setColorMap(colorMap); Style rasterStyle = SLD.wrapSymbolizers(rasterSym); // Set up a MapContext with the two layers final MapContent map = new MapContent(); map.setTitle("Coverage Viewer"); map.addLayer(new GridCoverageLayer(raster, rasterStyle)); // Create a JMapFrame with a menu to choose the display style for the final JMapFrame frame = new JMapFrame(map); frame.setSize(800, 600); frame.enableStatusBar(true); frame.enableTool(JMapFrame.Tool.ZOOM, JMapFrame.Tool.PAN, JMapFrame.Tool.RESET); frame.enableToolBar(true); frame.setVisible(true); frame.addWindowListener(new WindowAdapter(){ public void windowClosing( WindowEvent e ) { frame.setVisible(false); } }); while( frame.isVisible() ) { Thread.sleep(300); } }
Example #14
Source File: SLDExternalImagesTest.java From sldeditor with GNU General Public License v3.0 | 3 votes |
/** * Creates the test line. * * @param url the url * @return the styled layer descriptor */ private StyledLayerDescriptor createTestLine(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); LineSymbolizer line = styleFactory.createLineSymbolizer(); rule.symbolizers().add(line); Graphic graphicFill = createGraphic(url, styleFactory); Graphic graphicStroke = createGraphic(url, styleFactory); Stroke stroke = styleFactory.createStroke( null, null, null, null, null, null, null, graphicFill, graphicStroke); line.setStroke(stroke); return sld; }
Example #15
Source File: SLDExternalImagesTest.java From sldeditor with GNU General Public License v3.0 | 3 votes |
/** * Creates the test point. * * @param url the url * @return the styled layer descriptor */ private StyledLayerDescriptor createTestPoint(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); PointSymbolizer point = styleFactory.createPointSymbolizer(); rule.symbolizers().add(point); Graphic graphic = createGraphic(url, styleFactory); point.setGraphic(graphic); return sld; }
Example #16
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; }