/[zanavi_public1]/navit/navit/map/shapefile/shapefil.h
ZANavi

Contents of /navit/navit/map/shapefile/shapefil.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (show annotations) (download)
Fri Oct 28 21:19:04 2011 UTC (12 years, 5 months ago) by zoff99
File MIME type: text/plain
File size: 21479 byte(s)
import files
1 #ifndef SHAPEFILE_H_INCLUDED
2 #define SHAPEFILE_H_INCLUDED
3
4 /******************************************************************************
5 * $Id: shapefil.h 15715 2008-11-12 15:15:21Z warmerdam $
6 *
7 * Project: Shapelib
8 * Purpose: Primary include file for Shapelib.
9 * Author: Frank Warmerdam, warmerdam@pobox.com
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: shapefil.h,v $
40 * Revision 1.46 2008/11/12 14:28:15 fwarmerdam
41 * DBFCreateField() now works on files with records
42 *
43 * Revision 1.45 2008/11/11 17:47:10 fwarmerdam
44 * added DBFDeleteField() function
45 *
46 * Revision 1.44 2008/01/16 20:05:19 bram
47 * Add file hooks that accept UTF-8 encoded filenames on some platforms. Use SASetupUtf8Hooks
48 * tosetup the hooks and check SHPAPI_UTF8_HOOKS for its availability. Currently, this
49 * is only available on the Windows platform that decodes the UTF-8 filenames to wide
50 * character strings and feeds them to _wfopen and _wremove.
51 *
52 * Revision 1.43 2008/01/10 16:35:30 fwarmerdam
53 * avoid _ prefix on #defined symbols (bug 1840)
54 *
55 * Revision 1.42 2007/12/18 18:28:14 bram
56 * - create hook for client specific atof (bugzilla ticket 1615)
57 * - check for NULL handle before closing cpCPG file, and close after reading.
58 *
59 * Revision 1.41 2007/12/15 20:25:32 bram
60 * dbfopen.c now reads the Code Page information from the DBF file, and exports
61 * this information as a string through the DBFGetCodePage function. This is
62 * either the number from the LDID header field ("LDID/<number>") or as the
63 * content of an accompanying .CPG file. When creating a DBF file, the code can
64 * be set using DBFCreateEx.
65 *
66 * Revision 1.40 2007/12/06 07:00:25 fwarmerdam
67 * dbfopen now using SAHooks for fileio
68 *
69 * Revision 1.39 2007/12/04 20:37:56 fwarmerdam
70 * preliminary implementation of hooks api for io and errors
71 *
72 * Revision 1.38 2007/11/21 22:39:56 fwarmerdam
73 * close shx file in readonly mode (GDAL #1956)
74 *
75 * Revision 1.37 2007/10/27 03:31:14 fwarmerdam
76 * limit default depth of tree to 12 levels (gdal ticket #1594)
77 *
78 * Revision 1.36 2007/09/10 23:33:15 fwarmerdam
79 * Upstreamed support for visibility flag in SHPAPI_CALL for the needs
80 * of GDAL (gdal ticket #1810).
81 *
82 * Revision 1.35 2007/09/03 19:48:10 fwarmerdam
83 * move DBFReadAttribute() static dDoubleField into dbfinfo
84 *
85 * Revision 1.34 2006/06/17 15:33:32 fwarmerdam
86 * added pszWorkField - bug 1202 (rso)
87 *
88 * Revision 1.33 2006/02/15 01:14:30 fwarmerdam
89 * added DBFAddNativeFieldType
90 *
91 * Revision 1.32 2006/01/26 15:07:32 fwarmerdam
92 * add bMeasureIsUsed flag from Craig Bruce: Bug 1249
93 *
94 * Revision 1.31 2006/01/05 01:27:27 fwarmerdam
95 * added dbf deletion mark/fetch
96 *
97 * Revision 1.30 2005/01/03 22:30:13 fwarmerdam
98 * added support for saved quadtrees
99 *
100 * Revision 1.29 2004/09/26 20:09:35 fwarmerdam
101 * avoid rcsid warnings
102 *
103 * Revision 1.28 2003/12/29 06:02:18 fwarmerdam
104 * added cpl_error.h option
105 *
106 * Revision 1.27 2003/04/21 18:30:37 warmerda
107 * added header write/update public methods
108 *
109 * Revision 1.26 2002/09/29 00:00:08 warmerda
110 * added FTLogical and logical attribute read/write calls
111 *
112 * Revision 1.25 2002/05/07 13:46:30 warmerda
113 * added DBFWriteAttributeDirectly().
114 *
115 * Revision 1.24 2002/04/10 16:59:54 warmerda
116 * added SHPRewindObject
117 *
118 * Revision 1.23 2002/01/15 14:36:07 warmerda
119 * updated email address
120 *
121 * Revision 1.22 2002/01/15 14:32:00 warmerda
122 * try to improve SHPAPI_CALL docs
123 */
124
125 #include <stdio.h>
126
127 #ifdef USE_DBMALLOC
128 #include <dbmalloc.h>
129 #endif
130
131 #ifdef USE_CPL
132 #include "cpl_error.h"
133 #include "cpl_vsi.h"
134 #endif
135
136 #ifdef __cplusplus
137 extern "C" {
138 #endif
139
140 /************************************************************************/
141 /* Configuration options. */
142 /************************************************************************/
143
144 /* -------------------------------------------------------------------- */
145 /* Should the DBFReadStringAttribute() strip leading and */
146 /* trailing white space? */
147 /* -------------------------------------------------------------------- */
148 #define TRIM_DBF_WHITESPACE
149
150 /* -------------------------------------------------------------------- */
151 /* Should we write measure values to the Multipatch object? */
152 /* Reportedly ArcView crashes if we do write it, so for now it */
153 /* is disabled. */
154 /* -------------------------------------------------------------------- */
155 #define DISABLE_MULTIPATCH_MEASURE
156
157 /* -------------------------------------------------------------------- */
158 /* SHPAPI_CALL */
159 /* */
160 /* The following two macros are present to allow forcing */
161 /* various calling conventions on the Shapelib API. */
162 /* */
163 /* To force __stdcall conventions (needed to call Shapelib */
164 /* from Visual Basic and/or Dephi I believe) the makefile could */
165 /* be modified to define: */
166 /* */
167 /* /DSHPAPI_CALL=__stdcall */
168 /* */
169 /* If it is desired to force export of the Shapelib API without */
170 /* using the shapelib.def file, use the following definition. */
171 /* */
172 /* /DSHAPELIB_DLLEXPORT */
173 /* */
174 /* To get both at once it will be necessary to hack this */
175 /* include file to define: */
176 /* */
177 /* #define SHPAPI_CALL __declspec(dllexport) __stdcall */
178 /* #define SHPAPI_CALL1 __declspec(dllexport) * __stdcall */
179 /* */
180 /* The complexity of the situtation is partly caused by the */
181 /* peculiar requirement of Visual C++ that __stdcall appear */
182 /* after any "*"'s in the return value of a function while the */
183 /* __declspec(dllexport) must appear before them. */
184 /* -------------------------------------------------------------------- */
185
186 #ifdef SHAPELIB_DLLEXPORT
187 # define SHPAPI_CALL __declspec(dllexport)
188 # define SHPAPI_CALL1(x) __declspec(dllexport) x
189 #endif
190
191 #ifndef SHPAPI_CALL
192 # if defined(USE_GCC_VISIBILITY_FLAG)
193 # define SHPAPI_CALL __attribute__ ((visibility("default")))
194 # define SHPAPI_CALL1(x) __attribute__ ((visibility("default"))) x
195 # else
196 # define SHPAPI_CALL
197 # endif
198 #endif
199
200 #ifndef SHPAPI_CALL1
201 # define SHPAPI_CALL1(x) x SHPAPI_CALL
202 #endif
203
204 /* -------------------------------------------------------------------- */
205 /* Macros for controlling CVSID and ensuring they don't appear */
206 /* as unreferenced variables resulting in lots of warnings. */
207 /* -------------------------------------------------------------------- */
208 #ifndef DISABLE_CVSID
209 # define SHP_CVSID(string) static char cpl_cvsid[] = string; \
210 static char *cvsid_aw() { return( cvsid_aw() ? ((char *) NULL) : cpl_cvsid ); }
211 #else
212 # define SHP_CVSID(string)
213 #endif
214
215 /* -------------------------------------------------------------------- */
216 /* On some platforms, additional file IO hooks are defined that */
217 /* UTF-8 encoded filenames Unicode filenames */
218 /* -------------------------------------------------------------------- */
219 #if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
220 # define SHPAPI_WINDOWS
221 # define SHPAPI_UTF8_HOOKS
222 #endif
223
224 /* -------------------------------------------------------------------- */
225 /* IO/Error hook functions. */
226 /* -------------------------------------------------------------------- */
227 typedef int *SAFile;
228
229 #ifndef SAOffset
230 typedef unsigned long SAOffset;
231 #endif
232
233 typedef struct {
234 SAFile (*FOpen) ( const char *filename, const char *access);
235 SAOffset (*FRead) ( void *p, SAOffset size, SAOffset nmemb, SAFile file);
236 SAOffset (*FWrite)( void *p, SAOffset size, SAOffset nmemb, SAFile file);
237 SAOffset (*FSeek) ( SAFile file, SAOffset offset, int whence );
238 SAOffset (*FTell) ( SAFile file );
239 int (*FFlush)( SAFile file );
240 int (*FClose)( SAFile file );
241 int (*Remove) ( const char *filename );
242
243 void (*Error) ( const char *message );
244 double (*Atof) ( const char *str );
245 } SAHooks;
246
247 void SHPAPI_CALL SASetupDefaultHooks( SAHooks *psHooks );
248 #ifdef SHPAPI_UTF8_HOOKS
249 void SHPAPI_CALL SASetupUtf8Hooks( SAHooks *psHooks );
250 #endif
251
252 /************************************************************************/
253 /* SHP Support. */
254 /************************************************************************/
255 typedef struct
256 {
257 SAHooks sHooks;
258
259 SAFile fpSHP;
260 SAFile fpSHX;
261
262 int nShapeType; /* SHPT_* */
263
264 int nFileSize; /* SHP file */
265
266 int nRecords;
267 int nMaxRecords;
268 int *panRecOffset;
269 int *panRecSize;
270
271 double adBoundsMin[4];
272 double adBoundsMax[4];
273
274 int bUpdated;
275
276 unsigned char *pabyRec;
277 int nBufSize;
278 } SHPInfo;
279
280 typedef SHPInfo * SHPHandle;
281
282 /* -------------------------------------------------------------------- */
283 /* Shape types (nSHPType) */
284 /* -------------------------------------------------------------------- */
285 #define SHPT_NULL 0
286 #define SHPT_POINT 1
287 #define SHPT_ARC 3
288 #define SHPT_POLYGON 5
289 #define SHPT_MULTIPOINT 8
290 #define SHPT_POINTZ 11
291 #define SHPT_ARCZ 13
292 #define SHPT_POLYGONZ 15
293 #define SHPT_MULTIPOINTZ 18
294 #define SHPT_POINTM 21
295 #define SHPT_ARCM 23
296 #define SHPT_POLYGONM 25
297 #define SHPT_MULTIPOINTM 28
298 #define SHPT_MULTIPATCH 31
299
300
301 /* -------------------------------------------------------------------- */
302 /* Part types - everything but SHPT_MULTIPATCH just uses */
303 /* SHPP_RING. */
304 /* -------------------------------------------------------------------- */
305
306 #define SHPP_TRISTRIP 0
307 #define SHPP_TRIFAN 1
308 #define SHPP_OUTERRING 2
309 #define SHPP_INNERRING 3
310 #define SHPP_FIRSTRING 4
311 #define SHPP_RING 5
312
313 /* -------------------------------------------------------------------- */
314 /* SHPObject - represents on shape (without attributes) read */
315 /* from the .shp file. */
316 /* -------------------------------------------------------------------- */
317 typedef struct
318 {
319 int nSHPType;
320
321 int nShapeId; /* -1 is unknown/unassigned */
322
323 int nParts;
324 int *panPartStart;
325 int *panPartType;
326
327 int nVertices;
328 double *padfX;
329 double *padfY;
330 double *padfZ;
331 double *padfM;
332
333 double dfXMin;
334 double dfYMin;
335 double dfZMin;
336 double dfMMin;
337
338 double dfXMax;
339 double dfYMax;
340 double dfZMax;
341 double dfMMax;
342
343 int bMeasureIsUsed;
344 } SHPObject;
345
346 /* -------------------------------------------------------------------- */
347 /* SHP API Prototypes */
348 /* -------------------------------------------------------------------- */
349
350 /* If pszAccess is read-only, the fpSHX field of the returned structure */
351 /* will be NULL as it is not necessary to keep the SHX file open */
352 SHPHandle SHPAPI_CALL
353 SHPOpen( const char * pszShapeFile, const char * pszAccess );
354 SHPHandle SHPAPI_CALL
355 SHPOpenLL( const char *pszShapeFile, const char *pszAccess,
356 SAHooks *psHooks );
357 SHPHandle SHPAPI_CALL
358 SHPCreate( const char * pszShapeFile, int nShapeType );
359 SHPHandle SHPAPI_CALL
360 SHPCreateLL( const char * pszShapeFile, int nShapeType,
361 SAHooks *psHooks );
362 void SHPAPI_CALL
363 SHPGetInfo( SHPHandle hSHP, int * pnEntities, int * pnShapeType,
364 double * padfMinBound, double * padfMaxBound );
365
366 SHPObject SHPAPI_CALL1(*)
367 SHPReadObject( SHPHandle hSHP, int iShape );
368 int SHPAPI_CALL
369 SHPWriteObject( SHPHandle hSHP, int iShape, SHPObject * psObject );
370
371 void SHPAPI_CALL
372 SHPDestroyObject( SHPObject * psObject );
373 void SHPAPI_CALL
374 SHPComputeExtents( SHPObject * psObject );
375 SHPObject SHPAPI_CALL1(*)
376 SHPCreateObject( int nSHPType, int nShapeId, int nParts,
377 const int * panPartStart, const int * panPartType,
378 int nVertices,
379 const double * padfX, const double * padfY,
380 const double * padfZ, const double * padfM );
381 SHPObject SHPAPI_CALL1(*)
382 SHPCreateSimpleObject( int nSHPType, int nVertices,
383 const double * padfX,
384 const double * padfY,
385 const double * padfZ );
386
387 int SHPAPI_CALL
388 SHPRewindObject( SHPHandle hSHP, SHPObject * psObject );
389
390 void SHPAPI_CALL SHPClose( SHPHandle hSHP );
391 void SHPAPI_CALL SHPWriteHeader( SHPHandle hSHP );
392
393 const char SHPAPI_CALL1(*)
394 SHPTypeName( int nSHPType );
395 const char SHPAPI_CALL1(*)
396 SHPPartTypeName( int nPartType );
397
398 /* -------------------------------------------------------------------- */
399 /* Shape quadtree indexing API. */
400 /* -------------------------------------------------------------------- */
401
402 /* this can be two or four for binary or quad tree */
403 #define MAX_SUBNODE 4
404
405 /* upper limit of tree levels for automatic estimation */
406 #define MAX_DEFAULT_TREE_DEPTH 12
407
408 typedef struct shape_tree_node
409 {
410 /* region covered by this node */
411 double adfBoundsMin[4];
412 double adfBoundsMax[4];
413
414 /* list of shapes stored at this node. The papsShapeObj pointers
415 or the whole list can be NULL */
416 int nShapeCount;
417 int *panShapeIds;
418 SHPObject **papsShapeObj;
419
420 int nSubNodes;
421 struct shape_tree_node *apsSubNode[MAX_SUBNODE];
422
423 } SHPTreeNode;
424
425 typedef struct
426 {
427 SHPHandle hSHP;
428
429 int nMaxDepth;
430 int nDimension;
431 int nTotalCount;
432
433 SHPTreeNode *psRoot;
434 } SHPTree;
435
436 SHPTree SHPAPI_CALL1(*)
437 SHPCreateTree( SHPHandle hSHP, int nDimension, int nMaxDepth,
438 double *padfBoundsMin, double *padfBoundsMax );
439 void SHPAPI_CALL
440 SHPDestroyTree( SHPTree * hTree );
441
442 int SHPAPI_CALL
443 SHPWriteTree( SHPTree *hTree, const char * pszFilename );
444 SHPTree SHPAPI_CALL
445 SHPReadTree( const char * pszFilename );
446
447 int SHPAPI_CALL
448 SHPTreeAddObject( SHPTree * hTree, SHPObject * psObject );
449 int SHPAPI_CALL
450 SHPTreeAddShapeId( SHPTree * hTree, SHPObject * psObject );
451 int SHPAPI_CALL
452 SHPTreeRemoveShapeId( SHPTree * hTree, int nShapeId );
453
454 void SHPAPI_CALL
455 SHPTreeTrimExtraNodes( SHPTree * hTree );
456
457 int SHPAPI_CALL1(*)
458 SHPTreeFindLikelyShapes( SHPTree * hTree,
459 double * padfBoundsMin,
460 double * padfBoundsMax,
461 int * );
462 int SHPAPI_CALL
463 SHPCheckBoundsOverlap( double *, double *, double *, double *, int );
464
465 int SHPAPI_CALL1(*)
466 SHPSearchDiskTree( FILE *fp,
467 double *padfBoundsMin, double *padfBoundsMax,
468 int *pnShapeCount );
469
470 /************************************************************************/
471 /* DBF Support. */
472 /************************************************************************/
473 typedef struct
474 {
475 SAHooks sHooks;
476
477 SAFile fp;
478
479 int nRecords;
480
481 int nRecordLength;
482 int nHeaderLength;
483 int nFields;
484 int *panFieldOffset;
485 int *panFieldSize;
486 int *panFieldDecimals;
487 char *pachFieldType;
488
489 char *pszHeader;
490
491 int nCurrentRecord;
492 int bCurrentRecordModified;
493 char *pszCurrentRecord;
494
495 int nWorkFieldLength;
496 char *pszWorkField;
497
498 int bNoHeader;
499 int bUpdated;
500
501 double dfDoubleField;
502
503 int iLanguageDriver;
504 char *pszCodePage;
505 } DBFInfo;
506
507 typedef DBFInfo * DBFHandle;
508
509 typedef enum {
510 FTString,
511 FTInteger,
512 FTDouble,
513 FTLogical,
514 FTInvalid
515 } DBFFieldType;
516
517 #define XBASE_FLDHDR_SZ 32
518
519
520 DBFHandle SHPAPI_CALL
521 DBFOpen( const char * pszDBFFile, const char * pszAccess );
522 DBFHandle SHPAPI_CALL
523 DBFOpenLL( const char * pszDBFFile, const char * pszAccess,
524 SAHooks *psHooks );
525 DBFHandle SHPAPI_CALL
526 DBFCreate( const char * pszDBFFile );
527 DBFHandle SHPAPI_CALL
528 DBFCreateEx( const char * pszDBFFile, const char * pszCodePage );
529 DBFHandle SHPAPI_CALL
530 DBFCreateLL( const char * pszDBFFile, const char * pszCodePage, SAHooks *psHooks );
531
532 int SHPAPI_CALL
533 DBFGetFieldCount( DBFHandle psDBF );
534 int SHPAPI_CALL
535 DBFGetRecordCount( DBFHandle psDBF );
536 int SHPAPI_CALL
537 DBFAddField( DBFHandle hDBF, const char * pszFieldName,
538 DBFFieldType eType, int nWidth, int nDecimals );
539
540 int SHPAPI_CALL
541 DBFAddNativeFieldType( DBFHandle hDBF, const char * pszFieldName,
542 char chType, int nWidth, int nDecimals );
543
544 int SHPAPI_CALL
545 DBFDeleteField( DBFHandle hDBF, int iField );
546
547 DBFFieldType SHPAPI_CALL
548 DBFGetFieldInfo( DBFHandle psDBF, int iField,
549 char * pszFieldName, int * pnWidth, int * pnDecimals );
550
551 int SHPAPI_CALL
552 DBFGetFieldIndex(DBFHandle psDBF, const char *pszFieldName);
553
554 int SHPAPI_CALL
555 DBFReadIntegerAttribute( DBFHandle hDBF, int iShape, int iField );
556 double SHPAPI_CALL
557 DBFReadDoubleAttribute( DBFHandle hDBF, int iShape, int iField );
558 const char SHPAPI_CALL1(*)
559 DBFReadStringAttribute( DBFHandle hDBF, int iShape, int iField );
560 const char SHPAPI_CALL1(*)
561 DBFReadLogicalAttribute( DBFHandle hDBF, int iShape, int iField );
562 int SHPAPI_CALL
563 DBFIsAttributeNULL( DBFHandle hDBF, int iShape, int iField );
564
565 int SHPAPI_CALL
566 DBFWriteIntegerAttribute( DBFHandle hDBF, int iShape, int iField,
567 int nFieldValue );
568 int SHPAPI_CALL
569 DBFWriteDoubleAttribute( DBFHandle hDBF, int iShape, int iField,
570 double dFieldValue );
571 int SHPAPI_CALL
572 DBFWriteStringAttribute( DBFHandle hDBF, int iShape, int iField,
573 const char * pszFieldValue );
574 int SHPAPI_CALL
575 DBFWriteNULLAttribute( DBFHandle hDBF, int iShape, int iField );
576
577 int SHPAPI_CALL
578 DBFWriteLogicalAttribute( DBFHandle hDBF, int iShape, int iField,
579 const char lFieldValue);
580 int SHPAPI_CALL
581 DBFWriteAttributeDirectly(DBFHandle psDBF, int hEntity, int iField,
582 void * pValue );
583 const char SHPAPI_CALL1(*)
584 DBFReadTuple(DBFHandle psDBF, int hEntity );
585 int SHPAPI_CALL
586 DBFWriteTuple(DBFHandle psDBF, int hEntity, void * pRawTuple );
587
588 int SHPAPI_CALL DBFIsRecordDeleted( DBFHandle psDBF, int iShape );
589 int SHPAPI_CALL DBFMarkRecordDeleted( DBFHandle psDBF, int iShape,
590 int bIsDeleted );
591
592 DBFHandle SHPAPI_CALL
593 DBFCloneEmpty(DBFHandle psDBF, const char * pszFilename );
594
595 void SHPAPI_CALL
596 DBFClose( DBFHandle hDBF );
597 void SHPAPI_CALL
598 DBFUpdateHeader( DBFHandle hDBF );
599 char SHPAPI_CALL
600 DBFGetNativeFieldType( DBFHandle hDBF, int iField );
601
602 const char SHPAPI_CALL1(*)
603 DBFGetCodePage(DBFHandle psDBF );
604
605 #ifdef __cplusplus
606 }
607 #endif
608
609 #endif /* ndef SHAPEFILE_H_INCLUDED */

   
Visit the ZANavi Wiki