Java Code Examples for org.geotools.styling.RasterSymbolizer#setColorMap()
The following examples show how to use
org.geotools.styling.RasterSymbolizer#setColorMap() .
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: RuleRenderVisitor.java From sldeditor with GNU General Public License v3.0 | 6 votes |
public void visit(RasterSymbolizer raster) { // CHECKSTYLE:ON RasterSymbolizer copy = sf.createRasterSymbolizer(); copy.setChannelSelection(copy(raster.getChannelSelection())); copy.setColorMap(copy(raster.getColorMap())); copy.setContrastEnhancement(copy(raster.getContrastEnhancement())); copy.setGeometry(copy(raster.getGeometry())); copy.setUnitOfMeasure(raster.getUnitOfMeasure()); copy.setImageOutline(copy(raster.getImageOutline())); copy.setOpacity(copy(raster.getOpacity())); copy.setOverlap(copy(raster.getOverlap())); copy.setShadedRelief(copy(raster.getShadedRelief())); if (STRICT && !copy.equals(raster)) { throw new IllegalStateException("Was unable to duplicate provided raster:" + raster); } pages.push(copy); }
Example 3
Source File: RasterReader.java From sldeditor with GNU General Public License v3.0 | 5 votes |
/** * Creates the rgb image symbol. * * @param sym the sym * @param cov the cov * @param raster the raster */ private void createRGBImageSymbol( RasterSymbolizer sym, GridCoverage2D cov, WritableRaster raster) { double dest; List<Double> valueList = new ArrayList<>(); GridEnvelope2D gridRange2D = cov.getGridGeometry().getGridRange2D(); for (int x = 0; x < gridRange2D.getWidth(); x++) { for (int y = 0; y < gridRange2D.getHeight(); y++) { try { dest = raster.getSampleDouble(x, y, 0); if (!valueList.contains(dest)) { valueList.add(dest); } } catch (Exception e) { ConsoleManager.getInstance().exception(this, e); } } } ColorMapImpl colourMap = new ColorMapImpl(); // Sort the unique sample values in ascending order Collections.sort(valueList); // Create colour amp entries in the colour map for all the sample values for (Double value : valueList) { ColorMapEntry entry = new ColorMapEntryImpl(); Literal colourExpression = ff.literal(ColourUtils.fromColour(ColourUtils.createRandomColour())); entry.setColor(colourExpression); entry.setQuantity(ff.literal(value.doubleValue())); colourMap.addColorMapEntry(entry); } colourMap.setType(ColorMap.TYPE_VALUES); sym.setColorMap(colourMap); }
Example 4
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 5
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); } }