Search in sources :

Example 6 with ColorMapImpl

use of org.geotools.styling.ColorMapImpl in project sldeditor by robward-scisys.

the class RasterReader method createRGBImageSymbol.

/**
 * 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<Double>();
    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) {
                e.printStackTrace();
            }
        }
    }
    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);
}
Also used : ColorMapImpl(org.geotools.styling.ColorMapImpl) ColorMapEntryImpl(org.geotools.styling.ColorMapEntryImpl) GridEnvelope2D(org.geotools.coverage.grid.GridEnvelope2D) Literal(org.opengis.filter.expression.Literal) ArrayList(java.util.ArrayList) ColorMapEntry(org.geotools.styling.ColorMapEntry) IOException(java.io.IOException)

Example 7 with ColorMapImpl

use of org.geotools.styling.ColorMapImpl in project sldeditor by robward-scisys.

the class ColourMapModel method getColourMap.

/**
 * Gets the colour map.
 *
 * @return the colour map
 */
public ColorMap getColourMap() {
    ColorMap colourMap = new ColorMapImpl();
    for (ColourMapData data : colourMapList) {
        ColorMapEntry entry = createColourMapEntry(data);
        colourMap.addColorMapEntry(entry);
    }
    return colourMap;
}
Also used : ColorMapImpl(org.geotools.styling.ColorMapImpl) ColorMap(org.geotools.styling.ColorMap) ColorMapEntry(org.geotools.styling.ColorMapEntry)

Aggregations

ColorMapImpl (org.geotools.styling.ColorMapImpl)7 ColorMap (org.geotools.styling.ColorMap)6 ColorMapEntryImpl (org.geotools.styling.ColorMapEntryImpl)6 Test (org.junit.Test)5 FieldConfigCommonData (com.sldeditor.ui.detail.config.FieldConfigCommonData)4 FieldConfigColourMap (com.sldeditor.ui.detail.config.colourmap.FieldConfigColourMap)4 Geometry (com.vividsolutions.jts.geom.Geometry)4 FilterFactory (org.opengis.filter.FilterFactory)4 ColorMapEntry (org.geotools.styling.ColorMapEntry)3 ArrayList (java.util.ArrayList)2 UndoEvent (com.sldeditor.common.undo.UndoEvent)1 FieldIdEnum (com.sldeditor.common.xml.ui.FieldIdEnum)1 XMLColourMapEntry (com.sldeditor.common.xml.ui.XMLColourMapEntry)1 GraphicPanelFieldManager (com.sldeditor.ui.detail.GraphicPanelFieldManager)1 FieldConfigPopulation (com.sldeditor.ui.detail.config.FieldConfigPopulation)1 IOException (java.io.IOException)1 GridEnvelope2D (org.geotools.coverage.grid.GridEnvelope2D)1 StyleBuilder (org.geotools.styling.StyleBuilder)1 Literal (org.opengis.filter.expression.Literal)1