1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60 package org.gvsig.fmap.dal.store.shp.utils;
61
62 import java.nio.ByteBuffer;
63 import java.nio.ByteOrder;
64
65 import org.gvsig.utils.bigfile.BigByteBuffer2;
66
67
68
69
70
71
72 public class ShapeFileHeader2 {
73
74
75
76
77
78
79
80 public static final int SHAPE_NULL = 0;
81 public static final int SHAPE_POINT = 1;
82 public static final int SHAPE_POLYLINE = 3;
83 public static final int SHAPE_POLYGON = 5;
84 public static final int SHAPE_MULTIPOINT = 8;
85 public static final int SHAPE_POINTZ = 11;
86 public static final int SHAPE_POLYLINEZ = 13;
87 public static final int SHAPE_POLYGONZ = 15;
88 public static final int SHAPE_MULTIPOINTZ = 18;
89 public static final int SHAPE_POINTM = 21;
90 public static final int SHAPE_POLYLINEM = 23;
91 public static final int SHAPE_POLYGONM = 25;
92 public static final int SHAPE_MULTIPOINTM = 28;
93 public static final int SHAPE_MULTIPATCH = 31;
94
95
96 public int myFileCode = 9994;
97
98
99 public int myUnused1 = 0;
100
101
102 public int myUnused2 = 0;
103
104
105 public int myUnused3 = 0;
106
107
108 public int myUnused4 = 0;
109
110
111 public int myUnused5 = 0;
112
113
114 public int myFileLength = 0;
115
116
117 public int myVersion = 1000;
118 public int myShapeType = 0;
119
120
121 public double myXmin = 0;
122
123
124 public double myYmin = 0;
125
126
127 public double myXmax = 0;
128
129
130 public double myYmax = 0;
131
132
133 public double myZmin = 0;
134
135
136 public double myZmax = 0;
137
138
139 public double myMmin = 0;
140
141
142 public double myMmax = 0;
143
144
145 private boolean myWarning = true;
146
147
148
149
150 public ShapeFileHeader2() {
151 super();
152 }
153
154
155
156
157
158
159 public int getFileCode() {
160 return myFileCode;
161 }
162
163
164
165
166
167
168 public int getVersion() {
169 return myVersion;
170 }
171
172
173
174
175
176
177 public java.awt.geom.Rectangle2D.Double getFileExtents() {
178 return new java.awt.geom.Rectangle2D.Double(myXmin, myYmin,
179 myXmax - myXmin, myYmax - myYmin);
180 }
181
182
183
184
185
186
187 public void setWarnings(boolean inWarning) {
188 myWarning = inWarning;
189 }
190
191
192
193
194
195
196 public int getHeaderLength() {
197 return 50;
198 }
199
200
201
202
203
204
205
206 public int getFileLength() {
207 return myFileLength;
208 }
209
210
211
212
213
214
215 public void readHeader(BigByteBuffer2 in) {
216
217
218 in.order(ByteOrder.BIG_ENDIAN);
219 myFileCode = in.getInt();
220
221 if (myFileCode != 9994) {
222 warn("File Code = " + myFileCode + " Not equal to 9994");
223 }
224
225
226 myUnused1 = in.getInt();
227
228
229 myUnused2 = in.getInt();
230
231
232 myUnused3 = in.getInt();
233
234
235 myUnused4 = in.getInt();
236
237
238 myUnused5 = in.getInt();
239
240
241 myFileLength = in.getInt();
242
243
244 in.order(ByteOrder.LITTLE_ENDIAN);
245 myVersion = in.getInt();
246
247
248 myShapeType = in.getInt();
249
250
251 myXmin = in.getDouble();
252
253
254 myYmin = in.getDouble();
255
256
257 myXmax = in.getDouble();
258
259
260 myYmax = in.getDouble();
261
262
263 myZmin = in.getDouble();
264
265
266 myZmax = in.getDouble();
267
268
269 myMmin = in.getDouble();
270
271
272 myMmax = in.getDouble();
273
274
275 }
276 public void write(ByteBuffer out,int type,
277 int numGeoms,int length,double minX,double minY,double maxX,double maxY,double minZ,double maxZ,double minM,double maxM){
278 out.order(ByteOrder.BIG_ENDIAN);
279
280 out.putInt(myFileCode);
281
282 for (int i = 0; i < 5; i++) {
283 out.putInt(0);
284 }
285
286 out.putInt(length);
287
288 out.order(ByteOrder.LITTLE_ENDIAN);
289
290 out.putInt(myVersion);
291 out.putInt(type);
292
293
294 out.putDouble(minX);
295 out.putDouble(minY);
296 out.putDouble(maxX);
297 out.putDouble(maxY);
298
299
300
301
302
303 out.order(ByteOrder.BIG_ENDIAN);
304 for (int i = 0; i < 8; i++) {
305 out.putInt(0);
306 }
307
308 }
309
310
311
312
313
314
315 private void warn(String inWarn) {
316 if (myWarning) {
317 System.out.print("WARNING: ");
318 System.out.println(inWarn);
319 }
320 }
321 }