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