org.geotools.styling.SLD Java Examples

The following examples show how to use org.geotools.styling.SLD. 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 vote down vote up
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: GridCoverageNwwLayer.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
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 #3
Source File: RasterReader.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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 #4
Source File: GraphicViewer.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
private void setMark(final Mark mark, final Mode mode) {
	listen(false);
	try {
		this.enabled = mode == Mode.POINT && mark != null;
		this.type = SLD.wellKnownName(mark);

		// Stroke is used in line, point and polygon
		this.on.setEnabled(mode == Mode.POINT || mode == Mode.ALL);

		if (this.type != null) {
			this.name.setText(this.type);
			this.name.select(this.name.indexOf(this.type));
		}

		this.on.setSelection(this.enabled);
		this.size.setEnabled(this.enabled);
		this.name.setEnabled(this.enabled);
	} finally {
		listen(true); // listen to user now
	}
}
 
Example #5
Source File: StyleUtilities.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Changes the size of a mark inside a rule.
 * 
 * @param rule the {@link Rule}.
 * @param newSize the new size.
 */
public static void changeMarkSize( Rule rule, int newSize ) {
    PointSymbolizer pointSymbolizer = StyleUtilities.pointSymbolizerFromRule(rule);
    Graphic graphic = SLD.graphic(pointSymbolizer);
    graphic.setSize(ff.literal(newSize));
    // Mark oldMark = SLDs.mark(pointSymbolizer);
    // oldMark.setSize(ff.literal(newSize));
    // Graphic graphic = SLDs.graphic(pointSymbolizer);
}
 
