root / trunk / libraries / libDataSourceBaseDrivers / src / org / gvsig / data / datastores / vectorial / driver / shp / fileshp / ShapeFileHeader2.java @ 19673
History | View | Annotate | Download (8.6 KB)
1 |
/*
|
---|---|
2 |
* GISToolkit - Geographical Information System Toolkit
|
3 |
* (C) 2002, Ithaqua Enterprises Inc.
|
4 |
*
|
5 |
* This library is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU Lesser General Public
|
7 |
* License as published by the Free Software Foundation;
|
8 |
* version 2.1 of the License.
|
9 |
*
|
10 |
* This library is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13 |
* Lesser General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU Lesser General Public
|
16 |
* License along with this library; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
18 |
*
|
19 |
*/
|
20 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
21 |
*
|
22 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
23 |
*
|
24 |
* This program is free software; you can redistribute it and/or
|
25 |
* modify it under the terms of the GNU General Public License
|
26 |
* as published by the Free Software Foundation; either version 2
|
27 |
* of the License, or (at your option) any later version.
|
28 |
*
|
29 |
* This program is distributed in the hope that it will be useful,
|
30 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
31 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
32 |
* GNU General Public License for more details.
|
33 |
*
|
34 |
* You should have received a copy of the GNU General Public License
|
35 |
* along with this program; if not, write to the Free Software
|
36 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
37 |
*
|
38 |
* For more information, contact:
|
39 |
*
|
40 |
* Generalitat Valenciana
|
41 |
* Conselleria d'Infraestructures i Transport
|
42 |
* Av. Blasco Ib??ez, 50
|
43 |
* 46010 VALENCIA
|
44 |
* SPAIN
|
45 |
*
|
46 |
* +34 963862235
|
47 |
* gvsig@gva.es
|
48 |
* www.gvsig.gva.es
|
49 |
*
|
50 |
* or
|
51 |
*
|
52 |
* IVER T.I. S.A
|
53 |
* Salamanca 50
|
54 |
* 46005 Valencia
|
55 |
* Spain
|
56 |
*
|
57 |
* +34 963163400
|
58 |
* dac@iver.es
|
59 |
*/
|
60 |
package org.gvsig.data.datastores.vectorial.driver.shp.fileshp; |
61 |
|
62 |
import java.nio.ByteBuffer; |
63 |
import java.nio.ByteOrder; |
64 |
|
65 |
import com.iver.utiles.bigfile.BigByteBuffer2; |
66 |
|
67 |
|
68 |
/**
|
69 |
* Class to represent the header in the shape file.
|
70 |
*/
|
71 |
public class ShapeFileHeader2 { |
72 |
/**
|
73 |
* Shape Type Value Shape Type 0 Null Shape 1 Point 3 PolyLine 5 Polygon 8
|
74 |
* MultiPoint 11 PointZ 13 PolyLineZ 15 PolygonZ 18 MultiPointZ 21 PointM
|
75 |
* 23 PolyLineM 25 PolygonM 28 MultiPointM 31 MultiPatch
|
76 |
*/
|
77 |
|
78 |
/* The null shape type, there is no shape for this record. */
|
79 |
public static final int SHAPE_NULL = 0; |
80 |
public static final int SHAPE_POINT = 1; |
81 |
public static final int SHAPE_POLYLINE = 3; |
82 |
public static final int SHAPE_POLYGON = 5; |
83 |
public static final int SHAPE_MULTIPOINT = 8; |
84 |
public static final int SHAPE_POINTZ = 11; |
85 |
public static final int SHAPE_POLYLINEZ = 13; |
86 |
public static final int SHAPE_POLYGONZ = 15; |
87 |
public static final int SHAPE_MULTIPOINTZ = 18; |
88 |
public static final int SHAPE_POINTM = 21; |
89 |
public static final int SHAPE_POLYLINEM = 23; |
90 |
public static final int SHAPE_POLYGONM = 25; |
91 |
public static final int SHAPE_MULTIPOINTM = 28; |
92 |
public static final int SHAPE_MULTIPATCH = 31; |
93 |
|
94 |
/** File Code, must be the value 9994 */
|
95 |
public int myFileCode = 9994; |
96 |
|
97 |
/** Unused 1; */
|
98 |
public int myUnused1 = 0; |
99 |
|
100 |
/** Unused 2; */
|
101 |
public int myUnused2 = 0; |
102 |
|
103 |
/** Unused 3; */
|
104 |
public int myUnused3 = 0; |
105 |
|
106 |
/** Unused 4; */
|
107 |
public int myUnused4 = 0; |
108 |
|
109 |
/** Unused 5; */
|
110 |
public int myUnused5 = 0; |
111 |
|
112 |
/** File Length; */
|
113 |
public int myFileLength = 0; |
114 |
|
115 |
/** Version of the file. */
|
116 |
public int myVersion = 1000; |
117 |
public int myShapeType = 0; |
118 |
|
119 |
/** BoundingBox Xmin */
|
120 |
public double myXmin = 0; |
121 |
|
122 |
/** BoundingBox Ymin */
|
123 |
public double myYmin = 0; |
124 |
|
125 |
/** BoundingBox Xmax */
|
126 |
public double myXmax = 0; |
127 |
|
128 |
/** BoundingBox Ymax */
|
129 |
public double myYmax = 0; |
130 |
|
131 |
/** BoundingBox Zmin */
|
132 |
public double myZmin = 0; |
133 |
|
134 |
/** BoundingBox Zmax */
|
135 |
public double myZmax = 0; |
136 |
|
137 |
/** BoundingBox Zmin */
|
138 |
public double myMmin = 0; |
139 |
|
140 |
/** BoundingBox Zmax */
|
141 |
public double myMmax = 0; |
142 |
|
143 |
// notify about warnings.
|
144 |
private boolean myWarning = true; |
145 |
|
146 |
/**
|
147 |
* ShapeFileHeader constructor comment.
|
148 |
*/
|
149 |
public ShapeFileHeader2() {
|
150 |
super();
|
151 |
} |
152 |
|
153 |
/**
|
154 |
* Return the file code.
|
155 |
*
|
156 |
* @return Entero.
|
157 |
*/
|
158 |
public int getFileCode() { |
159 |
return myFileCode;
|
160 |
} |
161 |
|
162 |
/**
|
163 |
* Return the version of the file.
|
164 |
*
|
165 |
* @return Versi?n.
|
166 |
*/
|
167 |
public int getVersion() { |
168 |
return myVersion;
|
169 |
} |
170 |
|
171 |
/**
|
172 |
* Get the extents of the shape file.
|
173 |
*
|
174 |
* @return FullExtent.
|
175 |
*/
|
176 |
public java.awt.geom.Rectangle2D.Double getFileExtents() {
|
177 |
return new java.awt.geom.Rectangle2D.Double(myXmin, myYmin, |
178 |
myXmax - myXmin, myYmax - myYmin); |
179 |
} |
180 |
|
181 |
/**
|
182 |
* Print warnings to system.out.
|
183 |
*
|
184 |
* @param inWarning boolean.
|
185 |
*/
|
186 |
public void setWarnings(boolean inWarning) { |
187 |
myWarning = inWarning; |
188 |
} |
189 |
|
190 |
/**
|
191 |
* Return the length of the header in 16 bit words..
|
192 |
*
|
193 |
* @return Longitud de la cabecera.
|
194 |
*/
|
195 |
public int getHeaderLength() { |
196 |
return 50; |
197 |
} |
198 |
|
199 |
/**
|
200 |
* Return the number of 16 bit words in the shape file as recorded in the
|
201 |
* header
|
202 |
*
|
203 |
* @return Longitud del fichero.
|
204 |
*/
|
205 |
public int getFileLength() { |
206 |
return myFileLength;
|
207 |
} |
208 |
|
209 |
/**
|
210 |
* Read the header from the shape file.
|
211 |
*
|
212 |
* @param in ByteBuffer.
|
213 |
*/
|
214 |
public void readHeader(BigByteBuffer2 in) { |
215 |
// the first four bytes are integers
|
216 |
// in.setLittleEndianMode(false);
|
217 |
in.order(ByteOrder.BIG_ENDIAN);
|
218 |
myFileCode = in.getInt(); |
219 |
|
220 |
if (myFileCode != 9994) { |
221 |
warn("File Code = " + myFileCode + " Not equal to 9994"); |
222 |
} |
223 |
|
224 |
// From 4 to 8 are unused.
|
225 |
myUnused1 = in.getInt(); |
226 |
|
227 |
// From 8 to 12 are unused.
|
228 |
myUnused2 = in.getInt(); |
229 |
|
230 |
// From 12 to 16 are unused.
|
231 |
myUnused3 = in.getInt(); |
232 |
|
233 |
// From 16 to 20 are unused.
|
234 |
myUnused4 = in.getInt(); |
235 |
|
236 |
// From 20 to 24 are unused.
|
237 |
myUnused5 = in.getInt(); |
238 |
|
239 |
// From 24 to 28 are the file length.
|
240 |
myFileLength = in.getInt(); |
241 |
|
242 |
// From 28 to 32 are the File Version.
|
243 |
in.order(ByteOrder.LITTLE_ENDIAN);
|
244 |
myVersion = in.getInt(); |
245 |
|
246 |
// From 32 to 36 are the Shape Type.
|
247 |
myShapeType = in.getInt(); |
248 |
|
249 |
// From 36 to 44 are Xmin.
|
250 |
myXmin = in.getDouble(); // Double.longBitsToDouble(in.getLong());
|
251 |
|
252 |
// From 44 to 52 are Ymin.
|
253 |
myYmin = in.getDouble(); |
254 |
|
255 |
// From 52 to 60 are Xmax.
|
256 |
myXmax = in.getDouble(); |
257 |
|
258 |
// From 60 to 68 are Ymax.
|
259 |
myYmax = in.getDouble(); |
260 |
|
261 |
// From 68 to 76 are Zmin.
|
262 |
myZmin = in.getDouble(); |
263 |
|
264 |
// From 76 to 84 are Zmax.
|
265 |
myZmax = in.getDouble(); |
266 |
|
267 |
// From 84 to 92 are Mmin.
|
268 |
myMmin = in.getDouble(); |
269 |
|
270 |
// From 92 to 100 are Mmax.
|
271 |
myMmax = in.getDouble(); |
272 |
|
273 |
// that is all 100 bytes of the header.
|
274 |
} |
275 |
public void write(ByteBuffer out,int type, |
276 |
int numGeoms,int length,double minX,double minY,double maxX,double maxY,double minZ,double maxZ,double minM,double maxM){ |
277 |
out.order(ByteOrder.BIG_ENDIAN);
|
278 |
|
279 |
out.putInt(myFileCode); |
280 |
|
281 |
for (int i = 0; i < 5; i++) { |
282 |
out.putInt(0); //Skip unused part of header |
283 |
} |
284 |
|
285 |
out.putInt(length); |
286 |
|
287 |
out.order(ByteOrder.LITTLE_ENDIAN);
|
288 |
|
289 |
out.putInt(myVersion); |
290 |
out.putInt(type); |
291 |
|
292 |
//write the bounding box
|
293 |
out.putDouble(minX); |
294 |
out.putDouble(minY); |
295 |
out.putDouble(maxX); |
296 |
out.putDouble(maxY); |
297 |
/*
|
298 |
out.putDouble(minZ);
|
299 |
out.putDouble(minZ);
|
300 |
out.putDouble(maxM);
|
301 |
out.putDouble(maxM);*/
|
302 |
out.order(ByteOrder.BIG_ENDIAN);
|
303 |
for (int i = 0; i < 8; i++) { |
304 |
out.putInt(0); //Skip unused part of header |
305 |
} |
306 |
|
307 |
} |
308 |
|
309 |
/**
|
310 |
* Muestra por consola los warning.
|
311 |
*
|
312 |
* @param inWarn warning.
|
313 |
*/
|
314 |
private void warn(String inWarn) { |
315 |
if (myWarning) {
|
316 |
System.out.print("WARNING: "); |
317 |
System.out.println(inWarn);
|
318 |
} |
319 |
} |
320 |
} |