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