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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2734 - (hide annotations)
Thu Mar 1 12:42:59 2007 UTC (18 years ago) by bramz
File MIME type: text/plain
File size: 18503 byte(s)
made a copy
1 jan 1612 #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 bh 1769 * Author: Frank Warmerdam, [email protected]
10 jan 1612 *
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 2212 * 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 jan 1612 *
44 bh 2212 * * 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 bh 1769 * Revision 1.26 2002/09/29 00:00:08 warmerda
86     * added FTLogical and logical attribute read/write calls
87 jan 1612 *
88 bh 1769 * Revision 1.25 2002/05/07 13:46:30 warmerda
89     * added DBFWriteAttributeDirectly().
90 jan 1612 *
91 bh 1769 * 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 jan 1612 * 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 bh 2212 #ifdef USE_CPL
169     #include "cpl_error.h"
170     #endif
171    
172 jan 1612 #ifdef __cplusplus
173     extern "C" {
174     #endif
175    
176     /************************************************************************/
177     /* Configuration options. */
178     /************************************************************************/
179    
180     /* -------------------------------------------------------------------- */
181     /* Should the DBFReadStringAttribute() strip leading and */
182     /* trailing white space? */
183     /* -------------------------------------------------------------------- */
184     #define TRIM_DBF_WHITESPACE
185    
186     /* -------------------------------------------------------------------- */
187     /* Should we write measure values to the Multipatch object? */
188     /* Reportedly ArcView crashes if we do write it, so for now it */
189     /* is disabled. */
190     /* -------------------------------------------------------------------- */
191     #define DISABLE_MULTIPATCH_MEASURE
192    
193 bh 1769 /* -------------------------------------------------------------------- */
194     /* SHPAPI_CALL */
195     /* */
196     /* The following two macros are present to allow forcing */
197     /* various calling conventions on the Shapelib API. */
198     /* */
199     /* To force __stdcall conventions (needed to call Shapelib */
200     /* from Visual Basic and/or Dephi I believe) the makefile could */
201     /* be modified to define: */
202     /* */
203     /* /DSHPAPI_CALL=__stdcall */
204     /* */
205     /* If it is desired to force export of the Shapelib API without */
206     /* using the shapelib.def file, use the following definition. */
207     /* */
208     /* /DSHAPELIB_DLLEXPORT */
209     /* */
210     /* To get both at once it will be necessary to hack this */
211     /* include file to define: */
212     /* */
213     /* #define SHPAPI_CALL __declspec(dllexport) __stdcall */
214     /* #define SHPAPI_CALL1 __declspec(dllexport) * __stdcall */
215     /* */
216     /* The complexity of the situtation is partly caused by the */
217     /* peculiar requirement of Visual C++ that __stdcall appear */
218     /* after any "*"'s in the return value of a function while the */
219     /* __declspec(dllexport) must appear before them. */
220     /* -------------------------------------------------------------------- */
221    
222     #ifdef SHAPELIB_DLLEXPORT
223     # define SHPAPI_CALL __declspec(dllexport)
224     # define SHPAPI_CALL1(x) __declspec(dllexport) x
225     #endif
226    
227     #ifndef SHPAPI_CALL
228     # define SHPAPI_CALL
229     #endif
230    
231     #ifndef SHPAPI_CALL1
232     # define SHPAPI_CALL1(x) x SHPAPI_CALL
233     #endif
234    
235 jan 1612 /************************************************************************/
236     /* SHP Support. */
237     /************************************************************************/
238     typedef struct
239     {
240     FILE *fpSHP;
241     FILE *fpSHX;
242    
243     int nShapeType; /* SHPT_* */
244    
245     int nFileSize; /* SHP file */
246    
247     int nRecords;
248     int nMaxRecords;
249     int *panRecOffset;
250     int *panRecSize;
251    
252     double adBoundsMin[4];
253     double adBoundsMax[4];
254    
255     int bUpdated;
256 bh 1769
257     unsigned char *pabyRec;
258     int nBufSize;
259 jan 1612 } SHPInfo;
260    
261     typedef SHPInfo * SHPHandle;
262    
263     /* -------------------------------------------------------------------- */
264     /* Shape types (nSHPType) */
265     /* -------------------------------------------------------------------- */
266     #define SHPT_NULL 0
267     #define SHPT_POINT 1
268     #define SHPT_ARC 3
269     #define SHPT_POLYGON 5
270     #define SHPT_MULTIPOINT 8
271     #define SHPT_POINTZ 11
272     #define SHPT_ARCZ 13
273     #define SHPT_POLYGONZ 15
274     #define SHPT_MULTIPOINTZ 18
275     #define SHPT_POINTM 21
276     #define SHPT_ARCM 23
277     #define SHPT_POLYGONM 25
278     #define SHPT_MULTIPOINTM 28
279     #define SHPT_MULTIPATCH 31
280    
281    
282     /* -------------------------------------------------------------------- */
283     /* Part types - everything but SHPT_MULTIPATCH just uses */
284     /* SHPP_RING. */
285     /* -------------------------------------------------------------------- */
286    
287     #define SHPP_TRISTRIP 0
288     #define SHPP_TRIFAN 1
289     #define SHPP_OUTERRING 2
290     #define SHPP_INNERRING 3
291     #define SHPP_FIRSTRING 4
292     #define SHPP_RING 5
293    
294     /* -------------------------------------------------------------------- */
295     /* SHPObject - represents on shape (without attributes) read */
296     /* from the .shp file. */
297     /* -------------------------------------------------------------------- */
298     typedef struct
299     {
300     int nSHPType;
301    
302     int nShapeId; /* -1 is unknown/unassigned */
303    
304     int nParts;
305     int *panPartStart;
306     int *panPartType;
307    
308     int nVertices;
309     double *padfX;
310     double *padfY;
311     double *padfZ;
312     double *padfM;
313    
314     double dfXMin;
315     double dfYMin;
316     double dfZMin;
317     double dfMMin;
318    
319     double dfXMax;
320     double dfYMax;
321     double dfZMax;
322     double dfMMax;
323     } SHPObject;
324    
325     /* -------------------------------------------------------------------- */
326     /* SHP API Prototypes */
327     /* -------------------------------------------------------------------- */
328     SHPHandle SHPAPI_CALL
329     SHPOpen( const char * pszShapeFile, const char * pszAccess );
330     SHPHandle SHPAPI_CALL
331     SHPCreate( const char * pszShapeFile, int nShapeType );
332     void SHPAPI_CALL
333     SHPGetInfo( SHPHandle hSHP, int * pnEntities, int * pnShapeType,
334     double * padfMinBound, double * padfMaxBound );
335    
336     SHPObject SHPAPI_CALL1(*)
337     SHPReadObject( SHPHandle hSHP, int iShape );
338     int SHPAPI_CALL
339     SHPWriteObject( SHPHandle hSHP, int iShape, SHPObject * psObject );
340    
341     void SHPAPI_CALL
342     SHPDestroyObject( SHPObject * psObject );
343     void SHPAPI_CALL
344     SHPComputeExtents( SHPObject * psObject );
345     SHPObject SHPAPI_CALL1(*)
346     SHPCreateObject( int nSHPType, int nShapeId,
347     int nParts, int * panPartStart, int * panPartType,
348     int nVertices, double * padfX, double * padfY,
349     double * padfZ, double * padfM );
350     SHPObject SHPAPI_CALL1(*)
351     SHPCreateSimpleObject( int nSHPType, int nVertices,
352     double * padfX, double * padfY, double * padfZ );
353    
354 bh 1769 int SHPAPI_CALL
355     SHPRewindObject( SHPHandle hSHP, SHPObject * psObject );
356    
357 bh 2212 void SHPAPI_CALL SHPClose( SHPHandle hSHP );
358     void SHPAPI_CALL SHPWriteHeader( SHPHandle hSHP );
359 jan 1612
360     const char SHPAPI_CALL1(*)
361     SHPTypeName( int nSHPType );
362     const char SHPAPI_CALL1(*)
363     SHPPartTypeName( int nPartType );
364    
365     /* -------------------------------------------------------------------- */
366     /* Shape quadtree indexing API. */
367     /* -------------------------------------------------------------------- */
368    
369     /* this can be two or four for binary or quad tree */
370     #define MAX_SUBNODE 4
371    
372     typedef struct shape_tree_node
373     {
374     /* region covered by this node */
375     double adfBoundsMin[4];
376     double adfBoundsMax[4];
377    
378     /* list of shapes stored at this node. The papsShapeObj pointers
379     or the whole list can be NULL */
380     int nShapeCount;
381     int *panShapeIds;
382     SHPObject **papsShapeObj;
383    
384     int nSubNodes;
385     struct shape_tree_node *apsSubNode[MAX_SUBNODE];
386    
387     } SHPTreeNode;
388    
389     typedef struct
390     {
391     SHPHandle hSHP;
392    
393     int nMaxDepth;
394     int nDimension;
395    
396     SHPTreeNode *psRoot;
397     } SHPTree;
398    
399     SHPTree SHPAPI_CALL1(*)
400     SHPCreateTree( SHPHandle hSHP, int nDimension, int nMaxDepth,
401     double *padfBoundsMin, double *padfBoundsMax );
402     void SHPAPI_CALL
403     SHPDestroyTree( SHPTree * hTree );
404    
405     int SHPAPI_CALL
406     SHPWriteTree( SHPTree *hTree, const char * pszFilename );
407     SHPTree SHPAPI_CALL
408     SHPReadTree( const char * pszFilename );
409    
410     int SHPAPI_CALL
411     SHPTreeAddObject( SHPTree * hTree, SHPObject * psObject );
412     int SHPAPI_CALL
413     SHPTreeAddShapeId( SHPTree * hTree, SHPObject * psObject );
414     int SHPAPI_CALL
415     SHPTreeRemoveShapeId( SHPTree * hTree, int nShapeId );
416    
417     void SHPAPI_CALL
418     SHPTreeTrimExtraNodes( SHPTree * hTree );
419    
420     int SHPAPI_CALL1(*)
421     SHPTreeFindLikelyShapes( SHPTree * hTree,
422     double * padfBoundsMin,
423     double * padfBoundsMax,
424     int * );
425     int SHPAPI_CALL
426     SHPCheckBoundsOverlap( double *, double *, double *, double *, int );
427    
428     /************************************************************************/
429     /* DBF Support. */
430     /************************************************************************/
431     typedef struct
432     {
433     FILE *fp;
434    
435     int nRecords;
436    
437     int nRecordLength;
438     int nHeaderLength;
439     int nFields;
440     int *panFieldOffset;
441     int *panFieldSize;
442     int *panFieldDecimals;
443     char *pachFieldType;
444    
445     char *pszHeader;
446    
447     int nCurrentRecord;
448     int bCurrentRecordModified;
449     char *pszCurrentRecord;
450    
451     int bNoHeader;
452     int bUpdated;
453     } DBFInfo;
454    
455     typedef DBFInfo * DBFHandle;
456    
457     typedef enum {
458     FTString,
459     FTInteger,
460     FTDouble,
461 bh 1769 FTLogical,
462 jan 1612 FTInvalid
463     } DBFFieldType;
464    
465     #define XBASE_FLDHDR_SZ 32
466    
467 bernhard 2703 /* to hand over a locale agnostic atof function, if decimal_point != ".\0" */
468     void SHPAPI_CALL
469     DBFSetatof_function( double (* new_atof_function)(const char *nptr));
470    
471 jan 1612 DBFHandle SHPAPI_CALL
472     DBFOpen( const char * pszDBFFile, const char * pszAccess );
473     DBFHandle SHPAPI_CALL
474     DBFCreate( const char * pszDBFFile );
475    
476     int SHPAPI_CALL
477     DBFGetFieldCount( DBFHandle psDBF );
478     int SHPAPI_CALL
479     DBFGetRecordCount( DBFHandle psDBF );
480     int SHPAPI_CALL
481     DBFAddField( DBFHandle hDBF, const char * pszFieldName,
482     DBFFieldType eType, int nWidth, int nDecimals );
483    
484     DBFFieldType SHPAPI_CALL
485     DBFGetFieldInfo( DBFHandle psDBF, int iField,
486     char * pszFieldName, int * pnWidth, int * pnDecimals );
487    
488     int SHPAPI_CALL
489     DBFGetFieldIndex(DBFHandle psDBF, const char *pszFieldName);
490    
491     int SHPAPI_CALL
492     DBFReadIntegerAttribute( DBFHandle hDBF, int iShape, int iField );
493     double SHPAPI_CALL
494     DBFReadDoubleAttribute( DBFHandle hDBF, int iShape, int iField );
495     const char SHPAPI_CALL1(*)
496     DBFReadStringAttribute( DBFHandle hDBF, int iShape, int iField );
497 bh 1769 const char SHPAPI_CALL1(*)
498     DBFReadLogicalAttribute( DBFHandle hDBF, int iShape, int iField );
499 jan 1612 int SHPAPI_CALL
500     DBFIsAttributeNULL( DBFHandle hDBF, int iShape, int iField );
501    
502     int SHPAPI_CALL
503     DBFWriteIntegerAttribute( DBFHandle hDBF, int iShape, int iField,
504     int nFieldValue );
505     int SHPAPI_CALL
506     DBFWriteDoubleAttribute( DBFHandle hDBF, int iShape, int iField,
507     double dFieldValue );
508     int SHPAPI_CALL
509     DBFWriteStringAttribute( DBFHandle hDBF, int iShape, int iField,
510     const char * pszFieldValue );
511     int SHPAPI_CALL
512     DBFWriteNULLAttribute( DBFHandle hDBF, int iShape, int iField );
513    
514 bh 1769 int SHPAPI_CALL
515     DBFWriteLogicalAttribute( DBFHandle hDBF, int iShape, int iField,
516     const char lFieldValue);
517     int SHPAPI_CALL
518     DBFWriteAttributeDirectly(DBFHandle psDBF, int hEntity, int iField,
519     void * pValue );
520 jan 1612 const char SHPAPI_CALL1(*)
521     DBFReadTuple(DBFHandle psDBF, int hEntity );
522     int SHPAPI_CALL
523     DBFWriteTuple(DBFHandle psDBF, int hEntity, void * pRawTuple );
524    
525     DBFHandle SHPAPI_CALL
526     DBFCloneEmpty(DBFHandle psDBF, const char * pszFilename );
527    
528     void SHPAPI_CALL
529     DBFClose( DBFHandle hDBF );
530 bh 2212 void SHPAPI_CALL
531     DBFUpdateHeader( DBFHandle hDBF );
532 jan 1612 char SHPAPI_CALL
533     DBFGetNativeFieldType( DBFHandle hDBF, int iField );
534    
535     #ifdef __cplusplus
536     }
537     #endif
538    
539     #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