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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (hide annotations)
Tue Feb 24 22:43:52 2009 UTC (16 years ago) by mojays
File size: 6172 byte(s)
First Commit, corresponds to Revision 1008 of Wikisquare-SVN
includes:
- schmitzm.* (except schmitzm.test)
- org.geotools.* (all overridden classes)
- skrueger.geotools
- skrueger.i8n
- skrueger.swing
- appl.data.LateLoadable (dependency in SCHMITZM)
- appl.data.LoadingException (dependency in SCHMITZM)
- appl.util.RasterMetaData (dependency in SCHMITZM)

1 mojays 2 package appl.util;
2    
3     import java.awt.image.DataBuffer;
4     import java.io.Serializable;
5    
6     import org.geotools.referencing.crs.DefaultGeographicCRS;
7     import org.opengis.referencing.crs.CoordinateReferenceSystem;
8    
9     import schmitzm.data.WritableGrid;
10    
11     /**
12     * Simple immutable class that encapsulates raster metadata,
13     * especially the MetaData of a {@link WritableGrid}.
14     * Just a constructor and getters
15     * on the fields.
16     *
17     * <br>
18     * @see WritableGrid for details on the variable description
19     *
20     * @author Dominik Appl
21     */
22     public final class RasterMetaData implements Serializable {
23    
24     int width = 0;
25    
26     int height = 0;
27    
28     int minX = 0;
29    
30     int minY = 0;
31    
32     double realWidth = 0;
33    
34     double realHeight = 0;
35    
36     int dataType = DataBuffer.TYPE_UNDEFINED;
37    
38     double x = 0.0;
39    
40     double y = 0.0;
41    
42     CoordinateReferenceSystem crs = null;
43    
44    
45     /**
46     * @return Returns the CRS of the raster
47     */
48     public final CoordinateReferenceSystem getCoordinateReferenceSystem() {
49     return crs;
50     }
51    
52     /**
53     * @return Returns the height in cells
54     */
55     public final int getHeight() {
56     return height;
57     }
58    
59     /**
60     * @return Returns the width in cells.
61     */
62     public final int getWidth() {
63     return width;
64     }
65    
66     /**
67     * @return Returns the dataType.
68     */
69     public final int getDataType() {
70     return dataType;
71     }
72    
73     /**
74     * @return Returns minX (used to indicate a start index)
75     * @see WritableGrid#getMinX()
76     */
77     public final int getMinX() {
78     return minX;
79     }
80    
81     /**
82     * @return Returns the minY ((used to indicate a start index)
83     * @see WritableGrid#getMinY()
84     */
85     public final int getMinY() {
86     return minY;
87     }
88    
89     /**
90     * @return Returns the realHeight.
91     */
92     public final double getRealHeight() {
93     return realHeight;
94     }
95    
96     /**
97     * @return Returns the realWidth.
98     */
99     public final double getRealWidth() {
100     return realWidth;
101     }
102    
103     /**
104     * @return Returns the (geographic) x-coordinate
105     */
106     public final double getX() {
107     return x;
108     }
109    
110    
111     /**
112     * @return Returns the (geographic) y-coordinate
113     */
114     public final double getY() {
115     return y;
116     }
117    
118     /**
119     * @param dataType the datatype
120     * @param gridWidth the width of the grid (in cells)
121     * @param gridHeight the height of the grid (in cells)
122     * @param minX the minX (used to indicate a start index)
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
127     * @param y the (geographic) y-coordinate
128     * @param crs the {@link CoordinateReferenceSystem}. Use null for DefaultCRS (WGS84)
129     *
130     * @see WritableGrid
131     */
132     public RasterMetaData(int dataType, int gridWidth, int gridHeight,
133     int minX, int minY, double x, double y, double realWidth,
134     double realHeight, CoordinateReferenceSystem crs) {
135     this.width = gridWidth;
136     this.height = gridHeight;
137     this.minX = minX;
138     this.minY = minY;
139     this.realWidth = realWidth;
140     this.realHeight = realHeight;
141     this.dataType = dataType;
142     this.x = x;
143     this.y = y;
144     this.crs = (crs == null) ? DefaultGeographicCRS.WGS84 : crs;
145    
146     }
147    
148     /**
149     * Constructs a RasterMetaData Object. The values of the real height/ width
150     * are calculated out of the cellsize. The cells are assumed to be squares.
151     *
152     * @param dataType the datatype
153     * @param gridWidth the width of the grid (in cells)
154     * @param gridHeight the height of the grid (in cells)
155     * @param minX the minX (used to indicate a start index)
156     * @param minY the minY (used to indicate a start index)
157     * @param x the (geographic) x-coordinate
158     * @param y the (geographic) y-coordinate
159     * @param cellSize the real size of one cell
160     * @param crs the {@link CoordinateReferenceSystem}, use null for default CRS (WGS84)
161     */
162     public RasterMetaData(int dataType, int gridWidth, int gridHeight,
163     int minX, int minY, double x, double y, double cellSize, CoordinateReferenceSystem crs) {
164    
165     this(dataType, gridWidth, gridHeight, minX, minY, x, y, gridWidth
166     * cellSize, gridHeight * cellSize,crs);
167     }
168    
169     /**
170     * Constructs a RasterMetaDataObject out of the given Grid
171     * @param w the source grid
172     */
173     public RasterMetaData(WritableGrid w) {
174     super();
175     this.width = w.getWidth();
176     this.height = w.getHeight();
177     this.minX = w.getMinX();
178     this.minY = w.getMinY();
179     this.realWidth = w.getRealWidth();
180     this.realHeight = w.getRealHeight();
181     this.dataType = w.getSampleType();
182     this.x = w.getX();
183     this.y = w.getY();
184     this.crs = w.getCoordinateReferenceSystem();
185     }
186    
187     /**
188     * needed for serialization
189     */
190     private RasterMetaData() {
191     this(0,0,0,0,0,0,0,0,0,null);
192     }
193    
194     /**
195     * @return the real width of a raster cell
196     */
197     public final double getCellWidth() {
198     return getRealWidth() / getWidth();
199     }
200    
201     /**
202     * Checks if the given RasterMetaData object has the same values.
203     *
204     * @param rasterMeta must be a RasterMetaDataObject! Else ClassCastException will be thrown.
205     * @return true, if all values are the same
206     * @see java.lang.Object#equals(java.lang.Object)
207     */
208     @Override
209     public boolean equals(Object rasterMeta) {
210     RasterMetaData r = (RasterMetaData) rasterMeta;
211     return (
212     this.width == r.getWidth() &&
213     this.height == r.getHeight() &&
214     this.minX == r.getMinX() &&
215     this.minY == r.getMinY() &&
216     this.realWidth == r.getRealWidth() &&
217     this.realHeight == r.getRealHeight() &&
218     this.dataType == r.getDataType() &&
219     this.x == r.getX() &&
220     this.y == r.getY()
221     );
222     }
223    
224     /**
225     * @return the real height of a raster cell
226     */
227     public final double getCellHeight() {
228     return getRealHeight() / getHeight();
229     }
230    
231     public final String toString() {
232     return "MetaData: type:" + dataType + " wc:" + width + "hc:" + height
233     + " minX:" + minX + " minY:" + minY + " x:" + x + " y:" + y
234     + " rw:" + realWidth + " rh:" + realHeight;
235     }
236     }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26