Example #6
Source File: ShapefileLoader.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
private static Style createLineStyle() {
    LineSymbolizer symbolizer = styleFactory.createLineSymbolizer();
    SLD.setLineColour(symbolizer, Color.BLUE);
    symbolizer.getStroke().setWidth(filterFactory.literal(1));
    symbolizer.getStroke().setColor(filterFactory.literal(Color.BLUE));

    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 #7
Source File: RasterizedSpatialiteLayer.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
private static GTRenderer getRenderer( ASpatialDb db, String tableName, int featureLimit, Style style ) {
    MapContent mapContent = new MapContent();

    // read data and convert it to featurecollection
    try {
        long t1 = System.currentTimeMillis();
        System.out.println("STARTED READING: " + tableName);

        String databasePath = db.getDatabasePath();
        File dbFile = new File(databasePath);
        File parentFolder = dbFile.getParentFile();
        if (style == null) {
            File sldFile = new File(parentFolder, tableName + ".sld");
            if (sldFile.exists()) {
                style = SldUtilities.getStyleFromFile(sldFile);
            }
        }

        DefaultFeatureCollection fc = SpatialDbsImportUtils.tableToFeatureFCollection(db, tableName, featureLimit,
                NwwUtilities.GPS_CRS_SRID, null);
        long t2 = System.currentTimeMillis();
        System.out.println("FINISHED READING: " + tableName + " -> " + ((t2 - t1) / 1000) + "sec");
        if (style == null) {
            style = SLD.createSimpleStyle(fc.getSchema());
        }
        FeatureLayer layer = new FeatureLayer(fc, style);

        long t3 = System.currentTimeMillis();
        System.out.println("FINISHED BUILDING: " + tableName + " -> " + ((t3 - t2) / 1000) + "sec");

        mapContent.addLayer(layer);
    } catch (Exception e) {
        e.printStackTrace();
    }
    GTRenderer renderer = new StreamingRenderer();
    renderer.setMapContent(mapContent);
    return renderer;
}
 
Example #8
Source File: RasterizedShapefilesFolderNwwLayer.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
private static GTRenderer getRenderer(File shapeFilesFolder) {
    File[] shpFiles = shapeFilesFolder.listFiles(new FilenameFilter() {
        @Override
        public boolean accept(File dir, String name) {
            return name.toLowerCase().endsWith(".shp");
        }
    });

    MapContent mapContent = new MapContent();
    for (File shpFile : shpFiles) {
        try {
            SimpleFeatureCollection readFC = NwwUtilities.readAndReproject(shpFile.getAbsolutePath());
            ReferencedEnvelope tmpBounds = readFC.getBounds();
            if (tmpBounds.getWidth() == 0 || tmpBounds.getHeight() == 0) {
                System.err.println("Ignoring: " + shpFile);
                continue;
            }
            // if (bounds == null) {
            // bounds = new ReferencedEnvelope(tmpBounds);
            // } else {
            // bounds.expandToInclude(tmpBounds);
            // }
            Style style = SldUtilities.getStyleFromFile(shpFile);
            if (style == null)
                style = SLD.createSimpleStyle(readFC.getSchema());

            FeatureLayer layer = new FeatureLayer(readFC, style);
            mapContent.addLayer(layer);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    GTRenderer renderer = new StreamingRenderer();
    renderer.setMapContent(mapContent);
    return renderer;
}
 
Example #9
Source File: StyleUtilities.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Changes the rotation value inside a rule.
 * 
 * @param rule the {@link Rule}.
 * @param newRotation the new rotation value in degrees.
 */
public static void changeRotation( Rule rule, int newRotation ) {
    PointSymbolizer pointSymbolizer = StyleUtilities.pointSymbolizerFromRule(rule);
    Graphic graphic = SLD.graphic(pointSymbolizer);
    graphic.setRotation(ff.literal(newRotation));
    // Mark oldMark = SLDs.mark(pointSymbolizer);
    // oldMark.setSize(ff.literal(newRotation));
}
 
Example #10
Source File: SldUtilities.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
public static Style getDefaultStyle( StyledLayerDescriptor sld ) {
    Style[] styles = SLD.styles(sld);
    for( int i = 0; i < styles.length; i++ ) {
        Style style = styles[i];
        List<FeatureTypeStyle> ftStyles = style.featureTypeStyles();
        genericizeftStyles(ftStyles);
        if (style.isDefault()) {
            return style;
        }
    }
    // no default, so just grab the first one
    return styles[0];
}
 
Example #11
Source File: SldUtilities.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
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 #12
Source File: StrokeViewer.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
/**
 * TODO summary sentence for setStroke ...
 *
 * @param line
 * @param mode
 * @param defaultColor
 */
public void setStroke(final Stroke aLine, final Mode mode, final Color defaultColor) {
	listen(false);
	try {
		boolean enabled = true;
		Stroke line = aLine;

		if (line == null) {
			final StyleBuilder builder = new StyleBuilder();
			line = builder.createStroke(defaultColor);
			enabled = false;
		}
		this.enabled = enabled && mode != Mode.NONE && line != null;
		this.color = SLD.color(line);
		this.width = SLD.width(line);
		this.opacity = SLD.opacity(line);

		// Stroke is used in line, point and polygon
		this.on.setEnabled(mode != Mode.NONE);
		this.chooser.setColor(this.color);

		String text = MessageFormat.format("{0,number,#0}", this.width); //$NON-NLS-1$
		this.size.setText(text);
		this.size.select(this.size.indexOf(text));

		text = MessageFormat.format("{0,number,#0%}", this.opacity); //$NON-NLS-1$
		this.percent.setText(text);
		this.percent.select(this.percent.indexOf(text));

		this.on.setSelection(this.enabled);
		this.chooser.setEnabled(this.enabled);
		this.size.setEnabled(this.enabled);
		this.percent.setEnabled(this.enabled);
	} finally {
		listen(true); // listen to user now
	}
}
 
Example #13
Source File: FillViewer.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
/**
 * TODO summary sentence for setFill ...
 *
 * @param fill
 * @param mode
 * @param enabled
 */
public void setFill(final Fill fill2, final Mode mode, final Color defaultColor) {
	listen(false);
	try {

		boolean enabled = true;
		Fill fill = fill2;
		if (fill == null) {
			final StyleBuilder builder = new StyleBuilder();
			fill = builder.createFill(defaultColor, 0.5);
			enabled = false;
		}

		this.enabled = enabled && mode != Mode.NONE && mode != Mode.LINE && fill != null;
		this.color = SLD.color(fill);
		this.opacity = SLD.opacity(fill);

		// Fill is used in point and polygon
		this.on.setEnabled(mode != Mode.NONE && mode != Mode.LINE);
		this.chooser.setColor(this.color);

		final String text = MessageFormat.format("{0,number,#0%}", this.opacity); //$NON-NLS-1$
		this.percent.setText(text);
		this.percent.select(this.percent.indexOf(text));

		this.on.setSelection(this.enabled);
		this.chooser.setEnabled(this.enabled);
		this.percent.setEnabled(this.enabled);
	} finally {
		listen(true);
	}
}
 
Example #14
Source File: ShapeFileViewer.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Method getColor()
 *
 * @see ummisco.gama.ui.views.toolbar.IToolbarDecoratedView.Colorizable#getColor(int)
 */
@Override
public GamaUIColor getColor(final int index) {
	Color c;
	if (index == 0) {
		c = SLD.color(getStroke(mode, fts));
	} else {
		c = SLD.color(getFill(mode, fts));
	}
	return GamaColors.get(c);

}
 
Example #15
Source File: InternalMapObject.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public Style getStyle()
{
    Style style;

    if ( geometry instanceof Point )
    {
        style = SLD.createPointStyle( CIRCLE, strokeColor, fillColor,
            fillOpacity, radius );
    }
    else if ( geometry instanceof Polygon || geometry instanceof MultiPolygon )
    {
        if ( MapLayerType.BOUNDARY.equals( mapLayerType ) )
        {
            style = SLD.createLineStyle( strokeColor, LINE_STROKE_WIDTH );
        }
        else
        {
            style = SLD.createPolygonStyle( strokeColor, fillColor, fillOpacity );
        }
    }
    else
    {
        style = SLD.createSimpleStyle( getFeatureType() );
    }

    return style;
}
 
Example #16
Source File: ColourUtils.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Converts colour string to colour.
 *
 * @param htmlColour the html colour
 * @return the colour
 */
public static Color toColour(String htmlColour) {
    Color colour = null;

    if (validColourString(htmlColour)) {
        colour = SLD.toColor(htmlColour);
    }

    return colour;
}
 
Example #17
Source File: PointSymbolizerWrapper.java    From hortonmachine with GNU General Public License v3.0 4 votes vote down vote up
public PointSymbolizerWrapper( Symbolizer symbolizer, RuleWrapper parent ) {
    super(symbolizer, parent);

    PointSymbolizer pointSymbolizer = (PointSymbolizer) symbolizer;
    graphic = pointSymbolizer.getGraphic();
    List<ExternalGraphic> externalGraphicsList = externalGraphicsFromGraphic(graphic);

    // size
    Expression sizeExpr = graphic.getSize();
    String tmp = expressionToString(sizeExpr);
    if (tmp != null) {
        size = tmp;
    } else {
        size = DEFAULT_WIDTH;
    }
    // rotation
    Expression rotationExpr = graphic.getRotation();
    tmp = expressionToString(rotationExpr);
    if (tmp != null) {
        rotation = tmp;
    } else {
        rotation = DEFAULT_ROTATION;
    }
    // offset
    Point2D offset = StyleUtilities.getOffset(pointSymbolizer);
    if (offset != null) {
        xOffset = String.valueOf(offset.getX());
        yOffset = String.valueOf(offset.getY());
    } else {
        xOffset = DEFAULT_OFFSET;
        yOffset = DEFAULT_OFFSET;
    }

    if (externalGraphicsList.size() == 0) {
        mark = SLD.mark(pointSymbolizer);
        if (mark == null) {
            return;
        }
        markName = mark.getWellKnownName().evaluate(null, String.class);
        if (markName == null || markName.equals("")) { //$NON-NLS-1$
            markName = "circle"; //$NON-NLS-1$
            mark.setWellKnownName(ff.literal(markName));
        }

        fill = mark.getFill();
        if (fill != null) {
            fillColor = fill.getColor().evaluate(null, String.class);
            Expression opacityExpr = fill.getOpacity();
            fillOpacity = expressionToString(opacityExpr);
            hasFill = true;
        } else {
            hasFill = false;
        }

        stroke = mark.getStroke();
        if (stroke != null) {
            Expression color = stroke.getColor();
            tmp = color.evaluate(null, String.class);
            if (tmp != null) {
                strokeColor = tmp;
            } else {
                strokeColor = DEFAULT_COLOR;
            }

            Expression opacity = stroke.getOpacity();
            tmp = expressionToString(opacity);
            if (tmp != null) {
                strokeOpacity = tmp;
            } else {
                strokeOpacity = DEFAULT_OPACITY;
            }

            Expression width = stroke.getWidth();
            tmp = expressionToString(width);
            if (tmp != null) {
                strokeWidth = tmp;
            } else {
                strokeWidth = DEFAULT_WIDTH;
            }
            hasStroke = true;
        } else {
            hasStroke = false;
        }
    } else {
        // graphics case
        externalGraphic = externalGraphicsList.get(0);
    }
}
 
Example #18
Source File: RasterStyleUtilities.java    From hortonmachine with GNU General Public License v3.0 4 votes vote down vote up
public static Style createDefaultRasterStyle() {
    RasterSymbolizer rasterSym = sf.createRasterSymbolizer();
    Style newStyle = SLD.wrapSymbolizers(rasterSym);
    return newStyle;
}
 
Example #19
Source File: OmsCoverageViewer.java    From hortonmachine with GNU General Public License v3.0 4 votes vote down vote up
@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 #20
Source File: OmsMapsViewer.java    From hortonmachine with GNU General Public License v3.0 4 votes vote down vote up
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 #21
Source File: OmsMapsViewer.java    From hortonmachine with GNU General Public License v3.0 4 votes vote down vote up
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);
    }
}
 
Example #22
Source File: ColourUtils.java    From sldeditor with GNU General Public License v3.0 3 votes vote down vote up
/**
 * Create a #rrggbb string From colour.
 *
 * <p>Returns null if colour is null.
 *
 * @param colour the colour
 * @return the string
 */
public static String fromColour(Color colour) {
    if (colour == null) {
        return null;
    }

    return SLD.toHTMLColor(colour);
}