Search in sources :

Example 1 with GridEnvelope2D

use of org.geotools.coverage.grid.GridEnvelope2D 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 2 with GridEnvelope2D

use of org.geotools.coverage.grid.GridEnvelope2D in project OpenTripPlanner by opentripplanner.

the class SyntheticRasterPopulation method createIndividuals.

@Override
public void createIndividuals() {
    try {
        coverageCRS = CRS.decode(crsCode, true);
    } catch (Exception e) {
        LOG.error("error decoding coordinate reference system code.", e);
        return;
    }
    if (boundsFromGraph) {
    // autowire graph service or pass in
    }
    gridEnvelope = new GridEnvelope2D(0, 0, cols, rows);
    refEnvelope = new ReferencedEnvelope(left, right, bottom, top, coverageCRS);
    gridGeometry = new GridGeometry2D(gridEnvelope, refEnvelope);
    super.createIndividuals0();
}
Also used : ReferencedEnvelope(org.geotools.geometry.jts.ReferencedEnvelope) GridGeometry2D(org.geotools.coverage.grid.GridGeometry2D) GridEnvelope2D(org.geotools.coverage.grid.GridEnvelope2D)

Aggregations

GridEnvelope2D (org.geotools.coverage.grid.GridEnvelope2D)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 GridGeometry2D (org.geotools.coverage.grid.GridGeometry2D)1 ReferencedEnvelope (org.geotools.geometry.jts.ReferencedEnvelope)1 ColorMapEntry (org.geotools.styling.ColorMapEntry)1 ColorMapEntryImpl (org.geotools.styling.ColorMapEntryImpl)1 ColorMapImpl (org.geotools.styling.ColorMapImpl)1 Literal (org.opengis.filter.expression.Literal)1