001    //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/branches/2.3_testing/src/org/deegree/model/coverage/SampleDimension.java $
002    /*----------------------------------------------------------------------------
003     This file is part of deegree, http://deegree.org/
004     Copyright (C) 2001-2009 by:
005       Department of Geography, University of Bonn
006     and
007       lat/lon GmbH
008    
009     This library is free software; you can redistribute it and/or modify it under
010     the terms of the GNU Lesser General Public License as published by the Free
011     Software Foundation; either version 2.1 of the License, or (at your option)
012     any later version.
013     This library is distributed in the hope that it will be useful, but WITHOUT
014     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
015     FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
016     details.
017     You should have received a copy of the GNU Lesser General Public License
018     along with this library; if not, write to the Free Software Foundation, Inc.,
019     59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020    
021     Contact information:
022    
023     lat/lon GmbH
024     Aennchenstr. 19, 53177 Bonn
025     Germany
026     http://lat-lon.de/
027    
028     Department of Geography, University of Bonn
029     Prof. Dr. Klaus Greve
030     Postfach 1147, 53001 Bonn
031     Germany
032     http://www.geographie.uni-bonn.de/deegree/
033    
034     e-mail: info@deegree.org
035    ----------------------------------------------------------------------------*/
036    package org.deegree.model.coverage;
037    
038    import java.io.Serializable;
039    import java.util.HashMap;
040    import java.util.Iterator;
041    
042    import org.deegree.datatypes.parameter.ParameterValueIm;
043    
044    /**
045     * Contains information for an individual sample dimension of coverage. This interface is applicable
046     * to any coverage type. For grid coverages, the sample dimension refers to an individual band.
047     *
048     * @author <a href="mailto:poth@lat-lon.de">Andreas Poth </a>
049     * @author last edited by: $Author: mschneider $
050     *
051     * @version $Revision: 18195 $, $Date: 2009-06-18 17:55:39 +0200 (Do, 18. Jun 2009) $
052     */
053    public class SampleDimension implements Serializable {
054    
055        private static final long serialVersionUID = 6130760380289685594L;
056    
057        private ColorInterpretation colorInterpretation = null;
058    
059        private String[] categoryNames = null;
060    
061        private String description = null;
062    
063        private double maximumValue = 0;
064    
065        private double minimumValue = 0;
066    
067        private HashMap<String, Object> metadata = null;
068    
069        private double[] noData = null;
070    
071        private int offset = -1;
072    
073        private int[][] colorPalette = null;
074    
075        private PaletteInterpretation paletteInterpretation = null;
076    
077        private SampleDimensionType sampleDimensionType = null;
078    
079        private double scale = -1;
080    
081        private String units = null;
082    
083        /**
084         * @param categoryNames
085         * @param description
086         * @param minimumValue
087         * @param maximumValue
088         * @param metadata
089         * @param noData
090         * @param offset
091         * @param colorPalette
092         * @param scale
093         * @param units
094         * @param colorInterpretation
095         * @param paletteInterpretation
096         * @param sampleDimensionType
097         */
098        public SampleDimension( String[] categoryNames, String description, double minimumValue, double maximumValue,
099                                ParameterValueIm[] metadata, double[] noData, int offset, int[][] colorPalette,
100                                double scale, String units, ColorInterpretation colorInterpretation,
101                                PaletteInterpretation paletteInterpretation, SampleDimensionType sampleDimensionType ) {
102            this.categoryNames = categoryNames;
103            this.maximumValue = maximumValue;
104            this.minimumValue = minimumValue;
105            this.scale = scale;
106            this.noData = noData;
107            this.offset = offset;
108            this.colorPalette = colorPalette;
109            this.description = description;
110            this.metadata = new HashMap<String, Object>();
111            if ( metadata != null ) {
112                for ( int i = 0; i < metadata.length; i++ ) {
113                    this.metadata.put( metadata[i].getDescriptor().getName(), metadata[i].getValue() );
114                }
115            }
116            this.units = units;
117            if ( colorInterpretation == null ) {
118                this.colorInterpretation = ColorInterpretation.UNDEFINED;
119            } else {
120                this.colorInterpretation = colorInterpretation;
121            }
122            if ( paletteInterpretation == null ) {
123                this.paletteInterpretation = PaletteInterpretation.GRAY;
124            } else {
125                this.paletteInterpretation = paletteInterpretation;
126            }
127            this.sampleDimensionType = sampleDimensionType;
128    
129        }
130    
131        /**
132         * Sequence of category names for the values contained in a sample dimension. This allows for
133         * names to be assigned to numerical values. The first entry in the sequence relates to a cell
134         * value of zero. For grid coverages, category names are only valid for a classified grid data.
135         *
136         * For example:<br>
137         * <UL>
138         * <li>0 Background</li>
139         * <li>1 Water</li>
140         * <li>2 Forest</li>
141         * <li>3 Urban</li>
142         * </UL>
143         * Note: If no category names exist, an empty sequence is returned.
144         *
145         * @return the sequence of category names for the values contained in a sample dimension.
146         *
147         */
148        public String[] getCategoryNames() {
149            return categoryNames;
150        }
151    
152        /**
153         * Color interpretation of the sample dimension. A sample dimension can be an index into a color
154         * palette or be a color model component. If the sample dimension is not assigned a color
155         * interpretation the value is {@link ColorInterpretation#UNDEFINED Undefined}.
156         *
157         * @return the color interpretation of the sample dimension.
158         *
159         */
160        public ColorInterpretation getColorInterpretation() {
161            return colorInterpretation;
162        }
163    
164        /**
165         * Sample dimension title or description. This string may be null or empty if no description is
166         * present.
167         *
168         * @return the sample dimension title or description.
169         *
170         */
171        public String getDescription() {
172            return description;
173        }
174    
175        /**
176         * The maximum value occurring in the sample dimension. If this value is not available, this
177         * value can be determined from the {@link "org.opengis"} operation. This value can be empty if
178         * this value is not provided by the implementation.
179         *
180         * @return the maximum value occurring in the sample dimension.
181         *
182         */
183        public double getMaximumValue() {
184            return maximumValue;
185        }
186    
187        /**
188         * The list of metadata keywords for a sample dimension. If no metadata is available, the
189         * sequence will be empty.
190         *
191         * @return the list of metadata keywords for a sample dimension.
192         *
193         */
194        public String[] getMetaDataNames() {
195            Iterator<String> iterator = metadata.keySet().iterator();
196            String[] names = new String[metadata.size()];
197            int i = 0;
198            while ( iterator.hasNext() ) {
199                names[i++] = iterator.next();
200            }
201            return names;
202        }
203    
204        /**
205         * Retrieve the metadata value for a given metadata name.
206         *
207         * @param name
208         *            Metadata keyword for which to retrieve metadata.
209         * @return the metadata value for a given metadata name.
210         *
211         */
212        public String getMetadataValue( String name ) {
213            return (String) metadata.get( name );
214        }
215    
216        /**
217         * The minimum value occurring in the sample dimension. This value can be empty if this value is
218         * not provided by the implementation.
219         *
220         * @return the minimum value occurring in the sample dimension.
221         *
222         */
223        public double getMinimumValue() {
224            return minimumValue;
225        }
226    
227        /**
228         * Values to indicate no data values for the sample dimension. For low precision sample
229         * dimensions, this will often be no data values.
230         *
231         * @return the values to indicate no data values for the sample dimension.
232         *
233         */
234        public double[] getNoDataValues() {
235            return noData;
236        }
237    
238        /**
239         * Offset is the value to add to grid values for this sample dimension. This attribute is
240         * typically used when the sample dimension represents elevation data. The default for this
241         * value is 0.
242         *
243         * @return the offset is the value to add to grid values for this sample dimension.
244         *
245         */
246        public double getOffset() {
247            return offset;
248        }
249    
250        /**
251         * Color palette associated with the sample dimension. A color palette can have any number of
252         * colors. See palette interpretation for meaning of the palette entries. If the grid coverage
253         * has no color palette, an empty sequence will be returned.
254         *
255         * @return the color palette associated with the sample dimension.
256         *
257         */
258        public int[][] getPalette() {
259            return colorPalette;
260        }
261    
262        /**
263         * Indicates the type of color palette entry for sample dimensions which have a palette. If a
264         * sample dimension has a palette, the color interpretation must be
265         * {@link ColorInterpretation#GRAY_INDEX GrayIndex} or
266         * {@link ColorInterpretation#PALETTE_INDEX PaletteIndex}. A palette entry type can be Gray,
267         * RGB, CMYK or HLS.
268         *
269         * @return the type of color palette entry for sample dimensions which have a palette.
270         *
271         */
272        public PaletteInterpretation getPaletteInterpretation() {
273            return paletteInterpretation;
274        }
275    
276        /**
277         * A code value indicating grid value data type. This will also indicate the number of bits for
278         * the data type.
279         *
280         * @return a code value indicating grid value data type.
281         *
282         */
283        public SampleDimensionType getSampleDimensionType() {
284            return sampleDimensionType;
285        }
286    
287        /**
288         * Scale is the value which is multiplied to grid values for this sample dimension. This
289         * attribute is typically used when the sample dimension represents elevation data. The default
290         * for this value is 1.
291         *
292         * @return the scale.
293         *
294         */
295        public double getScale() {
296            return scale;
297        }
298    
299        /**
300         * The unit information for this sample dimension. This interface typically is provided with
301         * grid coverages which represent digital elevation data. This value will be <code>null</code>
302         * if no unit information is available.
303         *
304         * @return the unit information for this sample dimension.
305         *
306         */
307        public String getUnits() {
308            return units;
309        }
310    
311    }