pihmLIBS/shapefil.h

Go to the documentation of this file.
00001 #ifndef _SHAPEFILE_H_INCLUDED
00002 #define _SHAPEFILE_H_INCLUDED
00003 
00004 /******************************************************************************
00005  * $Id: shapefil.h,v 1.26 2002/09/29 00:00:08 warmerda Exp $
00006  *
00007  * Project:  Shapelib
00008  * Purpose:  Primary include file for Shapelib.
00009  * Author:   Frank Warmerdam, warmerdam@pobox.com
00010  *
00011  ******************************************************************************
00012  * Copyright (c) 1999, Frank Warmerdam
00013  *
00014  * This software is available under the following "MIT Style" license,
00015  * or at the option of the licensee under the LGPL (see LICENSE.LGPL).  This
00016  * option is discussed in more detail in shapelib.html.
00017  *
00018  * --
00019  * 
00020  * Permission is hereby granted, free of charge, to any person obtaining a
00021  * copy of this software and associated documentation files (the "Software"),
00022  * to deal in the Software without restriction, including without limitation
00023  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
00024  * and/or sell copies of the Software, and to permit persons to whom the
00025  * Software is furnished to do so, subject to the following conditions:
00026  *
00027  * The above copyright notice and this permission notice shall be included
00028  * in all copies or substantial portions of the Software.
00029  *
00030  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00031  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00032  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
00033  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00034  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00035  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
00036  * DEALINGS IN THE SOFTWARE.
00037  ******************************************************************************
00038  *
00039  * $Log: shapefil.h,v $
00040  * Revision 1.26  2002/09/29 00:00:08  warmerda
00041  * added FTLogical and logical attribute read/write calls
00042  *
00043  * Revision 1.25  2002/05/07 13:46:30  warmerda
00044  * added DBFWriteAttributeDirectly().
00045  *
00046  * Revision 1.24  2002/04/10 16:59:54  warmerda
00047  * added SHPRewindObject
00048  *
00049  * Revision 1.23  2002/01/15 14:36:07  warmerda
00050  * updated email address
00051  *
00052  * Revision 1.22  2002/01/15 14:32:00  warmerda
00053  * try to improve SHPAPI_CALL docs
00054  *
00055  * Revision 1.21  2001/11/01 16:29:55  warmerda
00056  * move pabyRec into SHPInfo for thread safety
00057  *
00058  * Revision 1.20  2001/07/20 13:06:02  warmerda
00059  * fixed SHPAPI attribute for SHPTreeFindLikelyShapes
00060  *
00061  * Revision 1.19  2001/05/31 19:20:13  warmerda
00062  * added DBFGetFieldIndex()
00063  *
00064  * Revision 1.18  2001/05/31 18:15:40  warmerda
00065  * Added support for NULL fields in DBF files
00066  *
00067  * Revision 1.17  2001/05/23 13:36:52  warmerda
00068  * added use of SHPAPI_CALL
00069  *
00070  * Revision 1.16  2000/09/25 14:15:59  warmerda
00071  * added DBFGetNativeFieldType()
00072  *
00073  * Revision 1.15  2000/02/16 16:03:51  warmerda
00074  * added null shape support
00075  *
00076  * Revision 1.14  1999/11/05 14:12:05  warmerda
00077  * updated license terms
00078  *
00079  * Revision 1.13  1999/06/02 18:24:21  warmerda
00080  * added trimming code
00081  *
00082  * Revision 1.12  1999/06/02 17:56:12  warmerda
00083  * added quad'' subnode support for trees
00084  *
00085  * Revision 1.11  1999/05/18 19:11:11  warmerda
00086  * Added example searching capability
00087  *
00088  * Revision 1.10  1999/05/18 17:49:38  warmerda
00089  * added initial quadtree support
00090  *
00091  * Revision 1.9  1999/05/11 03:19:28  warmerda
00092  * added new Tuple api, and improved extension handling - add from candrsn
00093  *
00094  * Revision 1.8  1999/03/23 17:22:27  warmerda
00095  * Added extern "C" protection for C++ users of shapefil.h.
00096  *
00097  * Revision 1.7  1998/12/31 15:31:07  warmerda
00098  * Added the TRIM_DBF_WHITESPACE and DISABLE_MULTIPATCH_MEASURE options.
00099  *
00100  * Revision 1.6  1998/12/03 15:48:15  warmerda
00101  * Added SHPCalculateExtents().
00102  *
00103  * Revision 1.5  1998/11/09 20:57:16  warmerda
00104  * Altered SHPGetInfo() call.
00105  *
00106  * Revision 1.4  1998/11/09 20:19:33  warmerda
00107  * Added 3D support, and use of SHPObject.
00108  *
00109  * Revision 1.3  1995/08/23 02:24:05  warmerda
00110  * Added support for reading bounds.
00111  *
00112  * Revision 1.2  1995/08/04  03:17:39  warmerda
00113  * Added header.
00114  *
00115  */
00116 
00117 #include <stdio.h>
00118 
00119 #ifdef USE_DBMALLOC
00120 #include <dbmalloc.h>
00121 #endif
00122 
00123 #ifdef __cplusplus
00124 extern "C" {
00125 #endif
00126 
00127 /************************************************************************/
00128 /*                        Configuration options.                        */
00129 /************************************************************************/
00130 
00131 /* -------------------------------------------------------------------- */
00132 /*      Should the DBFReadStringAttribute() strip leading and           */
00133 /*      trailing white space?                                           */
00134 /* -------------------------------------------------------------------- */
00135 #define TRIM_DBF_WHITESPACE
00136 
00137 /* -------------------------------------------------------------------- */
00138 /*      Should we write measure values to the Multipatch object?        */
00139 /*      Reportedly ArcView crashes if we do write it, so for now it     */
00140 /*      is disabled.                                                    */
00141 /* -------------------------------------------------------------------- */
00142 #define DISABLE_MULTIPATCH_MEASURE
00143 
00144 /* -------------------------------------------------------------------- */
00145 /*      SHPAPI_CALL                                                     */
00146 /*                                                                      */
00147 /*      The following two macros are present to allow forcing           */
00148 /*      various calling conventions on the Shapelib API.                */
00149 /*                                                                      */
00150 /*      To force __stdcall conventions (needed to call Shapelib         */
00151 /*      from Visual Basic and/or Dephi I believe) the makefile could    */
00152 /*      be modified to define:                                          */
00153 /*                                                                      */
00154 /*        /DSHPAPI_CALL=__stdcall                                       */
00155 /*                                                                      */
00156 /*      If it is desired to force export of the Shapelib API without    */
00157 /*      using the shapelib.def file, use the following definition.      */
00158 /*                                                                      */
00159 /*        /DSHAPELIB_DLLEXPORT                                          */
00160 /*                                                                      */
00161 /*      To get both at once it will be necessary to hack this           */
00162 /*      include file to define:                                         */
00163 /*                                                                      */
00164 /*        #define SHPAPI_CALL __declspec(dllexport) __stdcall           */
00165 /*        #define SHPAPI_CALL1 __declspec(dllexport) * __stdcall        */
00166 /*                                                                      */
00167 /*      The complexity of the situtation is partly caused by the        */
00168 /*      peculiar requirement of Visual C++ that __stdcall appear        */
00169 /*      after any "*"'s in the return value of a function while the     */
00170 /*      __declspec(dllexport) must appear before them.                  */
00171 /* -------------------------------------------------------------------- */
00172 
00173 #ifdef SHAPELIB_DLLEXPORT
00174 #  define SHPAPI_CALL __declspec(dllexport)
00175 #  define SHPAPI_CALL1(x)  __declspec(dllexport) x
00176 #endif
00177 
00178 #ifndef SHPAPI_CALL
00179 #  define SHPAPI_CALL
00180 #endif
00181 
00182 #ifndef SHPAPI_CALL1
00183 #  define SHPAPI_CALL1(x)      x SHPAPI_CALL
00184 #endif
00185     
00186 /************************************************************************/
00187 /*                             SHP Support.                             */
00188 /************************************************************************/
00189 typedef struct
00190 {
00191     FILE        *fpSHP;
00192     FILE        *fpSHX;
00193 
00194     int         nShapeType;                             /* SHPT_* */
00195     
00196     int         nFileSize;                              /* SHP file */
00197 
00198     int         nRecords;
00199     int         nMaxRecords;
00200     int         *panRecOffset;
00201     int         *panRecSize;
00202 
00203     double      adBoundsMin[4];
00204     double      adBoundsMax[4];
00205 
00206     int         bUpdated;
00207 
00208     unsigned char *pabyRec;
00209     int         nBufSize;
00210 } SHPInfo;
00211 
00212 typedef SHPInfo * SHPHandle;
00213 
00214 /* -------------------------------------------------------------------- */
00215 /*      Shape types (nSHPType)                                          */
00216 /* -------------------------------------------------------------------- */
00217 #define SHPT_NULL       0
00218 #define SHPT_POINT      1
00219 #define SHPT_ARC        3
00220 #define SHPT_POLYGON    5
00221 #define SHPT_MULTIPOINT 8
00222 #define SHPT_POINTZ     11
00223 #define SHPT_ARCZ       13
00224 #define SHPT_POLYGONZ   15
00225 #define SHPT_MULTIPOINTZ 18
00226 #define SHPT_POINTM     21
00227 #define SHPT_ARCM       23
00228 #define SHPT_POLYGONM   25
00229 #define SHPT_MULTIPOINTM 28
00230 #define SHPT_MULTIPATCH 31
00231 
00232 
00233 /* -------------------------------------------------------------------- */
00234 /*      Part types - everything but SHPT_MULTIPATCH just uses           */
00235 /*      SHPP_RING.                                                      */
00236 /* -------------------------------------------------------------------- */
00237 
00238 #define SHPP_TRISTRIP   0
00239 #define SHPP_TRIFAN     1
00240 #define SHPP_OUTERRING  2
00241 #define SHPP_INNERRING  3
00242 #define SHPP_FIRSTRING  4
00243 #define SHPP_RING       5
00244 
00245 /* -------------------------------------------------------------------- */
00246 /*      SHPObject - represents on shape (without attributes) read       */
00247 /*      from the .shp file.                                             */
00248 /* -------------------------------------------------------------------- */
00249 typedef struct
00250 {
00251     int         nSHPType;
00252 
00253     int         nShapeId; /* -1 is unknown/unassigned */
00254 
00255     int         nParts;
00256     int         *panPartStart;
00257     int         *panPartType;
00258     
00259     int         nVertices;
00260     double      *padfX;
00261     double      *padfY;
00262     double      *padfZ;
00263     double      *padfM;
00264 
00265     double      dfXMin;
00266     double      dfYMin;
00267     double      dfZMin;
00268     double      dfMMin;
00269 
00270     double      dfXMax;
00271     double      dfYMax;
00272     double      dfZMax;
00273     double      dfMMax;
00274 } SHPObject;
00275 
00276 /* -------------------------------------------------------------------- */
00277 /*      SHP API Prototypes                                              */
00278 /* -------------------------------------------------------------------- */
00279 SHPHandle SHPAPI_CALL
00280       SHPOpen( const char * pszShapeFile, const char * pszAccess );
00281 SHPHandle SHPAPI_CALL
00282       SHPCreate( const char * pszShapeFile, int nShapeType );
00283 void SHPAPI_CALL
00284       SHPGetInfo( SHPHandle hSHP, int * pnEntities, int * pnShapeType,
00285                   double * padfMinBound, double * padfMaxBound );
00286 
00287 SHPObject SHPAPI_CALL1(*)
00288       SHPReadObject( SHPHandle hSHP, int iShape );
00289 int SHPAPI_CALL
00290       SHPWriteObject( SHPHandle hSHP, int iShape, SHPObject * psObject );
00291 
00292 void SHPAPI_CALL
00293       SHPDestroyObject( SHPObject * psObject );
00294 void SHPAPI_CALL
00295       SHPComputeExtents( SHPObject * psObject );
00296 SHPObject SHPAPI_CALL1(*)
00297       SHPCreateObject( int nSHPType, int nShapeId,
00298                        int nParts, int * panPartStart, int * panPartType,
00299                        int nVertices, double * padfX, double * padfY,
00300                        double * padfZ, double * padfM );
00301 SHPObject SHPAPI_CALL1(*)
00302       SHPCreateSimpleObject( int nSHPType, int nVertices,
00303                              double * padfX, double * padfY, double * padfZ );
00304 
00305 int SHPAPI_CALL
00306       SHPRewindObject( SHPHandle hSHP, SHPObject * psObject );
00307 
00308 void SHPAPI_CALL
00309       SHPClose( SHPHandle hSHP );
00310 
00311 const char SHPAPI_CALL1(*)
00312       SHPTypeName( int nSHPType );
00313 const char SHPAPI_CALL1(*)
00314       SHPPartTypeName( int nPartType );
00315 
00316 /* -------------------------------------------------------------------- */
00317 /*      Shape quadtree indexing API.                                    */
00318 /* -------------------------------------------------------------------- */
00319 
00320 /* this can be two or four for binary or quad tree */
00321 #define MAX_SUBNODE     4
00322 
00323 typedef struct shape_tree_node
00324 {
00325     /* region covered by this node */
00326     double      adfBoundsMin[4];
00327     double      adfBoundsMax[4];
00328 
00329     /* list of shapes stored at this node.  The papsShapeObj pointers
00330        or the whole list can be NULL */
00331     int         nShapeCount;
00332     int         *panShapeIds;
00333     SHPObject   **papsShapeObj;
00334 
00335     int         nSubNodes;
00336     struct shape_tree_node *apsSubNode[MAX_SUBNODE];
00337     
00338 } SHPTreeNode;
00339 
00340 typedef struct
00341 {
00342     SHPHandle   hSHP;
00343     
00344     int         nMaxDepth;
00345     int         nDimension;
00346     
00347     SHPTreeNode *psRoot;
00348 } SHPTree;
00349 
00350 SHPTree SHPAPI_CALL1(*)
00351       SHPCreateTree( SHPHandle hSHP, int nDimension, int nMaxDepth,
00352                      double *padfBoundsMin, double *padfBoundsMax );
00353 void    SHPAPI_CALL
00354       SHPDestroyTree( SHPTree * hTree );
00355 
00356 int     SHPAPI_CALL
00357       SHPWriteTree( SHPTree *hTree, const char * pszFilename );
00358 SHPTree SHPAPI_CALL
00359       SHPReadTree( const char * pszFilename );
00360 
00361 int     SHPAPI_CALL
00362       SHPTreeAddObject( SHPTree * hTree, SHPObject * psObject );
00363 int     SHPAPI_CALL
00364       SHPTreeAddShapeId( SHPTree * hTree, SHPObject * psObject );
00365 int     SHPAPI_CALL
00366       SHPTreeRemoveShapeId( SHPTree * hTree, int nShapeId );
00367 
00368 void    SHPAPI_CALL
00369       SHPTreeTrimExtraNodes( SHPTree * hTree );
00370 
00371 int    SHPAPI_CALL1(*)
00372       SHPTreeFindLikelyShapes( SHPTree * hTree,
00373                                double * padfBoundsMin,
00374                                double * padfBoundsMax,
00375                                int * );
00376 int     SHPAPI_CALL
00377       SHPCheckBoundsOverlap( double *, double *, double *, double *, int );
00378 
00379 /************************************************************************/
00380 /*                             DBF Support.                             */
00381 /************************************************************************/
00382 typedef struct
00383 {
00384     FILE        *fp;
00385 
00386     int         nRecords;
00387 
00388     int         nRecordLength;
00389     int         nHeaderLength;
00390     int         nFields;
00391     int         *panFieldOffset;
00392     int         *panFieldSize;
00393     int         *panFieldDecimals;
00394     char        *pachFieldType;
00395 
00396     char        *pszHeader;
00397 
00398     int         nCurrentRecord;
00399     int         bCurrentRecordModified;
00400     char        *pszCurrentRecord;
00401     
00402     int         bNoHeader;
00403     int         bUpdated;
00404 } DBFInfo;
00405 
00406 typedef DBFInfo * DBFHandle;
00407 
00408 typedef enum {
00409   FTString,
00410   FTInteger,
00411   FTDouble,
00412   FTLogical,
00413   FTInvalid
00414 } DBFFieldType;
00415 
00416 #define XBASE_FLDHDR_SZ       32
00417 
00418 DBFHandle SHPAPI_CALL
00419       DBFOpen( const char * pszDBFFile, const char * pszAccess );
00420 DBFHandle SHPAPI_CALL
00421       DBFCreate( const char * pszDBFFile );
00422 
00423 int     SHPAPI_CALL
00424       DBFGetFieldCount( DBFHandle psDBF );
00425 int     SHPAPI_CALL
00426       DBFGetRecordCount( DBFHandle psDBF );
00427 int     SHPAPI_CALL
00428       DBFAddField( DBFHandle hDBF, const char * pszFieldName,
00429                    DBFFieldType eType, int nWidth, int nDecimals );
00430 
00431 DBFFieldType SHPAPI_CALL
00432       DBFGetFieldInfo( DBFHandle psDBF, int iField, 
00433                        char * pszFieldName, int * pnWidth, int * pnDecimals );
00434 
00435 int SHPAPI_CALL
00436       DBFGetFieldIndex(DBFHandle psDBF, const char *pszFieldName);
00437 
00438 int     SHPAPI_CALL
00439       DBFReadIntegerAttribute( DBFHandle hDBF, int iShape, int iField );
00440 double  SHPAPI_CALL
00441       DBFReadDoubleAttribute( DBFHandle hDBF, int iShape, int iField );
00442 const char SHPAPI_CALL1(*)
00443       DBFReadStringAttribute( DBFHandle hDBF, int iShape, int iField );
00444 const char SHPAPI_CALL1(*)
00445       DBFReadLogicalAttribute( DBFHandle hDBF, int iShape, int iField );
00446 int     SHPAPI_CALL
00447       DBFIsAttributeNULL( DBFHandle hDBF, int iShape, int iField );
00448 
00449 int SHPAPI_CALL
00450       DBFWriteIntegerAttribute( DBFHandle hDBF, int iShape, int iField, 
00451                                 int nFieldValue );
00452 int SHPAPI_CALL
00453       DBFWriteDoubleAttribute( DBFHandle hDBF, int iShape, int iField,
00454                                double dFieldValue );
00455 int SHPAPI_CALL
00456       DBFWriteStringAttribute( DBFHandle hDBF, int iShape, int iField,
00457                                const char * pszFieldValue );
00458 int SHPAPI_CALL
00459      DBFWriteNULLAttribute( DBFHandle hDBF, int iShape, int iField );
00460 
00461 int SHPAPI_CALL
00462      DBFWriteLogicalAttribute( DBFHandle hDBF, int iShape, int iField,
00463                                const char lFieldValue);
00464 int SHPAPI_CALL
00465      DBFWriteAttributeDirectly(DBFHandle psDBF, int hEntity, int iField,
00466                                void * pValue );
00467 const char SHPAPI_CALL1(*)
00468       DBFReadTuple(DBFHandle psDBF, int hEntity );
00469 int SHPAPI_CALL
00470       DBFWriteTuple(DBFHandle psDBF, int hEntity, void * pRawTuple );
00471 
00472 DBFHandle SHPAPI_CALL
00473       DBFCloneEmpty(DBFHandle psDBF, const char * pszFilename );
00474  
00475 void    SHPAPI_CALL
00476       DBFClose( DBFHandle hDBF );
00477 char    SHPAPI_CALL
00478       DBFGetNativeFieldType( DBFHandle hDBF, int iField );
00479 
00480 #ifdef __cplusplus
00481 }
00482 #endif
00483 
00484 #endif /* ndef _SHAPEFILE_H_INCLUDED */

Generated on Sun Aug 5 17:33:59 2007 for PIHMgis by  doxygen 1.5.2