Java Code Examples for org.geotools.styling.SLD#wrapSymbolizers()
The following examples show how to use
org.geotools.styling.SLD#wrapSymbolizers() .
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: RasterReader.java From sldeditor with GNU General Public License v3.0 | 6 votes |
/** * Creates the rgb style. * * @param reader the reader * @param raster the raster * @return the style */ private Style createRGBStyle(AbstractGridCoverage2DReader reader, WritableRaster raster) { RasterSymbolizer sym = sf.getDefaultRasterSymbolizer(); GridCoverage2D cov = null; try { cov = reader.read(null); } catch (IOException giveUp) { throw new RuntimeException(giveUp); } // We need at least three bands to create an RGB style int numBands = cov.getNumSampleDimensions(); if (numBands < 3) { createRGBImageSymbol(sym, cov, raster); } else { createRGBChannelSymbol(sym, cov, numBands); } return SLD.wrapSymbolizers(sym); }
Example 3
Source File: GridCoverageNwwLayer.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
private static GTRenderer getRenderer( File rasterFile ) { AbstractGridFormat format = GridFormatFinder.findFormat(rasterFile); AbstractGridCoverage2DReader coverageReader = format.getReader(rasterFile); MapContent mapContent = new MapContent(); try { Style rasterStyle = SldUtilities.getStyleFromFile(rasterFile); if (rasterStyle == null) { RasterSymbolizer sym = SldUtilities.sf.getDefaultRasterSymbolizer(); rasterStyle = SLD.wrapSymbolizers(sym); } GridReaderLayer layer = new GridReaderLayer(coverageReader, rasterStyle); mapContent.addLayer(layer); mapContent.getViewport().setCoordinateReferenceSystem(CrsUtilities.WGS84); } catch (Exception e) { e.printStackTrace(); } GTRenderer renderer = new StreamingRenderer(); renderer.setMapContent(mapContent); return renderer; }
Example 4
Source File: SldUtilities.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
public static Style getStyleFromRasterFile( File file ) throws Exception { String coveragePath = file.getAbsolutePath(); if (CoverageUtilities.isGrass(coveragePath)) { return getGrassStyle(coveragePath); } else { RasterSymbolizer sym = sf.getDefaultRasterSymbolizer(); return SLD.wrapSymbolizers(sym); } }
Example 5
Source File: RasterStyleUtilities.java From hortonmachine with GNU General Public License v3.0 | 4 votes |
public static Style createDefaultRasterStyle() { RasterSymbolizer rasterSym = sf.createRasterSymbolizer(); Style newStyle = SLD.wrapSymbolizers(rasterSym); return newStyle; }
Example 6
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 7
Source File: OmsMapsViewer.java From hortonmachine with GNU General Public License v3.0 | 4 votes |
private void addImageMosaic( MapContent map ) throws Exception { if (inImageMosaics != null) { RasterSymbolizer sym = sf.getDefaultRasterSymbolizer(); Style style = SLD.wrapSymbolizers(sym); final ParameterValue<Color> inTransp = AbstractGridFormat.INPUT_TRANSPARENT_COLOR.createValue(); inTransp.setValue(Color.white); final ParameterValue<Color> outTransp = ImageMosaicFormat.OUTPUT_TRANSPARENT_COLOR.createValue(); outTransp.setValue(Color.white); final ParameterValue<Color> backColor = ImageMosaicFormat.BACKGROUND_COLOR.createValue(); backColor.setValue(Color.RED); final ParameterValue<Boolean> fading = ImageMosaicFormat.FADING.createValue(); fading.setValue(true); final ParameterValue<Interpolation> interpol = ImageMosaicFormat.INTERPOLATION.createValue(); interpol.setValue(new javax.media.jai.InterpolationBilinear()); final ParameterValue<Boolean> resol = ImageMosaicFormat.ACCURATE_RESOLUTION.createValue(); resol.setValue(true); final ParameterValue<Boolean> multiThread= ImageMosaicFormat.ALLOW_MULTITHREADING.createValue(); multiThread.setValue(true); final ParameterValue<Boolean> usejai = ImageMosaicFormat.USE_JAI_IMAGEREAD.createValue(); usejai.setValue(false); final ParameterValue<double[]> bkg = ImageMosaicFormat.BACKGROUND_VALUES.createValue(); bkg.setValue(new double[]{0}); GeneralParameterValue[] gp = new GeneralParameterValue[]{inTransp, multiThread}; for( String imageMosaicPath : inImageMosaics ) { ImageMosaicReader imr = new ImageMosaicReader(new File(imageMosaicPath)); GridReaderLayer layer = new GridReaderLayer(imr, style, gp); map.addLayer(layer); } } }
Example 8
Source File: OmsMapsViewer.java From hortonmachine with GNU General Public License v3.0 | 4 votes |
private void addCoverages( final MapContent map ) throws Exception { if (inRasters == null) { return; } RasterSymbolizer rasterSym = sf.createRasterSymbolizer(); ColorMap colorMap = sf.createColorMap(); for( String rasterPath : inRasters ) { GridCoverage2D readRaster = OmsRasterReader.readRaster(rasterPath); RenderedImage renderedImage = readRaster.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 midColor = Color.green; Color toColor = Color.red; Expression fromColorExpr = sb .colorExpression(new java.awt.Color(fromColor.getRed(), fromColor.getGreen(), fromColor.getBlue(), 255)); Expression midColorExpr = sb .colorExpression(new java.awt.Color(midColor.getRed(), midColor.getGreen(), midColor.getBlue(), 255)); Expression toColorExpr = sb .colorExpression(new java.awt.Color(toColor.getRed(), toColor.getGreen(), toColor.getBlue(), 255)); Expression fromExpr = sb.literalExpression(min); Expression midExpr = sb.literalExpression(min + (max - min) / 2); Expression toExpr = sb.literalExpression(max); ColorMapEntry entry = sf.createColorMapEntry(); entry.setQuantity(fromExpr); entry.setColor(fromColorExpr); colorMap.addColorMapEntry(entry); entry = sf.createColorMapEntry(); entry.setQuantity(midExpr); entry.setColor(midColorExpr); colorMap.addColorMapEntry(entry); entry = sf.createColorMapEntry(); entry.setQuantity(toExpr); entry.setColor(toColorExpr); colorMap.addColorMapEntry(entry); rasterSym.setColorMap(colorMap); Style rasterStyle = SLD.wrapSymbolizers(rasterSym); GridCoverageLayer layer = new GridCoverageLayer(readRaster, rasterStyle); map.addLayer(layer); } }