Statistics
| Revision:

svn-gvsig-desktop / tags / Root_CqCMSDvp / libraries / libCq CMS for java.old / src / org / cresques / io / ShpFileHeader.java @ 1732

History | View | Annotate | Download (5.33 KB)

1
/*
2
 * Created on 14-may-2004
3
 *
4
 * @author "Luis W. Sevilla" <sevilla_lui@gva.es>
5
 */
6
package org.cresques.io;
7

    
8

    
9
/*
10
 *    GISToolkit - Geographical Information System Toolkit
11
 *    (C) 2002, Ithaqua Enterprises Inc.
12
 *
13
 *    This library is free software; you can redistribute it and/or
14
 *    modify it under the terms of the GNU Lesser General Public
15
 *    License as published by the Free Software Foundation;
16
 *    version 2.1 of the License.
17
 *
18
 *    This library is distributed in the hope that it will be useful,
19
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
20
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21
 *    Lesser General Public License for more details.
22
 *
23
 *    You should have received a copy of the GNU Lesser General Public
24
 *    License along with this library; if not, write to the Free Software
25
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26
 *
27
 */
28
import java.nio.*;
29

    
30
/**
31
 * Procesa la cabecera de un .shp
32
 * 
33
 * @author "Luis W. Sevilla" <sevilla_lui@gva.es>* @author administrador
34
 */
