/[schmitzm]/trunk/src/skrueger/RasterLegendData.java
ViewVC logotype

Diff of /trunk/src/skrueger/RasterLegendData.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

branches/1.0-gt2-2.6/src/skrueger/RasterLegendData.java revision 398 by mojays, Mon Sep 14 11:42:49 2009 UTC trunk/src/skrueger/RasterLegendData.java revision 685 by alfonx, Wed Feb 10 15:04:02 2010 UTC
# Line 28  Line 28 
28   *     Stefan A. Krüger - additional utility classes   *     Stefan A. Krüger - additional utility classes
29   ******************************************************************************/   ******************************************************************************/
30  package skrueger;  package skrueger;
31    
32  import java.util.Arrays;  import java.util.Arrays;
33  import java.util.HashMap;  import java.util.HashMap;
34  import java.util.LinkedList;  import java.util.LinkedList;
35  import java.util.List;  import java.util.List;
36  import java.util.Map;  import java.util.Map;
 import java.util.SortedMap;  
37  import java.util.TreeMap;  import java.util.TreeMap;
38    
39  import org.apache.log4j.Logger;  import org.apache.log4j.Logger;
# Line 43  import org.geotools.renderer.lite.gridco Line 43  import org.geotools.renderer.lite.gridco
43    
44  import schmitzm.geotools.GTUtil;  import schmitzm.geotools.GTUtil;
45  import schmitzm.geotools.grid.GridUtil;  import schmitzm.geotools.grid.GridUtil;
46    import skrueger.geotools.Copyable;
47  import skrueger.i8n.Translation;  import skrueger.i8n.Translation;
48    
49  /**  /**
50   * Holds all the additional information needed to paint a Legend for a RasterLayer.   * Holds all the additional information needed to paint a Legend for a
51   * So far, only Legends for one-band raster layers are supported.   * RasterLayer. So far, only Legends for one-band raster layers are supported.
52   *   *
53   * @author <a href="mailto:[email protected]">Stefan Alfons Kr&uuml;ger</a>   * @author <a href="mailto:[email protected]">Stefan Alfons Kr&uuml;ger</a>
54   *   *
55     *         TODO implements {@link Copyable}
56   */   */
57  public class RasterLegendData extends TreeMap<Double, Translation> {  public class RasterLegendData extends TreeMap<Double, Translation> implements
58          static private final Logger LOGGER = Logger.getLogger(RasterLegendData.class);                  Copyable<RasterLegendData> {
59            static private final Logger LOGGER = Logger
60                            .getLogger(RasterLegendData.class);
61    
62          private Boolean paintGaps = false;          private Boolean paintGaps = false;
63    
64            /**
65             * Shall bigger gaps be painted between the raster images
66             */
67          public Boolean isPaintGaps() {          public Boolean isPaintGaps() {
68                  return paintGaps;                  return paintGaps;
69          }          }
# Line 65  public class RasterLegendData extends Tr Line 73  public class RasterLegendData extends Tr
73          }          }
74    
75          /**          /**
76           * {@link #paintGaps} defines, if gaps should be painted between the legends colors,           * {@link #paintGaps} defines, if gaps should be painted between the legends
77           * indicating nominal values in the raster (e.g. classifications)           * colors, indicating nominal values in the raster (e.g. classifications)
78           */           */
79          public RasterLegendData(boolean paintGaps) {          public RasterLegendData(boolean paintGaps) {
80                  this.paintGaps = paintGaps;                  this.paintGaps = paintGaps;
81          }          }
82    
83          public boolean getPaintGaps() {          /**
84                  return paintGaps ;           * Returns a new list containing all {@link Double} values that shall apear
85             * in the legend.
86             */
87            public List<Double> getSortedKeys() {
88                    Double[] array = keySet().toArray(new Double[] {});
89    
90                    Arrays.sort(array);
91    
92                    final LinkedList<Double> linkedList = new LinkedList<Double>();
93                    for (Double o : array) {
94                            linkedList.add(o);
95                    }
96    
97                    return linkedList;
98            }
99    
100            /**
101             * Creates a sample {@link GridCoverage2D} (size 1x1, WGS84) for each legend
102             * value. These rasters can be used to do visualize the legend item in the
103             * corresponding color via {@link GridCoverageRenderer}.
104             */
105            public Map<Double, GridCoverage2D> createSampleRasters() {
106                    Map<Double, GridCoverage2D> sampleRaster = new HashMap<Double, GridCoverage2D>();
107    
108                    for (Double rasterValue : keySet()) {
109                            GridCoverage2D grid = GridUtil.GRID_FAC.create("Legend_"
110                                            + rasterValue,
111                                            new float[][] { { rasterValue.floatValue() } },
112                                            new Envelope2D(GTUtil.WGS84, 0, 0, 1, 1));
113                            sampleRaster.put(rasterValue, grid);
114                    }
115                    return sampleRaster;
116          }          }
117    
118  //      public List<Double> getSortedKeys(){          /**
119  //              Object[] array = keySet().toArray();           * Creates a new {@link RasterLegendData} object with identical values
120  //           */
121  //              Arrays.sort(array);          @Override
122  //          public RasterLegendData copy() {
123  //              final LinkedList<Double> linkedList = new LinkedList<Double>();                  RasterLegendData copy = (RasterLegendData) super.clone();
124  //              for (Object o : array){                  return copyTo(copy);
125  //                      linkedList.add( (Double)o);          }
126  //              }  
127  //          /**
128  //              return linkedList;           * Deep-copies all values of this {@link RasterLegendData} to another
129  //           * {@link RasterLegendData}
130  //      }           */
131            @Override
132      /**          public RasterLegendData copyTo(RasterLegendData target) {
133       * Creates a sample {@link GridCoverage2D} (size 1x1, WGS84) for each                  target.clear();
134       * legend value.  These rasters can be used to do visualize the                  
135       * legend item in the corresponding color via {@link GridCoverageRenderer}.                  target.setPaintGaps(isPaintGaps());
136       */  
137      public SortedMap<Double, GridCoverage2D> createSampleRasters() {                  for (Double o : keySet()) {
138        SortedMap<Double, GridCoverage2D> sampleRaster = new TreeMap<Double, GridCoverage2D>();                          target.put(new Double(o), get(o).copy());
139                          }
140        for (Double rasterValue : keySet()) {  
141          GridCoverage2D grid = GridUtil.GRID_FAC.create(                  return target;
142              "Legend_"+rasterValue,          }
             new float[][] { { rasterValue.floatValue() } },  
             new Envelope2D(GTUtil.WGS84, 0,0,1,1)  
         );  
         sampleRaster.put(rasterValue, grid);  
       }  
         
         
       return sampleRaster;  
     }  
143  }  }

Legend:
Removed from v.398  
changed lines
  Added in v.685

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26