/[schmitzm]/trunk/src/appl/util/RasterMetaData.java
ViewVC logotype

Diff of /trunk/src/appl/util/RasterMetaData.java

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

revision 243 by mojays, Tue Feb 24 22:43:52 2009 UTC revision 244 by alfonx, Wed Jul 29 09:33:33 2009 UTC
# Line 1  Line 1 
1  package appl.util;  /*******************************************************************************
2     * Copyright (c) 2009 Martin O. J. Schmitz.
3  import java.awt.image.DataBuffer;   *
4  import java.io.Serializable;   * This file is part of the SCHMITZM library - a collection of utility
5     * classes based on Java 1.6, focussing (not only) on Java Swing
6  import org.geotools.referencing.crs.DefaultGeographicCRS;   * and the Geotools library.
7  import org.opengis.referencing.crs.CoordinateReferenceSystem;   *
8     * The SCHMITZM project is hosted at:
9  import schmitzm.data.WritableGrid;   * http://wald.intevation.org/projects/schmitzm/
10     *
11  /**   * This program is free software; you can redistribute it and/or
12   * Simple immutable class that encapsulates raster metadata,   * modify it under the terms of the GNU Lesser General Public License
13   * especially the MetaData of a {@link WritableGrid}.   * as published by the Free Software Foundation; either version 3
14   * Just a constructor and getters   * of the License, or (at your option) any later version.
15   * on the fields.   *
16   *   * This program is distributed in the hope that it will be useful,
17   * <br>   * but WITHOUT ANY WARRANTY; without even the implied warranty of
18   * @see WritableGrid for details on the variable description   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19   *   * GNU General Public License for more details.
20   * @author Dominik Appl   *
21   */   * You should have received a copy of the GNU Lesser General Public License (license.txt)
22  public final class RasterMetaData implements Serializable {   * along with this program; if not, write to the Free Software
23     * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
24      int width = 0;   * or try this link: http://www.gnu.org/licenses/lgpl.html
25     *
26      int height = 0;   * Contributors:
27     *     Martin O. J. Schmitz - initial API and implementation
28      int minX = 0;   *     Stefan A. Krüger - additional utility classes
29     ******************************************************************************/
30      int minY = 0;  package appl.util;
31    
32      double realWidth = 0;  import java.awt.image.DataBuffer;
33    import java.io.Serializable;
34      double realHeight = 0;  
35    import org.geotools.referencing.crs.DefaultGeographicCRS;
36      int dataType = DataBuffer.TYPE_UNDEFINED;  import org.opengis.referencing.crs.CoordinateReferenceSystem;
37    
38      double x = 0.0;  import schmitzm.data.WritableGrid;
39    
40      double y = 0.0;  /**
41     * Simple immutable class that encapsulates raster metadata,
42      CoordinateReferenceSystem crs = null;   * especially the MetaData of a {@link WritableGrid}.
43     * Just a constructor and getters
44     * on the fields.
45          /**   *
46           * @return Returns the CRS of the raster   * <br>
47           */   * @see WritableGrid for details on the variable description
48          public final CoordinateReferenceSystem getCoordinateReferenceSystem() {   *
49            return crs;   * @author Dominik Appl
50          }   */
51    public final class RasterMetaData implements Serializable {
52          /**  
53           * @return Returns the height in cells      int width = 0;
54           */  
55          public final int getHeight() {      int height = 0;
56                  return height;  
57          }      int minX = 0;
58    
59          /**      int minY = 0;
60           * @return Returns the width in cells.  
61           */      double realWidth = 0;
62          public final int getWidth() {  
63                  return width;      double realHeight = 0;
64          }  
65        int dataType = DataBuffer.TYPE_UNDEFINED;
66          /**  
67           * @return Returns the dataType.      double x = 0.0;
68           */  
69          public final int getDataType() {      double y = 0.0;
70                  return dataType;  
71          }      CoordinateReferenceSystem crs = null;
72    
73          /**  
74           * @return Returns minX (used to indicate a start index)          /**
75           * @see WritableGrid#getMinX()           * @return Returns the CRS of the raster
76           */           */
77          public final int getMinX() {          public final CoordinateReferenceSystem getCoordinateReferenceSystem() {
78                  return minX;            return crs;
79          }          }
80    
81          /**          /**
82           * @return Returns the minY ((used to indicate a start index)           * @return Returns the height in cells
83           * @see WritableGrid#getMinY()           */
84           */          public final int getHeight() {
85          public final int getMinY() {                  return height;
86                  return minY;          }
87          }  
88            /**
89          /**           * @return Returns the width in cells.
90           * @return Returns the realHeight.           */
91           */          public final int getWidth() {
92          public final double getRealHeight() {                  return width;
93                  return realHeight;          }
94          }  
95            /**
96          /**           * @return Returns the dataType.
97           * @return Returns the realWidth.           */
98           */          public final int getDataType() {
99          public final double getRealWidth() {                  return dataType;
100                  return realWidth;          }
101          }  
102            /**
103          /**           * @return Returns minX (used to indicate a start index)
104           * @return Returns the (geographic) x-coordinate           * @see WritableGrid#getMinX()
105           */           */
106          public final double getX() {          public final int getMinX() {
107                  return x;                  return minX;
108          }          }
109    
110            /**
111          /**           * @return Returns the minY ((used to indicate a start index)
112           * @return Returns  the (geographic) y-coordinate           * @see WritableGrid#getMinY()
113           */           */
114          public final double getY() {          public final int getMinY() {
115                  return y;                  return minY;
116          }          }
117    
118          /**          /**
119           * @param dataType the datatype           * @return Returns the realHeight.
120           * @param gridWidth the width of the grid (in cells)           */
121           * @param gridHeight the height of the grid (in cells)          public final double getRealHeight() {
122           * @param minX the minX (used to indicate a start index)                  return realHeight;
123           * @param minY the minY (used to indicate a start index)          }
124           * @param realWidth the real width  
125           * @param realHeight the real height          /**
126           * @param x the (geographic) x-coordinate           * @return Returns the realWidth.
127           * @param y the (geographic) y-coordinate           */
128       * @param crs the {@link CoordinateReferenceSystem}. Use null for DefaultCRS (WGS84)          public final double getRealWidth() {
129       *                  return realWidth;
130       * @see WritableGrid          }
131           */  
132          public RasterMetaData(int dataType, int gridWidth, int gridHeight,          /**
133                          int minX, int minY, double x, double y, double realWidth,           * @return Returns the (geographic) x-coordinate
134                          double realHeight, CoordinateReferenceSystem crs) {           */
135                  this.width = gridWidth;          public final double getX() {
136                  this.height = gridHeight;                  return x;
137                  this.minX = minX;          }
138                  this.minY = minY;  
139                  this.realWidth = realWidth;  
140                  this.realHeight = realHeight;          /**
141                  this.dataType = dataType;           * @return Returns  the (geographic) y-coordinate
142                  this.x = x;           */
143                  this.y = y;          public final double getY() {
144                  this.crs = (crs == null) ? DefaultGeographicCRS.WGS84 : crs;                  return y;
145                    }
146          }  
147            /**
148          /**           * @param dataType the datatype
149           * Constructs a RasterMetaData Object. The values of the real height/ width           * @param gridWidth the width of the grid (in cells)
150           * are calculated out of the cellsize. The cells are assumed to be squares.           * @param gridHeight the height of the grid (in cells)
151           *           * @param minX the minX (used to indicate a start index)
152           * @param dataType the datatype           * @param minY the minY (used to indicate a start index)
153           * @param gridWidth the width of the grid (in cells)           * @param realWidth the real width
154           * @param gridHeight the height of the grid (in cells)           * @param realHeight the real height
155           * @param minX the minX (used to indicate a start index)           * @param x the (geographic) x-coordinate
156           * @param minY the minY (used to indicate a start index)           * @param y the (geographic) y-coordinate
157           * @param x the (geographic) x-coordinate       * @param crs the {@link CoordinateReferenceSystem}. Use null for DefaultCRS (WGS84)
158           * @param y the (geographic) y-coordinate       *
159           * @param cellSize the real size of one cell       * @see WritableGrid
160       * @param crs the {@link CoordinateReferenceSystem}, use null for default CRS (WGS84)           */
161           */          public RasterMetaData(int dataType, int gridWidth, int gridHeight,
162          public RasterMetaData(int dataType,  int gridWidth, int gridHeight,                          int minX, int minY, double x, double y, double realWidth,
163                          int minX, int minY, double x, double y, double cellSize, CoordinateReferenceSystem crs) {                          double realHeight, CoordinateReferenceSystem crs) {
164                    this.width = gridWidth;
165                  this(dataType, gridWidth, gridHeight, minX, minY, x, y, gridWidth                  this.height = gridHeight;
166                                  * cellSize, gridHeight * cellSize,crs);                  this.minX = minX;
167          }                  this.minY = minY;
168                    this.realWidth = realWidth;
169          /**                  this.realHeight = realHeight;
170           * Constructs a RasterMetaDataObject out of the given Grid                  this.dataType = dataType;
171           * @param w the source grid                  this.x = x;
172           */                  this.y = y;
173          public RasterMetaData(WritableGrid w) {                  this.crs = (crs == null) ? DefaultGeographicCRS.WGS84 : crs;
174          super();          
175          this.width = w.getWidth();          }
176          this.height = w.getHeight();  
177          this.minX = w.getMinX();          /**
178          this.minY = w.getMinY();           * Constructs a RasterMetaData Object. The values of the real height/ width
179          this.realWidth = w.getRealWidth();           * are calculated out of the cellsize. The cells are assumed to be squares.
180          this.realHeight = w.getRealHeight();           *
181          this.dataType = w.getSampleType();           * @param dataType the datatype
182          this.x = w.getX();           * @param gridWidth the width of the grid (in cells)
183          this.y = w.getY();           * @param gridHeight the height of the grid (in cells)
184          this.crs = w.getCoordinateReferenceSystem();           * @param minX the minX (used to indicate a start index)
185      }           * @param minY the minY (used to indicate a start index)
186             * @param x the (geographic) x-coordinate
187          /**           * @param y the (geographic) y-coordinate
188           * needed for serialization           * @param cellSize the real size of one cell
189           */       * @param crs the {@link CoordinateReferenceSystem}, use null for default CRS (WGS84)
190          private RasterMetaData() {           */
191           this(0,0,0,0,0,0,0,0,0,null);          public RasterMetaData(int dataType,  int gridWidth, int gridHeight,
192          }                          int minX, int minY, double x, double y, double cellSize, CoordinateReferenceSystem crs) {
193    
194          /**                  this(dataType, gridWidth, gridHeight, minX, minY, x, y, gridWidth
195           * @return the real width of a raster cell                                  * cellSize, gridHeight * cellSize,crs);
196           */          }
197          public final double getCellWidth() {  
198                  return getRealWidth() / getWidth();          /**
199          }           * Constructs a RasterMetaDataObject out of the given Grid
200             * @param w the source grid
201          /**           */
202           * Checks if the given RasterMetaData object has the same values.          public RasterMetaData(WritableGrid w) {
203           *          super();
204           * @param rasterMeta must be a RasterMetaDataObject! Else ClassCastException will be thrown.          this.width = w.getWidth();
205           * @return true, if all values are the same          this.height = w.getHeight();
206           * @see java.lang.Object#equals(java.lang.Object)          this.minX = w.getMinX();
207           */          this.minY = w.getMinY();
208          @Override          this.realWidth = w.getRealWidth();
209          public boolean equals(Object rasterMeta) {          this.realHeight = w.getRealHeight();
210                  RasterMetaData r = (RasterMetaData) rasterMeta;          this.dataType = w.getSampleType();
211          return (          this.x = w.getX();
212                          this.width == r.getWidth() &&          this.y = w.getY();
213                          this.height == r.getHeight() &&          this.crs = w.getCoordinateReferenceSystem();
214                          this.minX == r.getMinX() &&      }
215                          this.minY == r.getMinY() &&  
216                          this.realWidth == r.getRealWidth() &&          /**
217                          this.realHeight == r.getRealHeight() &&           * needed for serialization
218                          this.dataType == r.getDataType() &&           */
219                          this.x == r.getX() &&          private RasterMetaData() {
220                          this.y == r.getY()           this(0,0,0,0,0,0,0,0,0,null);
221                          );          }
222          }  
223            /**
224          /**           * @return the real width of a raster cell
225           * @return the real height of a raster cell           */
226           */          public final double getCellWidth() {
227          public final double getCellHeight() {                  return getRealWidth() / getWidth();
228                  return getRealHeight() / getHeight();          }
229          }  
230            /**
231          public final String toString() {           * Checks if the given RasterMetaData object has the same values.
232                  return "MetaData: type:" + dataType + " wc:" + width + "hc:" + height           *
233                                  + " minX:" + minX + " minY:" + minY + " x:" + x + " y:" + y           * @param rasterMeta must be a RasterMetaDataObject! Else ClassCastException will be thrown.
234                                  + " rw:" + realWidth + " rh:" + realHeight;           * @return true, if all values are the same
235          }           * @see java.lang.Object#equals(java.lang.Object)
236  }           */
237            @Override
238            public boolean equals(Object rasterMeta) {
239                    RasterMetaData r = (RasterMetaData) rasterMeta;
240            return (
241                            this.width == r.getWidth() &&
242                            this.height == r.getHeight() &&
243                            this.minX == r.getMinX() &&
244                            this.minY == r.getMinY() &&
245                            this.realWidth == r.getRealWidth() &&
246                            this.realHeight == r.getRealHeight() &&
247                            this.dataType == r.getDataType() &&
248                            this.x == r.getX() &&
249                            this.y == r.getY()
250                            );
251            }
252    
253            /**
254             * @return the real height of a raster cell
255             */
256            public final double getCellHeight() {
257                    return getRealHeight() / getHeight();
258            }
259    
260            public final String toString() {
261                    return "MetaData: type:" + dataType + " wc:" + width + "hc:" + height
262                                    + " minX:" + minX + " minY:" + minY + " x:" + x + " y:" + y
263                                    + " rw:" + realWidth + " rh:" + realHeight;
264            }
265    }

Legend:
Removed from v.243  
changed lines
  Added in v.244

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26