source: TI02-CSML/trunk/services/3rdParty/Quadtree-0.1.2/shapelib/shapefil.h @ 2194

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI02-CSML/trunk/services/3rdParty/Quadtree-0.1.2/shapelib/shapefil.h@2194
Revision 2194, 16.0 KB checked in by lawrence, 13 years ago (diff)

Adding various specs and 3rd party code of interest for the CSML
services development.

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