--- trunk/src/skrueger/RasterLegendData.java 2009/07/29 09:33:33 244 +++ branches/1.0-gt2-2.6/src/skrueger/RasterLegendData.java 2009/11/09 15:05:41 514 @@ -2,7 +2,7 @@ * Copyright (c) 2009 Martin O. J. Schmitz. * * This file is part of the SCHMITZM library - a collection of utility - * classes based on Java 1.6, focussing (not only) on Java Swing + * classes based on Java 1.6, focusing (not only) on Java Swing * and the Geotools library. * * The SCHMITZM project is hosted at: @@ -32,9 +32,16 @@ import java.util.HashMap; import java.util.LinkedList; import java.util.List; +import java.util.Map; import org.apache.log4j.Logger; - +import org.geotools.coverage.grid.GridCoverage2D; +import org.geotools.geometry.Envelope2D; +import org.geotools.renderer.lite.gridcoverage2d.GridCoverageRenderer; + +import schmitzm.geotools.GTUtil; +import schmitzm.geotools.grid.GridUtil; +import skrueger.geotools.Copyable; import skrueger.i8n.Translation; /** @@ -43,6 +50,7 @@ * * @author Stefan Alfons Krüger * + * TODO implements {@link Copyable} */ public class RasterLegendData extends HashMap { static private final Logger LOGGER = Logger.getLogger(RasterLegendData.class); @@ -61,7 +69,6 @@ * indicating nominal values in the raster (e.g. classifications) */ public RasterLegendData(boolean paintGaps) { - super(); this.paintGaps = paintGaps; } @@ -82,4 +89,25 @@ return linkedList; } + + /** + * Creates a sample {@link GridCoverage2D} (size 1x1, WGS84) for each + * legend value. These rasters can be used to do visualize the + * legend item in the corresponding color via {@link GridCoverageRenderer}. + */ + public Map createSampleRasters() { + Map sampleRaster = new HashMap(); + + for (Double rasterValue : keySet()) { + GridCoverage2D grid = GridUtil.GRID_FAC.create( + "Legend_"+rasterValue, + new float[][] { { rasterValue.floatValue() } }, + new Envelope2D(GTUtil.WGS84, 0,0,1,1) + ); + sampleRaster.put(rasterValue, grid); + } + + + return sampleRaster; + } }