Statistics
| Revision:

root / branches / Mobile_Compatible_Hito_1 / libFMap / src / es / prodevelop / gvsig / mobile / fmap / driver / vect / shp / ShapeFileHeader.java @ 21606

History | View | Annotate | Download (9.04 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
/************************************************
61
 *                                                                                                *
62
 *   Modfied By:                                                                *
63
 *   Prodevelop Integraci?n de Tecnolog?as SL        *
64
 *   Conde Salvatierra de ?lava , 34-10                        *
65
 *   46004 Valencia                                                                *
66
 *   Spain                                                                                *
67
 *                                                                                                *
68
 *   +34 963 510 612                                                        *
69
 *   +34 963 510 968                                                        *
70
 *   gis@prodevelop.es                                                        *
71
 *   http://www.prodevelop.es                                        *
72
 *                                                                                                *
73
 *   gvSIG Mobile Team 2006                                         *
74
 *                                                                                          *         
75
 ************************************************/
76

    
77
package es.prodevelop.gvsig.mobile.fmap.driver.vect.shp;
78

    
79
import java.io.IOException;
80
import java.nio.ByteOrder;
81

    
82
import org.apache.log4j.Logger;
83
import org.gvsig.datasources.common.IByteBuffer;
84

    
85
import es.prodevelop.gvsig.mobile.fmap.core.FPolyline2D;
86
import es.prodevelop.gvsig.mobile.fmap.util.bytebuffer.FalseByteBuffer;
87

    
88
/**
89
 * Class to represent the header in the shape file.
90
 */
91
public class ShapeFileHeader {
92
    /**
93
     * Shape Type Value Shape Type 0 Null Shape 1 Point 3 PolyLine 5 Polygon 8
94
     * MultiPoint 11 PointZ 13 PolyLineZ 15 PolygonZ 18 MultiPointZ 21 PointM
95
     * 23 PolyLineM 25 PolygonM 28 MultiPointM 31 MultiPatch
96
     */
97

    
98
    /* The null shape type, there is no shape for this record. */
99
    public static final int SHAPE_NULL = 0;
100
    public static final int SHAPE_POINT = 1;
101
    public static final int SHAPE_POLYLINE = 3;
102
    public static final int SHAPE_POLYGON = 5;
103
    public static final int SHAPE_MULTIPOINT = 8;
104
    public static final int SHAPE_POINTZ = 11;
105
    public static final int SHAPE_POLYLINEZ = 13;
106
    public static final int SHAPE_POLYGONZ = 15;
107
    public static final int SHAPE_MULTIPOINTZ = 18;
108
    public static final int SHAPE_POINTM = 21;
109
    public static final int SHAPE_POLYLINEM = 23;
110
    public static final int SHAPE_POLYGONM = 25;
111
    public static final int SHAPE_MULTIPOINTM = 28;
112
    public static final int SHAPE_MULTIPATCH = 31;
113
    
114
    private static Logger logger = Logger.getLogger(FPolyline2D.class);
115

    
116
    /** File Code, must be the value 9994 */
117
    public int myFileCode = 9994;
118

    
119
    /** Unused 1; */
120
    public int myUnused1 = 0;
121

    
122
    /** Unused 2; */
123
    public int myUnused2 = 0;
124

    
125
    /** Unused 3; */
126
    public int myUnused3 = 0;
127

    
128
    /** Unused 4; */
129
    public int myUnused4 = 0;
130

    
131
    /** Unused 5; */
132
    public int myUnused5 = 0;
133

    
134
    /** File Length; */
135
    public int myFileLength = 0;
136

    
137
    /** Version of the file. */
138
    public int myVersion = 1000;
139
    public int myShapeType = 0;
140

    
141
    /** BoundingBox Xmin */
142
    public double myXmin = 0;
143

    
144
    /** BoundingBox Ymin */
145
    public double myYmin = 0;
146

    
147
    /** BoundingBox Xmax */
148
    public double myXmax = 0;
149

    
150
    /** BoundingBox Ymax */
151
    public double myYmax = 0;
152

    
153
    /** BoundingBox Zmin */
154
    public double myZmin = 0;
155

    
156
    /** BoundingBox Zmax */
157
    public double myZmax = 0;
158

    
159
    /** BoundingBox Zmin */
160
    public double myMmin = 0;
161

    
162
    /** BoundingBox Zmax */
163
    public double myMmax = 0;
164

    
165
    // notify about warnings.
166
    private boolean myWarning = true;
167

    
168
    /**
169
     * ShapeFileHeader constructor comment.
170
     */
171
    public ShapeFileHeader() {
172
        super();
173
    }
174

    
175
    /**
176
     * Return the file code.
177
     *
178
     * @return Entero.
179
     */
180
    public int getFileCode() {
181
        return myFileCode;
182
    }
183

    
184
    /**
185
     * Return the version of the file.
186
     *
187
     * @return Versi?n.
188
     */
189
    public int getVersion() {
190
        return myVersion;
191
    }
192

    
193
    /**
194
     * Get the extents of the shape file.
195
     *
196
     * @return FullExtent.
197
     */
198
    public java.awt.geom.Rectangle2D.Double getFileExtents() {
199
        return new java.awt.geom.Rectangle2D.Double(myXmin, myYmin,
200
            myXmax - myXmin, myYmax - myYmin);
201
    }
202

    
203
    /**
204
     * Print warnings to system.out.
205
     *
206
     * @param inWarning boolean.
207
     */
208
    public void setWarnings(boolean inWarning) {
209
        myWarning = inWarning;
210
    }
211

    
212
    /**
213
     * Return the length of the header in 16 bit words..
214
     *
215
     * @return Longitud de la cabecera.
216
     */
217
    public int getHeaderLength() {
218
        return 50;
219
    }
220

    
221
    /**
222
     * Return the number of 16 bit words in the shape file as recorded in the
223
     * header
224
     *
225
     * @return Longitud del fichero.
226
     */
227
    public int getFileLength() {
228
        return myFileLength;
229
    }
230

    
231
    /**
232
     * Read the header from the shape file.
233
     *
234
     * @param in ByteBuffer.
235
     */
236
    public void readHeader(FalseByteBuffer in) {
237
        // the first four bytes are integers
238
        // in.setLittleEndianMode(false);
239
        in.setByteOrder(ByteOrder.BIG_ENDIAN);
240
        myFileCode = in.getInt();
241

    
242
        if (myFileCode != 9994) {
243
            warn("File Code = " + myFileCode + " Not equal to 9994");
244
        }
245

    
246
        // From 4 to 8 are unused.
247
        myUnused1 = in.getInt();
248

    
249
        // From 8 to 12 are unused.
250
        myUnused2 = in.getInt();
251

    
252
        // From 12 to 16 are unused.
253
        myUnused3 = in.getInt();
254

    
255
        // From 16 to 20 are unused.
256
        myUnused4 = in.getInt();
257

    
258
        // From 20 to 24 are unused.
259
        myUnused5 = in.getInt();
260

    
261
        // From 24 to 28 are the file length.
262
        myFileLength = in.getInt();
263

    
264
        // From 28 to 32 are the File Version.
265
        in.setByteOrder(ByteOrder.LITTLE_ENDIAN);
266
        myVersion = in.getInt();
267

    
268
        // From 32 to 36 are the Shape Type.
269
        myShapeType = in.getInt();
270

    
271
        // From 36 to 44 are Xmin.
272
        myXmin = in.getDouble(); // Double.longBitsToDouble(in.getLong());
273

    
274
        // From 44 to 52 are Ymin.
275
        myYmin = in.getDouble();
276

    
277
        // From 52 to 60 are Xmax.
278
        myXmax = in.getDouble();
279

    
280
        // From 60 to 68 are Ymax.
281
        myYmax = in.getDouble();
282

    
283
        // From 68 to 76 are Zmin.
284
        myZmin = in.getDouble();
285

    
286
        // From 76 to 84 are Zmax.
287
        myZmax = in.getDouble();
288

    
289
        // From 84 to 92 are Mmin.
290
        myMmin = in.getDouble();
291

    
292
        // From 92 to 100 are Mmax.
293
        myMmax = in.getDouble();
294

    
295
        // that is all 100 bytes of the header.
296
    }
297
    public void write(IByteBuffer out,int type,
298
                    int numGeoms,int length,double minX,double minY,double maxX,double maxY,double minZ,double maxZ,double minM,double maxM)
299
                    throws IOException {
300
                      out.order(ByteOrder.BIG_ENDIAN);
301
                      
302
                      out.putInt(myFileCode);
303
                      
304
                      for (int i = 0; i < 5; i++) {
305
                        out.putInt(0); //Skip unused part of header
306
                      }
307

    
308
                      out.putInt(length);
309
                      
310
                      out.order(ByteOrder.LITTLE_ENDIAN);
311
                      
312
                      out.putInt(myVersion);
313
                      out.putInt(type);
314
                      
315
                      //write the bounding box
316
                      out.putDouble(minX);
317
                      out.putDouble(minY);
318
                      out.putDouble(maxX);
319
                      out.putDouble(maxY);
320
                      /*
321
                      out.putDouble(minZ);
322
                      out.putDouble(minZ);
323
                      out.putDouble(maxM);
324
                      out.putDouble(maxM);*/
325
                      out.order(ByteOrder.BIG_ENDIAN);
326
                      for (int i = 0; i < 8; i++) {
327
                        out.putInt(0); //Skip unused part of header
328
                      }
329
                     
330
                    }
331

    
332
    /**
333
     * Muestra por consola los warning.
334
     *
335
     * @param inWarn warning.
336
     */
337
    private void warn(String inWarn) {
338
        if (myWarning) {
339
            logger.warn(inWarn);
340
        }
341
    }
342
}