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