svn-gvsig-desktop / tags / v1_1_Build_1011 / libraries / libCq_CMS_praster / src / org / cresques / io / ShpFileHeader.java @ 12904
History | View | Annotate | Download (6.05 KB)
1 | 8026 | nacho | package org.cresques.io; |
---|---|---|---|
2 | |||
3 | |||
4 | /*
|
||
5 | * GISToolkit - Geographical Information System Toolkit
|
||
6 | * (C) 2002, Ithaqua Enterprises Inc.
|
||
7 | *
|
||
8 | * This library is free software; you can redistribute it and/or
|
||
9 | * modify it under the terms of the GNU Lesser General Public
|
||
10 | * License as published by the Free Software Foundation;
|
||
11 | * version 2.1 of the License.
|
||
12 | *
|
||
13 | * This library is distributed in the hope that it will be useful,
|
||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
16 | * Lesser General Public License for more details.
|
||
17 | *
|
||
18 | * You should have received a copy of the GNU Lesser General Public
|
||
19 | * License along with this library; if not, write to the Free Software
|
||
20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||
21 | *
|
||
22 | */
|
||
23 | import java.nio.*; |
||
24 | |||
25 | |||
26 | /**
|
||
27 | * Procesa la cabecera de un .shp
|
||
28 | * @author "Luis W. Sevilla" <sevilla_lui@gva.es>* @author administrador
|
||
29 | */
|
||
30 | public class ShpFileHeader { |
||
31 | //}
|
||
32 | |||
33 | /**
|
||
34 | * Class to represent the header in the shape file.
|
||
35 | */
|
||
36 | |||
37 | //public class ShapeFileHeader {
|
||
38 | |||
39 | /**
|
||
40 | * Shape Type
|
||
41 | * Value Shape Type
|
||
42 | * 0 Null Shape
|
||
43 | * 1 Point
|
||
44 | * 3 PolyLine
|
||
45 | * 5 Polygon
|
||
46 | * 8 MultiPoint
|
||
47 | * 11 PointZ
|
||
48 | * 13 PolyLineZ
|
||
49 | * 15 PolygonZ
|
||
50 | * 18 MultiPointZ
|
||
51 | * 21 PointM
|
||
52 | * 23 PolyLineM
|
||
53 | * 25 PolygonM
|
||
54 | * 28 MultiPointM
|
||
55 | * 31 MultiPatch
|
||
56 | */
|
||
57 | |||
58 | /* The null shape type, there is no shape for this record. */
|
||
59 | public static final int SHAPE_NULL = 0; |
||
60 | public static final int SHAPE_POINT = 1; |
||
61 | public static final int SHAPE_POLYLINE = 3; |
||
62 | public static final int SHAPE_POLYGON = 5; |
||
63 | public static final int SHAPE_MULTIPOINT = 8; |
||
64 | public static final int SHAPE_POINTZ = 11; |
||
65 | public static final int SHAPE_POLYLINEZ = 13; |
||
66 | public static final int SHAPE_POLYGONZ = 15; |
||
67 | public static final int SHAPE_MULTIPOINTZ = 18; |
||
68 | public static final int SHAPE_POINTM = 21; |
||
69 | public static final int SHAPE_POLYLINEM = 23; |
||
70 | public static final int SHAPE_POLYGONM = 25; |
||
71 | public static final int SHAPE_MULTIPOINTM = 28; |
||
72 | public static final int SHAPE_MULTIPATCH = 31; |
||
73 | |||
74 | /**File Code, must be the value 9994*/
|
||
75 | int myFileCode = 9994; |
||
76 | |||
77 | /**
|
||
78 | * Unused 1;
|
||
79 | */
|
||
80 | int myUnused1 = 0; |
||
81 | |||
82 | /**
|
||
83 | * Unused 2;
|
||
84 | */
|
||
85 | int myUnused2 = 0; |
||
86 | |||
87 | /**
|
||
88 | * Unused 3;
|
||
89 | */
|
||
90 | int myUnused3 = 0; |
||
91 | |||
92 | /**
|
||
93 | * Unused 4;
|
||
94 | */
|
||
95 | int myUnused4 = 0; |
||
96 | |||
97 | /**
|
||
98 | * Unused 5;
|
||
99 | */
|
||
100 | int myUnused5 = 0; |
||
101 | |||
102 | /**File Length;*/
|
||
103 | int myFileLength = 0; |
||
104 | |||
105 | /**Version of the file.*/
|
||
106 | int myVersion = 1000; |
||
107 | int myShapeType = 0; |
||
108 | |||
109 | /**
|
||
110 | * BoundingBox Xmin
|
||
111 | */
|
||
112 | double myXmin = 0; |
||
113 | |||
114 | /**
|
||
115 | * BoundingBox Ymin
|
||
116 | */
|
||
117 | double myYmin = 0; |
||
118 | |||
119 | /**
|
||
120 | * BoundingBox Xmax
|
||
121 | */
|
||
122 | double myXmax = 0; |
||
123 | |||
124 | /**
|
||
125 | * BoundingBox Ymax
|
||
126 | */
|
||
127 | double myYmax = 0; |
||
128 | |||
129 | /**
|
||
130 | * BoundingBox Zmin
|
||
131 | */
|
||
132 | double myZmin = 0; |
||
133 | |||
134 | /**
|
||
135 | * BoundingBox Zmax
|
||
136 | */
|
||
137 | double myZmax = 0; |
||
138 | |||
139 | /**
|
||
140 | * BoundingBox Zmin
|
||
141 | */
|
||
142 | double myMmin = 0; |
||
143 | |||
144 | /**
|
||
145 | * BoundingBox Zmax
|
||
146 | */
|
||
147 | double myMmax = 0; |
||
148 | |||
149 | // notify about warnings.
|
||
150 | private boolean myWarning = true; |
||
151 | |||
152 | /**
|
||
153 | * ShapeFileHeader constructor comment.
|
||
154 | */
|
||
155 | public ShpFileHeader() {
|
||
156 | super();
|
||
157 | } |
||
158 | |||
159 | /** Return the file code. */
|
||
160 | public int getFileCode() { |
||
161 | return myFileCode;
|
||
162 | } |
||
163 | |||
164 | /** Return the version of the file. */
|
||
165 | public int getVersion() { |
||
166 | return myVersion;
|
||
167 | } |
||
168 | |||
169 | /** Get the extents of the shape file. */
|
||
170 | public java.awt.geom.Rectangle2D.Double getFileExtents() {
|
||
171 | return new java.awt.geom.Rectangle2D.Double(myXmin, myYmin, |
||
172 | myXmax - myXmin, |
||
173 | myYmax - myYmin); |
||
174 | } |
||
175 | |||
176 | /** Print warnings to system.out. */
|
||
177 | public void setWarnings(boolean inWarning) { |
||
178 | myWarning = inWarning; |
||
179 | } |
||
180 | |||
181 | /**
|
||
182 | * Return the length of the header in 16 bit words..
|
||
183 | */
|
||
184 | public int getHeaderLength() { |
||
185 | return 50; |
||
186 | } |
||
187 | |||
188 | /**
|
||
189 | * Return the number of 16 bit words in the shape file as recorded in the header
|
||
190 | */
|
||
191 | public int getFileLength() { |
||
192 | return myFileLength;
|
||
193 | } |
||
194 | |||
195 | /**
|
||
196 | * Read the header from the shape file.
|
||
197 | */
|
||
198 | public void readHeader(ByteBuffer in) { |
||
199 | // the first four bytes are integers
|
||
200 | // in.setLittleEndianMode(false);
|
||
201 | in.order(ByteOrder.BIG_ENDIAN);
|
||
202 | myFileCode = in.getInt(); |
||
203 | |||
204 | if (myFileCode != 9994) { |
||
205 | warn("File Code = " + myFileCode + " Not equal to 9994"); |
||
206 | } |
||
207 | |||
208 | // From 4 to 8 are unused.
|
||
209 | myUnused1 = in.getInt(); |
||
210 | |||
211 | // From 8 to 12 are unused.
|
||
212 | myUnused2 = in.getInt(); |
||
213 | |||
214 | // From 12 to 16 are unused.
|
||
215 | myUnused3 = in.getInt(); |
||
216 | |||
217 | // From 16 to 20 are unused.
|
||
218 | myUnused4 = in.getInt(); |
||
219 | |||
220 | // From 20 to 24 are unused.
|
||
221 | myUnused5 = in.getInt(); |
||
222 | |||
223 | // From 24 to 28 are the file length.
|
||
224 | myFileLength = in.getInt(); |
||
225 | |||
226 | // From 28 to 32 are the File Version.
|
||
227 | in.order(ByteOrder.LITTLE_ENDIAN);
|
||
228 | myVersion = in.getInt(); |
||
229 | |||
230 | // From 32 to 36 are the Shape Type.
|
||
231 | myShapeType = in.getInt(); |
||
232 | |||
233 | // From 36 to 44 are Xmin.
|
||
234 | myXmin = in.getDouble(); // Double.longBitsToDouble(in.getLong());
|
||
235 | |||
236 | // From 44 to 52 are Ymin.
|
||
237 | myYmin = in.getDouble(); |
||
238 | |||
239 | // From 52 to 60 are Xmax.
|
||
240 | myXmax = in.getDouble(); |
||
241 | |||
242 | // From 60 to 68 are Ymax.
|
||
243 | myYmax = in.getDouble(); |
||
244 | |||
245 | // From 68 to 76 are Zmin.
|
||
246 | myZmin = in.getDouble(); |
||
247 | |||
248 | // From 76 to 84 are Zmax.
|
||
249 | myZmax = in.getDouble(); |
||
250 | |||
251 | // From 84 to 92 are Mmin.
|
||
252 | myMmin = in.getDouble(); |
||
253 | |||
254 | // From 92 to 100 are Mmax.
|
||
255 | myMmax = in.getDouble(); |
||
256 | |||
257 | // that is all 100 bytes of the header.
|
||
258 | } |
||
259 | |||
260 | private void warn(String inWarn) { |
||
261 | if (myWarning) {
|
||
262 | System.out.print("WARNING: "); |
||
263 | System.out.println(inWarn);
|
||
264 | } |
||
265 | } |
||
266 | } |