/[thuban]/branches/WIP-pyshapelib-bramz/libraries/shapelib/shapefil.h
ViewVC logotype

Contents of /branches/WIP-pyshapelib-bramz/libraries/shapelib/shapefil.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2752 - (show annotations)
Tue Apr 10 23:45:00 2007 UTC (17 years, 10 months ago) by bramz
File MIME type: text/plain
File size: 19644 byte(s)
attempt to add support for Unicode and Language Driver ID (LDID) support in dbflib
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 2004/05/17 15:47:57 bh
41 * Update to newest shapelib and get rid of Thuban specific extensions,
42 * i.e. use the new DBFUpdateHeader instead of our DBFCommit kludge
43 *
44 * * libraries/shapelib/shpopen.c: Update to version from current
45 * shapelib CVS.
46 *
47 * * libraries/shapelib/shapefil.h: Update to version from current
48 * shapelib CVS.
49 *
50 * * libraries/shapelib/dbfopen.c: Update to version from current
51 * shapelib CVS.
52 * (DBFCommit): Effectively removed since shapelib itself has
53 * DBFUpdateHeader now which is better for what DBFCommit wanted to
54 * achieve.
55 * We're now using an unmodified version of dbfopen.
56 *
57 * * libraries/pyshapelib/dbflib_wrap.c, libraries/pyshapelib/dbflib.py:
58 * Update from dbflib.i
59 *
60 * * libraries/pyshapelib/dbflib.i (DBFInfo_commit): New. Implementation of
61 * the commit method. This new indirection is necessary because we use the
62 * DBFUpdateHeader function now which is not available in shapelib <=
63 * 1.2.10
64 * (DBFFile::commit): Use DBFInfo_commit as implementation
65 * (pragma __class__): New. Kludge to remove the commit method when
66 * the DBFUpdateHeader function isn't available
67 * (_have_commit): New. Helper for the pragma kludge.
68 *
69 * * libraries/pyshapelib/setup.py (dbf_macros): New. Return the
70 * preprocessor macros needed to compile the dbflib wrapper. Determine
71 * whether DBFUpdateHeader is available and define the right value of
72 * HAVE_UPDATE_HEADER
73 * (extensions): Use dbf_macros for the dbflibc extension
74 *
75 * * setup.py (extensions): Add the HAVE_UPDATE_HEADER macro with
76 * value '1' to the Lib.dbflibc extension. This simply reflects the
77 * shapelib and pyshapelib updates
78 *
79 * Revision 1.28 2003/12/29 06:02:18 fwarmerdam
80 * added cpl_error.h option
81 *
82 * Revision 1.27 2003/04/21 18:30:37 warmerda
83 * added header write/update public methods
84 *
85 * Revision 1.26 2002/09/29 00:00:08 warmerda
86 * added FTLogical and logical attribute read/write calls
87 *
88 * Revision 1.25 2002/05/07 13:46:30 warmerda
89 * added DBFWriteAttributeDirectly().
90 *
91 * Revision 1.24 2002/04/10 16:59:54 warmerda
92 * added SHPRewindObject
93 *
94 * Revision 1.23 2002/01/15 14:36:07 warmerda
95 * updated email address
96 *
97 * Revision 1.22 2002/01/15 14:32:00 warmerda
98 * try to improve SHPAPI_CALL docs
99 *
100 * Revision 1.21 2001/11/01 16:29:55 warmerda
101 * move pabyRec into SHPInfo for thread safety
102 *
103 * Revision 1.20 2001/07/20 13:06:02 warmerda
104 * fixed SHPAPI attribute for SHPTreeFindLikelyShapes
105 *
106 * Revision 1.19 2001/05/31 19:20:13 warmerda
107 * added DBFGetFieldIndex()
108 *
109 * Revision 1.18 2001/05/31 18:15:40 warmerda
110 * Added support for NULL fields in DBF files
111 *
112 * Revision 1.17 2001/05/23 13:36:52 warmerda
113 * added use of SHPAPI_CALL
114 *
115 * Revision 1.16 2000/09/25 14:15:59 warmerda
116 * added DBFGetNativeFieldType()
117 *
118 * Revision 1.15 2000/02/16 16:03:51 warmerda
119 * added null shape support
120 *
121 * Revision 1.14 1999/11/05 14:12:05 warmerda
122 * updated license terms
123 *
124 * Revision 1.13 1999/06/02 18:24:21 warmerda
125 * added trimming code
126 *
127 * Revision 1.12 1999/06/02 17:56:12 warmerda
128 * added quad'' subnode support for trees
129 *
130 * Revision 1.11 1999/05/18 19:11:11 warmerda
131 * Added example searching capability
132 *
133 * Revision 1.10 1999/05/18 17:49:38 warmerda
134 * added initial quadtree support
135 *
136 * Revision 1.9 1999/05/11 03:19:28 warmerda
137 * added new Tuple api, and improved extension handling - add from candrsn
138 *
139 * Revision 1.8 1999/03/23 17:22:27 warmerda
140 * Added extern "C" protection for C++ users of shapefil.h.
141 *
142 * Revision 1.7 1998/12/31 15:31:07 warmerda
143 * Added the TRIM_DBF_WHITESPACE and DISABLE_MULTIPATCH_MEASURE options.
144 *
145 * Revision 1.6 1998/12/03 15:48:15 warmerda
146 * Added SHPCalculateExtents().
147 *
148 * Revision 1.5 1998/11/09 20:57:16 warmerda
149 * Altered SHPGetInfo() call.
150 *
151 * Revision 1.4 1998/11/09 20:19:33 warmerda
152 * Added 3D support, and use of SHPObject.
153 *
154 * Revision 1.3 1995/08/23 02:24:05 warmerda
155 * Added support for reading bounds.
156 *
157 * Revision 1.2 1995/08/04 03:17:39 warmerda
158 * Added header.
159 *
160 */
161
162 #include <stdio.h>
163
164 #ifdef USE_DBMALLOC
165 #include <dbmalloc.h>
166 #endif
167
168 #ifdef USE_CPL
169 #include "cpl_error.h"
170 #endif
171
172 #ifdef __cplusplus
173 extern "C" {
174 #endif
175
176 #if defined(_WIN32) || defined(_WIN64)
177 #define SHPAPI_HAS_WIDE
178 #endif
179
180 /************************************************************************/
181 /* Configuration options. */
182 /************************************************************************/
183
184 /* -------------------------------------------------------------------- */
185 /* Should the DBFReadStringAttribute() strip leading and */
186 /* trailing white space? */
187 /* -------------------------------------------------------------------- */
188 #define TRIM_DBF_WHITESPACE
189
190 /* -------------------------------------------------------------------- */
191 /* Should we write measure values to the Multipatch object? */
192 /* Reportedly ArcView crashes if we do write it, so for now it */
193 /* is disabled. */
194 /* -------------------------------------------------------------------- */
195 #define DISABLE_MULTIPATCH_MEASURE
196
197 /* -------------------------------------------------------------------- */
198 /* SHPAPI_CALL */
199 /* */
200 /* The following two macros are present to allow forcing */
201 /* various calling conventions on the Shapelib API. */
202 /* */
203 /* To force __stdcall conventions (needed to call Shapelib */
204 /* from Visual Basic and/or Dephi I believe) the makefile could */
205 /* be modified to define: */
206 /* */
207 /* /DSHPAPI_CALL=__stdcall */
208 /* */
209 /* If it is desired to force export of the Shapelib API without */
210 /* using the shapelib.def file, use the following definition. */
211 /* */
212 /* /DSHAPELIB_DLLEXPORT */
213 /* */
214 /* To get both at once it will be necessary to hack this */
215 /* include file to define: */
216 /* */
217 /* #define SHPAPI_CALL __declspec(dllexport) __stdcall */
218 /* #define SHPAPI_CALL1 __declspec(dllexport) * __stdcall */
219 /* */
220 /* The complexity of the situtation is partly caused by the */
221 /* peculiar requirement of Visual C++ that __stdcall appear */
222 /* after any "*"'s in the return value of a function while the */
223 /* __declspec(dllexport) must appear before them. */
224 /* -------------------------------------------------------------------- */
225
226 #ifdef SHAPELIB_DLLEXPORT
227 # define SHPAPI_CALL __declspec(dllexport)
228 # define SHPAPI_CALL1(x) __declspec(dllexport) x
229 #endif
230
231 #ifndef SHPAPI_CALL
232 # define SHPAPI_CALL
233 #endif
234
235 #ifndef SHPAPI_CALL1
236 # define SHPAPI_CALL1(x) x SHPAPI_CALL
237 #endif
238
239 /************************************************************************/
240 /* SHP Support. */
241 /************************************************************************/
242 typedef struct
243 {
244 FILE *fpSHP;
245 FILE *fpSHX;
246
247 int nShapeType; /* SHPT_* */
248
249 int nFileSize; /* SHP file */
250
251 int nRecords;
252 int nMaxRecords;
253 int *panRecOffset;
254 int *panRecSize;
255
256 double adBoundsMin[4];
257 double adBoundsMax[4];
258
259 int bUpdated;
260
261 unsigned char *pabyRec;
262 int nBufSize;
263 } SHPInfo;
264
265 typedef SHPInfo * SHPHandle;
266
267 /* -------------------------------------------------------------------- */
268 /* Shape types (nSHPType) */
269 /* -------------------------------------------------------------------- */
270 #define SHPT_NULL 0
271 #define SHPT_POINT 1
272 #define SHPT_ARC 3
273 #define SHPT_POLYGON 5
274 #define SHPT_MULTIPOINT 8
275 #define SHPT_POINTZ 11
276 #define SHPT_ARCZ 13
277 #define SHPT_POLYGONZ 15
278 #define SHPT_MULTIPOINTZ 18
279 #define SHPT_POINTM 21
280 #define SHPT_ARCM 23
281 #define SHPT_POLYGONM 25
282 #define SHPT_MULTIPOINTM 28
283 #define SHPT_MULTIPATCH 31
284
285
286 /* -------------------------------------------------------------------- */
287 /* Part types - everything but SHPT_MULTIPATCH just uses */
288 /* SHPP_RING. */
289 /* -------------------------------------------------------------------- */
290
291 #define SHPP_TRISTRIP 0
292 #define SHPP_TRIFAN 1
293 #define SHPP_OUTERRING 2
294 #define SHPP_INNERRING 3
295 #define SHPP_FIRSTRING 4
296 #define SHPP_RING 5
297
298 /* -------------------------------------------------------------------- */
299 /* SHPObject - represents on shape (without attributes) read */
300 /* from the .shp file. */
301 /* -------------------------------------------------------------------- */
302 typedef struct
303 {
304 int nSHPType;
305
306 int nShapeId; /* -1 is unknown/unassigned */
307
308 int nParts;
309 int *panPartStart;
310 int *panPartType;
311
312 int nVertices;
313 double *padfX;
314 double *padfY;
315 double *padfZ;
316 double *padfM;
317
318 double dfXMin;
319 double dfYMin;
320 double dfZMin;
321 double dfMMin;
322
323 double dfXMax;
324 double dfYMax;
325 double dfZMax;
326 double dfMMax;
327 } SHPObject;
328
329 /* -------------------------------------------------------------------- */
330 /* SHP API Prototypes */
331 /* -------------------------------------------------------------------- */
332 SHPHandle SHPAPI_CALL
333 SHPOpen( const char * pszShapeFile, const char * pszAccess );
334 SHPHandle SHPAPI_CALL
335 SHPCreate( const char * pszShapeFile, int nShapeType );
336 #ifdef SHPAPI_HAS_WIDE
337 SHPHandle SHPAPI_CALL
338 SHPOpenW( const wchar_t * pszShapeFile, const wchar_t * pszAccess );
339 SHPHandle SHPAPI_CALL
340 SHPCreateW( const wchar_t * pszShapeFile, int nShapeType );
341 #endif
342 SHPHandle SHPAPI_CALL
343 SHPOpenEx( FILE * pfSHP, FILE * pfSHX );
344 void SHPAPI_CALL
345 SHPCreateEx( FILE * pfSHP, FILE * pfSHX, int nShapeType );
346
347 void SHPAPI_CALL
348 SHPGetInfo( SHPHandle hSHP, int * pnEntities, int * pnShapeType,
349 double * padfMinBound, double * padfMaxBound );
350
351 SHPObject SHPAPI_CALL1(*)
352 SHPReadObject( SHPHandle hSHP, int iShape );
353 int SHPAPI_CALL
354 SHPWriteObject( SHPHandle hSHP, int iShape, SHPObject * psObject );
355
356 void SHPAPI_CALL
357 SHPDestroyObject( SHPObject * psObject );
358 void SHPAPI_CALL
359 SHPComputeExtents( SHPObject * psObject );
360 SHPObject SHPAPI_CALL1(*)
361 SHPCreateObject( int nSHPType, int nShapeId,
362 int nParts, int * panPartStart, int * panPartType,
363 int nVertices, double * padfX, double * padfY,
364 double * padfZ, double * padfM );
365 SHPObject SHPAPI_CALL1(*)
366 SHPCreateSimpleObject( int nSHPType, int nVertices,
367 double * padfX, double * padfY, double * padfZ );
368
369 int SHPAPI_CALL
370 SHPRewindObject( SHPHandle hSHP, SHPObject * psObject );
371
372 void SHPAPI_CALL SHPClose( SHPHandle hSHP );
373 void SHPAPI_CALL SHPWriteHeader( SHPHandle hSHP );
374
375 const char SHPAPI_CALL1(*)
376 SHPTypeName( int nSHPType );
377 const char SHPAPI_CALL1(*)
378 SHPPartTypeName( int nPartType );
379
380 /* -------------------------------------------------------------------- */
381 /* Shape quadtree indexing API. */
382 /* -------------------------------------------------------------------- */
383
384 /* this can be two or four for binary or quad tree */
385 #define MAX_SUBNODE 4
386
387 typedef struct shape_tree_node
388 {
389 /* region covered by this node */
390 double adfBoundsMin[4];
391 double adfBoundsMax[4];
392
393 /* list of shapes stored at this node. The papsShapeObj pointers
394 or the whole list can be NULL */
395 int nShapeCount;
396 int *panShapeIds;
397 SHPObject **papsShapeObj;
398
399 int nSubNodes;
400 struct shape_tree_node *apsSubNode[MAX_SUBNODE];
401
402 } SHPTreeNode;
403
404 typedef struct
405 {
406 SHPHandle hSHP;
407
408 int nMaxDepth;
409 int nDimension;
410
411 SHPTreeNode *psRoot;
412 } SHPTree;
413
414 SHPTree SHPAPI_CALL1(*)
415 SHPCreateTree( SHPHandle hSHP, int nDimension, int nMaxDepth,
416 double *padfBoundsMin, double *padfBoundsMax );
417 void SHPAPI_CALL
418 SHPDestroyTree( SHPTree * hTree );
419
420 int SHPAPI_CALL
421 SHPWriteTree( SHPTree *hTree, const char * pszFilename );
422 SHPTree SHPAPI_CALL
423 SHPReadTree( const char * pszFilename );
424 #ifdef SHPAPI_HAS_WIDE
425 int SHPAPI_CALL
426 SHPWriteTreeW( SHPTree *hTree, const wchar_t * pszFilename );
427 SHPTree SHPAPI_CALL
428 SHPReadTreeW( const wchar_t * pszFilename );
429 #endif
430
431 int SHPAPI_CALL
432 SHPTreeAddObject( SHPTree * hTree, SHPObject * psObject );
433 int SHPAPI_CALL
434 SHPTreeAddShapeId( SHPTree * hTree, SHPObject * psObject );
435 int SHPAPI_CALL
436 SHPTreeRemoveShapeId( SHPTree * hTree, int nShapeId );
437
438 void SHPAPI_CALL
439 SHPTreeTrimExtraNodes( SHPTree * hTree );
440
441 int SHPAPI_CALL1(*)
442 SHPTreeFindLikelyShapes( SHPTree * hTree,
443 double * padfBoundsMin,
444 double * padfBoundsMax,
445 int * );
446 int SHPAPI_CALL
447 SHPCheckBoundsOverlap( double *, double *, double *, double *, int );
448
449 /************************************************************************/
450 /* DBF Support. */
451 /************************************************************************/
452 typedef struct
453 {
454 FILE *fp;
455
456 int nRecords;
457
458 int nRecordLength;
459 int nHeaderLength;
460 int nFields;
461 int *panFieldOffset;
462 int *panFieldSize;
463 int *panFieldDecimals;
464 char *pachFieldType;
465
466 char *pszHeader;
467
468 int nCurrentRecord;
469 int bCurrentRecordModified;
470 char *pszCurrentRecord;
471
472 int bNoHeader;
473 int bUpdated;
474 int nLanguageDriver;
475 } DBFInfo;
476
477 typedef DBFInfo * DBFHandle;
478
479 typedef enum {
480 FTString,
481 FTInteger,
482 FTDouble,
483 FTLogical,
484 FTInvalid
485 } DBFFieldType;
486
487 #define XBASE_FLDHDR_SZ 32
488
489 /* to hand over a locale agnostic atof function, if decimal_point != ".\0" */
490 void SHPAPI_CALL
491 DBFSetatof_function( double (* new_atof_function)(const char *nptr));
492
493 DBFHandle SHPAPI_CALL
494 DBFOpen( const char * pszDBFFile, const char * pszAccess );
495 DBFHandle SHPAPI_CALL
496 DBFCreate( const char * pszDBFFile );
497 #ifdef SHPAPI_HAS_WIDE
498 DBFHandle SHPAPI_CALL
499 DBFOpenW( const wchar_t * pszDBFFile, const wchar_t * pszAccess );
500 DBFHandle SHPAPI_CALL
501 DBFCreateW( const wchar_t * pszDBFFile );
502 #endif
503 DBFHandle SHPAPI_CALL
504 DBFOpenEx( FILE* pf );
505 DBFHandle SHPAPI_CALL
506 DBFCreateEx( FILE* pf );
507
508 int SHPAPI_CALL
509 DBFGetFieldCount( DBFHandle psDBF );
510 int SHPAPI_CALL
511 DBFGetRecordCount( DBFHandle psDBF );
512 int SHPAPI_CALL
513 DBFAddField( DBFHandle hDBF, const char * pszFieldName,
514 DBFFieldType eType, int nWidth, int nDecimals );
515
516 DBFFieldType SHPAPI_CALL
517 DBFGetFieldInfo( DBFHandle psDBF, int iField,
518 char * pszFieldName, int * pnWidth, int * pnDecimals );
519
520 int SHPAPI_CALL
521 DBFGetFieldIndex(DBFHandle psDBF, const char *pszFieldName);
522
523 int SHPAPI_CALL
524 DBFReadIntegerAttribute( DBFHandle hDBF, int iShape, int iField );
525 double SHPAPI_CALL
526 DBFReadDoubleAttribute( DBFHandle hDBF, int iShape, int iField );
527 const char SHPAPI_CALL1(*)
528 DBFReadStringAttribute( DBFHandle hDBF, int iShape, int iField );
529 const char SHPAPI_CALL1(*)
530 DBFReadLogicalAttribute( DBFHandle hDBF, int iShape, int iField );
531 int SHPAPI_CALL
532 DBFIsAttributeNULL( DBFHandle hDBF, int iShape, int iField );
533
534 int SHPAPI_CALL
535 DBFWriteIntegerAttribute( DBFHandle hDBF, int iShape, int iField,
536 int nFieldValue );
537 int SHPAPI_CALL
538 DBFWriteDoubleAttribute( DBFHandle hDBF, int iShape, int iField,
539 double dFieldValue );
540 int SHPAPI_CALL
541 DBFWriteStringAttribute( DBFHandle hDBF, int iShape, int iField,
542 const char * pszFieldValue );
543 int SHPAPI_CALL
544 DBFWriteNULLAttribute( DBFHandle hDBF, int iShape, int iField );
545
546 int SHPAPI_CALL
547 DBFWriteLogicalAttribute( DBFHandle hDBF, int iShape, int iField,
548 const char lFieldValue);
549 int SHPAPI_CALL
550 DBFWriteAttributeDirectly(DBFHandle psDBF, int hEntity, int iField,
551 void * pValue );
552 const char SHPAPI_CALL1(*)
553 DBFReadTuple(DBFHandle psDBF, int hEntity );
554 int SHPAPI_CALL
555 DBFWriteTuple(DBFHandle psDBF, int hEntity, void * pRawTuple );
556
557 DBFHandle SHPAPI_CALL
558 DBFCloneEmpty(DBFHandle psDBF, const char * pszFilename );
559 #ifdef DBFAPI_HAS_WIDE
560 DBFHandle SHPAPI_CALL
561 DBFCloneEmptyW(DBFHandle psDBF, const wchar_t * pszFilename );
562 #endif
563 void SHPAPI_CALL
564 DBFCloneEmptyEx(DBFHandle psDBF, DBFHandle newDBF );
565
566 void SHPAPI_CALL
567 DBFClose( DBFHandle hDBF );
568 void SHPAPI_CALL
569 DBFUpdateHeader( DBFHandle hDBF );
570 char SHPAPI_CALL
571 DBFGetNativeFieldType( DBFHandle hDBF, int iField );
572
573 #ifdef __cplusplus
574 }
575 #endif
576
577 #endif /* ndef _SHAPEFILE_H_INCLUDED */

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26