1 |
bh |
6 |
#ifndef _SHAPEFILE_H_INCLUDED |
2 |
|
|
#define _SHAPEFILE_H_INCLUDED |
3 |
|
|
|
4 |
|
|
/****************************************************************************** |
5 |
|
|
* $Id$ |
6 |
|
|
* |
7 |
|
|
* Project: Shapelib |
8 |
|
|
* Purpose: Primary include file for Shapelib. |
9 |
|
|
* Author: Frank Warmerdam, [email protected] |
10 |
|
|
* |
11 |
|
|
****************************************************************************** |
12 |
|
|
* Copyright (c) 1999, Frank Warmerdam |
13 |
|
|
* |
14 |
|
|
* This software is available under the following "MIT Style" license, |
15 |
|
|
* or at the option of the licensee under the LGPL (see LICENSE.LGPL). This |
16 |
|
|
* option is discussed in more detail in shapelib.html. |
17 |
|
|
* |
18 |
|
|
* -- |
19 |
|
|
* |
20 |
|
|
* Permission is hereby granted, free of charge, to any person obtaining a |
21 |
|
|
* copy of this software and associated documentation files (the "Software"), |
22 |
|
|
* to deal in the Software without restriction, including without limitation |
23 |
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense, |
24 |
|
|
* and/or sell copies of the Software, and to permit persons to whom the |
25 |
|
|
* Software is furnished to do so, subject to the following conditions: |
26 |
|
|
* |
27 |
|
|
* The above copyright notice and this permission notice shall be included |
28 |
|
|
* in all copies or substantial portions of the Software. |
29 |
|
|
* |
30 |
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
31 |
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
32 |
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
33 |
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
34 |
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
35 |
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
36 |
|
|
* DEALINGS IN THE SOFTWARE. |
37 |
|
|
****************************************************************************** |
38 |
|
|
* |
39 |
|
|
* $Log$ |
40 |
bh |
272 |
* Revision 1.4 2002/08/22 16:00:01 bh |
41 |
|
|
* * extensions/shapelib/shapefil.h (DBFCommit), |
42 |
|
|
* extensions/shapelib/dbfopen.c (DBFCommit): New API function to |
43 |
|
|
* commit any changes made to the DBF file. |
44 |
|
|
* |
45 |
bh |
140 |
* Revision 1.3 2002/05/07 14:09:45 bh |
46 |
|
|
* * extensions/shapelib/shpopen.c, extensions/shapelib/shapefil.h, |
47 |
|
|
* extensions/shapelib/dbfopen.c: Really update to the versions of |
48 |
|
|
* shapelib 1.2.9. For some reason it wasn't really done on |
49 |
|
|
* 2002-04-11. |
50 |
bh |
6 |
* |
51 |
bh |
140 |
* Revision 1.20 2001/07/20 13:06:02 warmerda |
52 |
|
|
* fixed SHPAPI attribute for SHPTreeFindLikelyShapes |
53 |
|
|
* |
54 |
|
|
* Revision 1.19 2001/05/31 19:20:13 warmerda |
55 |
|
|
* added DBFGetFieldIndex() |
56 |
|
|
* |
57 |
|
|
* Revision 1.18 2001/05/31 18:15:40 warmerda |
58 |
|
|
* Added support for NULL fields in DBF files |
59 |
|
|
* |
60 |
|
|
* Revision 1.17 2001/05/23 13:36:52 warmerda |
61 |
|
|
* added use of SHPAPI_CALL |
62 |
|
|
* |
63 |
|
|
* Revision 1.16 2000/09/25 14:15:59 warmerda |
64 |
|
|
* added DBFGetNativeFieldType() |
65 |
|
|
* |
66 |
bh |
6 |
* Revision 1.15 2000/02/16 16:03:51 warmerda |
67 |
|
|
* added null shape support |
68 |
|
|
* |
69 |
|
|
* Revision 1.14 1999/11/05 14:12:05 warmerda |
70 |
|
|
* updated license terms |
71 |
|
|
* |
72 |
|
|
* Revision 1.13 1999/06/02 18:24:21 warmerda |
73 |
|
|
* added trimming code |
74 |
|
|
* |
75 |
|
|
* Revision 1.12 1999/06/02 17:56:12 warmerda |
76 |
|
|
* added quad'' subnode support for trees |
77 |
|
|
* |
78 |
|
|
* Revision 1.11 1999/05/18 19:11:11 warmerda |
79 |
|
|
* Added example searching capability |
80 |
|
|
* |
81 |
|
|
* Revision 1.10 1999/05/18 17:49:38 warmerda |
82 |
|
|
* added initial quadtree support |
83 |
|
|
* |
84 |
|
|
* Revision 1.9 1999/05/11 03:19:28 warmerda |
85 |
|
|
* added new Tuple api, and improved extension handling - add from candrsn |
86 |
|
|
* |
87 |
|
|
* Revision 1.8 1999/03/23 17:22:27 warmerda |
88 |
|
|
* Added extern "C" protection for C++ users of shapefil.h. |
89 |
|
|
* |
90 |
|
|
* Revision 1.7 1998/12/31 15:31:07 warmerda |
91 |
|
|
* Added the TRIM_DBF_WHITESPACE and DISABLE_MULTIPATCH_MEASURE options. |
92 |
|
|
* |
93 |
|
|
* Revision 1.6 1998/12/03 15:48:15 warmerda |
94 |
|
|
* Added SHPCalculateExtents(). |
95 |
|
|
* |
96 |
|
|
* Revision 1.5 1998/11/09 20:57:16 warmerda |
97 |
|
|
* Altered SHPGetInfo() call. |
98 |
|
|
* |
99 |
|
|
* Revision 1.4 1998/11/09 20:19:33 warmerda |
100 |
|
|
* Added 3D support, and use of SHPObject. |
101 |
|
|
* |
102 |
|
|
* Revision 1.3 1995/08/23 02:24:05 warmerda |
103 |
|
|
* Added support for reading bounds. |
104 |
|
|
* |
105 |
|
|
* Revision 1.2 1995/08/04 03:17:39 warmerda |
106 |
|
|
* Added header. |
107 |
|
|
* |
108 |
|
|
*/ |
109 |
|
|
|
110 |
|
|
#include <stdio.h> |
111 |
|
|
|
112 |
|
|
#ifdef USE_DBMALLOC |
113 |
|
|
#include <dbmalloc.h> |
114 |
|
|
#endif |
115 |
|
|
|
116 |
|
|
#ifdef __cplusplus |
117 |
|
|
extern "C" { |
118 |
|
|
#endif |
119 |
bh |
140 |
|
120 |
|
|
#ifndef SHPAPI_CALL |
121 |
|
|
#define SHPAPI_CALL |
122 |
|
|
#endif |
123 |
|
|
|
124 |
|
|
#define SHPAPI_CALL1(x) * SHPAPI_CALL |
125 |
bh |
6 |
|
126 |
|
|
/************************************************************************/ |
127 |
|
|
/* Configuration options. */ |
128 |
|
|
/************************************************************************/ |
129 |
|
|
|
130 |
|
|
/* -------------------------------------------------------------------- */ |
131 |
|
|
/* Should the DBFReadStringAttribute() strip leading and */ |
132 |
|
|
/* trailing white space? */ |
133 |
|
|
/* -------------------------------------------------------------------- */ |
134 |
|
|
#define TRIM_DBF_WHITESPACE |
135 |
|
|
|
136 |
|
|
/* -------------------------------------------------------------------- */ |
137 |
|
|
/* Should we write measure values to the Multipatch object? */ |
138 |
|
|
/* Reportedly ArcView crashes if we do write it, so for now it */ |
139 |
|
|
/* is disabled. */ |
140 |
|
|
/* -------------------------------------------------------------------- */ |
141 |
|
|
#define DISABLE_MULTIPATCH_MEASURE |
142 |
|
|
|
143 |
|
|
/************************************************************************/ |
144 |
|
|
/* SHP Support. */ |
145 |
|
|
/************************************************************************/ |
146 |
|
|
typedef struct |
147 |
|
|
{ |
148 |
|
|
FILE *fpSHP; |
149 |
|
|
FILE *fpSHX; |
150 |
|
|
|
151 |
|
|
int nShapeType; /* SHPT_* */ |
152 |
|
|
|
153 |
|
|
int nFileSize; /* SHP file */ |
154 |
|
|
|
155 |
|
|
int nRecords; |
156 |
|
|
int nMaxRecords; |
157 |
|
|
int *panRecOffset; |
158 |
|
|
int *panRecSize; |
159 |
|
|
|
160 |
|
|
double adBoundsMin[4]; |
161 |
|
|
double adBoundsMax[4]; |
162 |
|
|
|
163 |
|
|
int bUpdated; |
164 |
|
|
} SHPInfo; |
165 |
|
|
|
166 |
|
|
typedef SHPInfo * SHPHandle; |
167 |
|
|
|
168 |
|
|
/* -------------------------------------------------------------------- */ |
169 |
|
|
/* Shape types (nSHPType) */ |
170 |
|
|
/* -------------------------------------------------------------------- */ |
171 |
|
|
#define SHPT_NULL 0 |
172 |
|
|
#define SHPT_POINT 1 |
173 |
|
|
#define SHPT_ARC 3 |
174 |
|
|
#define SHPT_POLYGON 5 |
175 |
|
|
#define SHPT_MULTIPOINT 8 |
176 |
|
|
#define SHPT_POINTZ 11 |
177 |
|
|
#define SHPT_ARCZ 13 |
178 |
|
|
#define SHPT_POLYGONZ 15 |
179 |
|
|
#define SHPT_MULTIPOINTZ 18 |
180 |
|
|
#define SHPT_POINTM 21 |
181 |
|
|
#define SHPT_ARCM 23 |
182 |
|
|
#define SHPT_POLYGONM 25 |
183 |
|
|
#define SHPT_MULTIPOINTM 28 |
184 |
|
|
#define SHPT_MULTIPATCH 31 |
185 |
|
|
|
186 |
|
|
|
187 |
|
|
/* -------------------------------------------------------------------- */ |
188 |
|
|
/* Part types - everything but SHPT_MULTIPATCH just uses */ |
189 |
|
|
/* SHPP_RING. */ |
190 |
|
|
/* -------------------------------------------------------------------- */ |
191 |
|
|
|
192 |
|
|
#define SHPP_TRISTRIP 0 |
193 |
|
|
#define SHPP_TRIFAN 1 |
194 |
|
|
#define SHPP_OUTERRING 2 |
195 |
|
|
#define SHPP_INNERRING 3 |
196 |
|
|
#define SHPP_FIRSTRING 4 |
197 |
|
|
#define SHPP_RING 5 |
198 |
|
|
|
199 |
|
|
/* -------------------------------------------------------------------- */ |
200 |
|
|
/* SHPObject - represents on shape (without attributes) read */ |
201 |
|
|
/* from the .shp file. */ |
202 |
|
|
/* -------------------------------------------------------------------- */ |
203 |
|
|
typedef struct |
204 |
|
|
{ |
205 |
|
|
int nSHPType; |
206 |
|
|
|
207 |
|
|
int nShapeId; /* -1 is unknown/unassigned */ |
208 |
|
|
|
209 |
|
|
int nParts; |
210 |
|
|
int *panPartStart; |
211 |
|
|
int *panPartType; |
212 |
|
|
|
213 |
|
|
int nVertices; |
214 |
|
|
double *padfX; |
215 |
|
|
double *padfY; |
216 |
|
|
double *padfZ; |
217 |
|
|
double *padfM; |
218 |
|
|
|
219 |
|
|
double dfXMin; |
220 |
|
|
double dfYMin; |
221 |
|
|
double dfZMin; |
222 |
|
|
double dfMMin; |
223 |
|
|
|
224 |
|
|
double dfXMax; |
225 |
|
|
double dfYMax; |
226 |
|
|
double dfZMax; |
227 |
|
|
double dfMMax; |
228 |
|
|
} SHPObject; |
229 |
|
|
|
230 |
|
|
/* -------------------------------------------------------------------- */ |
231 |
|
|
/* SHP API Prototypes */ |
232 |
|
|
/* -------------------------------------------------------------------- */ |
233 |
bh |
140 |
SHPHandle SHPAPI_CALL |
234 |
|
|
SHPOpen( const char * pszShapeFile, const char * pszAccess ); |
235 |
|
|
SHPHandle SHPAPI_CALL |
236 |
|
|
SHPCreate( const char * pszShapeFile, int nShapeType ); |
237 |
|
|
void SHPAPI_CALL |
238 |
|
|
SHPGetInfo( SHPHandle hSHP, int * pnEntities, int * pnShapeType, |
239 |
|
|
double * padfMinBound, double * padfMaxBound ); |
240 |
bh |
6 |
|
241 |
bh |
140 |
SHPObject SHPAPI_CALL1(*) |
242 |
|
|
SHPReadObject( SHPHandle hSHP, int iShape ); |
243 |
|
|
int SHPAPI_CALL |
244 |
|
|
SHPWriteObject( SHPHandle hSHP, int iShape, SHPObject * psObject ); |
245 |
bh |
6 |
|
246 |
bh |
140 |
void SHPAPI_CALL |
247 |
|
|
SHPDestroyObject( SHPObject * psObject ); |
248 |
|
|
void SHPAPI_CALL |
249 |
|
|
SHPComputeExtents( SHPObject * psObject ); |
250 |
|
|
SHPObject SHPAPI_CALL1(*) |
251 |
|
|
SHPCreateObject( int nSHPType, int nShapeId, |
252 |
|
|
int nParts, int * panPartStart, int * panPartType, |
253 |
|
|
int nVertices, double * padfX, double * padfY, |
254 |
|
|
double * padfZ, double * padfM ); |
255 |
|
|
SHPObject SHPAPI_CALL1(*) |
256 |
|
|
SHPCreateSimpleObject( int nSHPType, int nVertices, |
257 |
|
|
double * padfX, double * padfY, double * padfZ ); |
258 |
bh |
6 |
|
259 |
bh |
140 |
void SHPAPI_CALL |
260 |
|
|
SHPClose( SHPHandle hSHP ); |
261 |
bh |
6 |
|
262 |
bh |
140 |
const char SHPAPI_CALL1(*) |
263 |
|
|
SHPTypeName( int nSHPType ); |
264 |
|
|
const char SHPAPI_CALL1(*) |
265 |
|
|
SHPPartTypeName( int nPartType ); |
266 |
bh |
6 |
|
267 |
|
|
/* -------------------------------------------------------------------- */ |
268 |
|
|
/* Shape quadtree indexing API. */ |
269 |
|
|
/* -------------------------------------------------------------------- */ |
270 |
|
|
|
271 |
|
|
/* this can be two or four for binary or quad tree */ |
272 |
|
|
#define MAX_SUBNODE 4 |
273 |
|
|
|
274 |
|
|
typedef struct shape_tree_node |
275 |
|
|
{ |
276 |
|
|
/* region covered by this node */ |
277 |
|
|
double adfBoundsMin[4]; |
278 |
|
|
double adfBoundsMax[4]; |
279 |
|
|
|
280 |
|
|
/* list of shapes stored at this node. The papsShapeObj pointers |
281 |
|
|
or the whole list can be NULL */ |
282 |
|
|
int nShapeCount; |
283 |
|
|
int *panShapeIds; |
284 |
|
|
SHPObject **papsShapeObj; |
285 |
|
|
|
286 |
|
|
int nSubNodes; |
287 |
|
|
struct shape_tree_node *apsSubNode[MAX_SUBNODE]; |
288 |
|
|
|
289 |
|
|
} SHPTreeNode; |
290 |
|
|
|
291 |
|
|
typedef struct |
292 |
|
|
{ |
293 |
|
|
SHPHandle hSHP; |
294 |
|
|
|
295 |
|
|
int nMaxDepth; |
296 |
|
|
int nDimension; |
297 |
|
|
|
298 |
|
|
SHPTreeNode *psRoot; |
299 |
|
|
} SHPTree; |
300 |
|
|
|
301 |
bh |
140 |
SHPTree SHPAPI_CALL1(*) |
302 |
|
|
SHPCreateTree( SHPHandle hSHP, int nDimension, int nMaxDepth, |
303 |
|
|
double *padfBoundsMin, double *padfBoundsMax ); |
304 |
|
|
void SHPAPI_CALL |
305 |
|
|
SHPDestroyTree( SHPTree * hTree ); |
306 |
bh |
6 |
|
307 |
bh |
140 |
int SHPAPI_CALL |
308 |
|
|
SHPWriteTree( SHPTree *hTree, const char * pszFilename ); |
309 |
|
|
SHPTree SHPAPI_CALL |
310 |
|
|
SHPReadTree( const char * pszFilename ); |
311 |
bh |
6 |
|
312 |
bh |
140 |
int SHPAPI_CALL |
313 |
|
|
SHPTreeAddObject( SHPTree * hTree, SHPObject * psObject ); |
314 |
|
|
int SHPAPI_CALL |
315 |
|
|
SHPTreeAddShapeId( SHPTree * hTree, SHPObject * psObject ); |
316 |
|
|
int SHPAPI_CALL |
317 |
|
|
SHPTreeRemoveShapeId( SHPTree * hTree, int nShapeId ); |
318 |
bh |
6 |
|
319 |
bh |
140 |
void SHPAPI_CALL |
320 |
|
|
SHPTreeTrimExtraNodes( SHPTree * hTree ); |
321 |
bh |
6 |
|
322 |
bh |
140 |
int SHPAPI_CALL1(*) |
323 |
|
|
SHPTreeFindLikelyShapes( SHPTree * hTree, |
324 |
|
|
double * padfBoundsMin, |
325 |
|
|
double * padfBoundsMax, |
326 |
|
|
int * ); |
327 |
|
|
int SHPAPI_CALL |
328 |
|
|
SHPCheckBoundsOverlap( double *, double *, double *, double *, int ); |
329 |
bh |
6 |
|
330 |
|
|
/************************************************************************/ |
331 |
|
|
/* DBF Support. */ |
332 |
|
|
/************************************************************************/ |
333 |
|
|
typedef struct |
334 |
|
|
{ |
335 |
|
|
FILE *fp; |
336 |
|
|
|
337 |
|
|
int nRecords; |
338 |
|
|
|
339 |
|
|
int nRecordLength; |
340 |
|
|
int nHeaderLength; |
341 |
|
|
int nFields; |
342 |
|
|
int *panFieldOffset; |
343 |
|
|
int *panFieldSize; |
344 |
|
|
int *panFieldDecimals; |
345 |
|
|
char *pachFieldType; |
346 |
|
|
|
347 |
|
|
char *pszHeader; |
348 |
|
|
|
349 |
|
|
int nCurrentRecord; |
350 |
|
|
int bCurrentRecordModified; |
351 |
|
|
char *pszCurrentRecord; |
352 |
|
|
|
353 |
|
|
int bNoHeader; |
354 |
|
|
int bUpdated; |
355 |
|
|
} DBFInfo; |
356 |
|
|
|
357 |
|
|
typedef DBFInfo * DBFHandle; |
358 |
|
|
|
359 |
|
|
typedef enum { |
360 |
|
|
FTString, |
361 |
|
|
FTInteger, |
362 |
|
|
FTDouble, |
363 |
|
|
FTInvalid |
364 |
|
|
} DBFFieldType; |
365 |
|
|
|
366 |
|
|
#define XBASE_FLDHDR_SZ 32 |
367 |
|
|
|
368 |
bh |
140 |
DBFHandle SHPAPI_CALL |
369 |
|
|
DBFOpen( const char * pszDBFFile, const char * pszAccess ); |
370 |
|
|
DBFHandle SHPAPI_CALL |
371 |
|
|
DBFCreate( const char * pszDBFFile ); |
372 |
bh |
6 |
|
373 |
bh |
140 |
int SHPAPI_CALL |
374 |
|
|
DBFGetFieldCount( DBFHandle psDBF ); |
375 |
|
|
int SHPAPI_CALL |
376 |
|
|
DBFGetRecordCount( DBFHandle psDBF ); |
377 |
|
|
int SHPAPI_CALL |
378 |
|
|
DBFAddField( DBFHandle hDBF, const char * pszFieldName, |
379 |
|
|
DBFFieldType eType, int nWidth, int nDecimals ); |
380 |
bh |
6 |
|
381 |
bh |
140 |
DBFFieldType SHPAPI_CALL |
382 |
|
|
DBFGetFieldInfo( DBFHandle psDBF, int iField, |
383 |
|
|
char * pszFieldName, int * pnWidth, int * pnDecimals ); |
384 |
bh |
6 |
|
385 |
bh |
140 |
int SHPAPI_CALL |
386 |
|
|
DBFGetFieldIndex(DBFHandle psDBF, const char *pszFieldName); |
387 |
bh |
6 |
|
388 |
bh |
140 |
int SHPAPI_CALL |
389 |
|
|
DBFReadIntegerAttribute( DBFHandle hDBF, int iShape, int iField ); |
390 |
|
|
double SHPAPI_CALL |
391 |
|
|
DBFReadDoubleAttribute( DBFHandle hDBF, int iShape, int iField ); |
392 |
|
|
const char SHPAPI_CALL1(*) |
393 |
|
|
DBFReadStringAttribute( DBFHandle hDBF, int iShape, int iField ); |
394 |
|
|
int SHPAPI_CALL |
395 |
|
|
DBFIsAttributeNULL( DBFHandle hDBF, int iShape, int iField ); |
396 |
bh |
6 |
|
397 |
bh |
140 |
int SHPAPI_CALL |
398 |
|
|
DBFWriteIntegerAttribute( DBFHandle hDBF, int iShape, int iField, |
399 |
|
|
int nFieldValue ); |
400 |
|
|
int SHPAPI_CALL |
401 |
|
|
DBFWriteDoubleAttribute( DBFHandle hDBF, int iShape, int iField, |
402 |
|
|
double dFieldValue ); |
403 |
|
|
int SHPAPI_CALL |
404 |
|
|
DBFWriteStringAttribute( DBFHandle hDBF, int iShape, int iField, |
405 |
|
|
const char * pszFieldValue ); |
406 |
|
|
int SHPAPI_CALL |
407 |
|
|
DBFWriteNULLAttribute( DBFHandle hDBF, int iShape, int iField ); |
408 |
bh |
6 |
|
409 |
bh |
140 |
const char SHPAPI_CALL1(*) |
410 |
|
|
DBFReadTuple(DBFHandle psDBF, int hEntity ); |
411 |
|
|
int SHPAPI_CALL |
412 |
|
|
DBFWriteTuple(DBFHandle psDBF, int hEntity, void * pRawTuple ); |
413 |
|
|
|
414 |
|
|
DBFHandle SHPAPI_CALL |
415 |
|
|
DBFCloneEmpty(DBFHandle psDBF, const char * pszFilename ); |
416 |
bh |
6 |
|
417 |
bh |
140 |
void SHPAPI_CALL |
418 |
|
|
DBFClose( DBFHandle hDBF ); |
419 |
|
|
char SHPAPI_CALL |
420 |
|
|
DBFGetNativeFieldType( DBFHandle hDBF, int iField ); |
421 |
bh |
6 |
|
422 |
bh |
272 |
int SHPAPI_CALL |
423 |
|
|
DBFCommit( DBFHandle hDBF ); |
424 |
|
|
|
425 |
bh |
6 |
#ifdef __cplusplus |
426 |
|
|
} |
427 |
|
|
#endif |
428 |
|
|
|
429 |
|
|
#endif /* ndef _SHAPEFILE_H_INCLUDED */ |