35
public class ShpFileHeader {
36

    
37
//}
38
/**
39
 * Class to represent the header in the shape file.
40
 */
41
//public class ShapeFileHeader {
42
        /**
43
         * Shape Type
44
         * Value Shape Type
45
         * 0 Null Shape
46
         * 1 Point
47
         * 3 PolyLine
48
         * 5 Polygon
49
         * 8 MultiPoint
50
         * 11 PointZ
51
         * 13 PolyLineZ
52
         * 15 PolygonZ
53
         * 18 MultiPointZ
54
         * 21 PointM
55
         * 23 PolyLineM
56
         * 25 PolygonM
57
         * 28 MultiPointM
58
         * 31 MultiPatch
59
         */
60

    
61
        /* The null shape type, there is no shape for this record. */
62
        public static final int SHAPE_NULL = 0;
63
        public static final int SHAPE_POINT = 1;
64
        public static final int SHAPE_POLYLINE = 3;
65
        public static final int SHAPE_POLYGON = 5;
66
        public static final int SHAPE_MULTIPOINT = 8;
67
        public static final int SHAPE_POINTZ = 11;
68
        public static final int SHAPE_POLYLINEZ = 13;
69
        public static final int SHAPE_POLYGONZ = 15;
70
        public static final int SHAPE_MULTIPOINTZ = 18;
71
        public static final int SHAPE_POINTM = 21;
72
        public static final int SHAPE_POLYLINEM = 23;
73
        public static final int SHAPE_POLYGONM = 25;
74
        public static final int SHAPE_MULTIPOINTM = 28;
75
        public static final int SHAPE_MULTIPATCH = 31;
76

    
77
        /**File Code, must be the value 9994*/
78
        int myFileCode = 9994;
79

    
80
        /**
81
         * Unused 1;
82
         */
83
        int myUnused1 = 0;
84

    
85
        /**
86
         * Unused 2;
87
         */
88
        int myUnused2 = 0;
89

    
90
        /**
91
         * Unused 3;
92
         */
93
        int myUnused3 = 0;
94

    
95
        /**
96
         * Unused 4;
97
         */
98
        int myUnused4 = 0;
99

    
100
        /**
101
         * Unused 5;
102
         */
103
        int myUnused5 = 0;
104

    
105
        /**File Length;*/
106
        int myFileLength = 0;
107

    
108
        /**Version of the file.*/
109
        int myVersion = 1000;
110
        int myShapeType = 0;
111

    
112
        /**
113
         * BoundingBox Xmin
114
         */
115
        double myXmin = 0;
116

    
117
        /**
118
         * BoundingBox Ymin
119
         */
120
        double myYmin = 0;
121

    
122
        /**
123
         * BoundingBox Xmax
124
         */
125
        double myXmax = 0;
126

    
127
        /**
128
         * BoundingBox Ymax
129
         */
130
        double myYmax = 0;
131

    
132
        /**
133
         * BoundingBox Zmin
134
         */
135
        double myZmin = 0;
136

    
137
        /**
138
         * BoundingBox Zmax
139
         */
140
        double myZmax = 0;
141

    
142
        /**
143
         * BoundingBox Zmin
144
         */
145
        double myMmin = 0;
146

    
147
        /**
148
         * BoundingBox Zmax
149
         */
150
        double myMmax = 0;
151

    
152
        // notify about warnings.
153
        private boolean myWarning = true;
154

    
155
        /**
156
         * ShapeFileHeader constructor comment.
157
         */
158
        public ShpFileHeader() {
159
                super();
160
        }
161

    
162
        /** Return the file code. */
163
        public int getFileCode() {
164
                return myFileCode;
165
        }
166

    
167
        /** Return the version of the file. */
168
        public int getVersion() {
169
                return myVersion;
170
        }
171

    
172
        /** Get the extents of the shape file. */
173
        public java.awt.geom.Rectangle2D.Double getFileExtents() {
174
                return new java.awt.geom.Rectangle2D.Double(myXmin, myYmin,
175
                        myXmax - myXmin, myYmax - myYmin);
176
        }
177

    
178
        /** Print warnings to system.out. */
179
        public void setWarnings(boolean inWarning) {
180
                myWarning = inWarning;
181
        }
182

    
183
        /**
184
         * Return the length of the header in 16 bit words..
185
         */
186
        public int getHeaderLength() {
187
                return 50;
188
        }
189

    
190
        /**
191
         * Return the number of 16 bit words in the shape file as recorded in the header
192
         */
193
        public int getFileLength() {
194
                return myFileLength;
195
        }
196

    
197
        /**
198
         * Read the header from the shape file.
199
         */
200
        public void readHeader(ByteBuffer in) {
201
                // the first four bytes are integers
202
                // in.setLittleEndianMode(false);
203
                in.order(ByteOrder.BIG_ENDIAN);
204
                myFileCode = in.getInt();
205

    
206
                if (myFileCode != 9994) {
207
                        warn("File Code = " + myFileCode + " Not equal to 9994");
208
                }
209

    
210
                // From 4 to 8 are unused.
211
                myUnused1 = in.getInt();
212

    
213
                // From 8 to 12 are unused.
214
                myUnused2 = in.getInt();
215

    
216
                // From 12 to 16 are unused.
217
                myUnused3 = in.getInt();
218

    
219
                // From 16 to 20 are unused.
220
                myUnused4 = in.getInt();
221

    
222
                // From 20 to 24 are unused.
223
                myUnused5 = in.getInt();
224

    
225
                // From 24 to 28 are the file length.
226
                myFileLength = in.getInt();
227

    
228
                // From 28 to 32 are the File Version.
229
                in.order(ByteOrder.LITTLE_ENDIAN);
230
                myVersion = in.getInt();
231

    
232
                // From 32 to 36 are the Shape Type.
233
                myShapeType = in.getInt();
234

    
235
                // From 36 to 44 are Xmin.
236
                myXmin = in.getDouble(); // Double.longBitsToDouble(in.getLong());
237

    
238
                // From 44 to 52 are Ymin.
239
                myYmin = in.getDouble();
240

    
241
                // From 52 to 60 are Xmax.
242
                myXmax = in.getDouble();
243

    
244
                // From 60 to 68 are Ymax.
245
                myYmax = in.getDouble();
246

    
247
                // From 68 to 76 are Zmin.
248
                myZmin = in.getDouble();
249

    
250
                // From 76 to 84 are Zmax.
251
                myZmax = in.getDouble();
252

    
253
                // From 84 to 92 are Mmin.
254
                myMmin = in.getDouble();
255

    
256
                // From 92 to 100 are Mmax.
257
                myMmax = in.getDouble();
258

    
259
                // that is all 100 bytes of the header.
260
        }
261

    
262
        private void warn(String inWarn) {
263
                if (myWarning) {
264
                        System.out.print("WARNING: ");
265
                        System.out.println(inWarn);
266
                }
267
        }
268
}