src/plugins/dxf2shp_converter/shapelib-1.2.10/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 {
00126 #endif
00127 
00128   /************************************************************************/
00129   /*                        Configuration options.                        */
00130   /************************************************************************/
00131 
00132   /* -------------------------------------------------------------------- */
00133   /*      Should the DBFReadStringAttribute() strip leading and           */
00134   /*      trailing white space?                                           */
00135   /* -------------------------------------------------------------------- */
00136 #define TRIM_DBF_WHITESPACE
00137 
00138   /* -------------------------------------------------------------------- */
00139   /*      Should we write measure values to the Multipatch object?        */
00140   /*      Reportedly ArcView crashes if we do write it, so for now it     */
00141   /*      is disabled.                                                    */
00142   /* -------------------------------------------------------------------- */
00143 #define DISABLE_MULTIPATCH_MEASURE
00144 
00145   /* -------------------------------------------------------------------- */
00146   /*      SHPAPI_CALL                                                     */
00147   /*                                                                      */
00148   /*      The following two macros are present to allow forcing           */
00149   /*      various calling conventions on the Shapelib API.                */
00150   /*                                                                      */
00151   /*      To force __stdcall conventions (needed to call Shapelib         */
00152   /*      from Visual Basic and/or Dephi I believe) the makefile could    */
00153   /*      be modified to define:                                          */
00154   /*                                                                      */
00155   /*        /DSHPAPI_CALL=__stdcall                                       */
00156   /*                                                                      */
00157   /*      If it is desired to force export of the Shapelib API without    */
00158   /*      using the shapelib.def file, use the following definition.      */
00159   /*                                                                      */
00160   /*        /DSHAPELIB_DLLEXPORT                                          */
00161   /*                                                                      */
00162   /*      To get both at once it will be necessary to hack this           */
00163   /*      include file to define:                                         */
00164   /*                                                                      */
00165   /*        #define SHPAPI_CALL __declspec(dllexport) __stdcall           */
00166   /*        #define SHPAPI_CALL1 __declspec(dllexport) * __stdcall        */
00167   /*                                                                      */
00168   /*      The complexity of the situtation is partly caused by the        */
00169   /*      peculiar requirement of Visual C++ that __stdcall appear        */
00170   /*      after any "*"'s in the return value of a function while the     */
00171   /*      __declspec(dllexport) must appear before them.                  */
00172   /* -------------------------------------------------------------------- */
00173 
00174 #ifdef SHAPELIB_DLLEXPORT
00175 #  define SHPAPI_CALL __declspec(dllexport)
00176 #  define SHPAPI_CALL1(x)  __declspec(dllexport) x
00177 #endif
00178 
00179 #ifndef SHPAPI_CALL
00180 #  define SHPAPI_CALL
00181 #endif
00182 
00183 #ifndef SHPAPI_CALL1
00184 #  define SHPAPI_CALL1(x)      x SHPAPI_CALL
00185 #endif
00186 
00187   /************************************************************************/
00188   /*                             SHP Support.                             */
00189   /************************************************************************/
00190   typedef struct
00191   {
00192     FILE        *fpSHP;
00193     FILE *fpSHX;
00194 
00195     int  nShapeType;    /* SHPT_* */
00196 
00197     int  nFileSize;    /* SHP file */
00198 
00199     int         nRecords;
00200     int  nMaxRecords;
00201     int  *panRecOffset;
00202     int  *panRecSize;
00203 
00204     double adBoundsMin[4];
00205     double adBoundsMax[4];
00206 
00207     int  bUpdated;
00208 
00209     unsigned char *pabyRec;
00210     int         nBufSize;
00211   } SHPInfo;
00212 
00213   typedef SHPInfo * SHPHandle;
00214 
00215   /* -------------------------------------------------------------------- */
00216   /*      Shape types (nSHPType)                                          */
00217   /* -------------------------------------------------------------------- */
00218 #define SHPT_NULL 0
00219 #define SHPT_POINT 1
00220 #define SHPT_ARC 3
00221 #define SHPT_POLYGON 5
00222 #define SHPT_MULTIPOINT 8
00223 #define SHPT_POINTZ 11
00224 #define SHPT_ARCZ 13
00225 #define SHPT_POLYGONZ 15
00226 #define SHPT_MULTIPOINTZ 18
00227 #define SHPT_POINTM 21
00228 #define SHPT_ARCM 23
00229 #define SHPT_POLYGONM 25
00230 #define SHPT_MULTIPOINTM 28
00231 #define SHPT_MULTIPATCH 31
00232 
00233 
00234   /* -------------------------------------------------------------------- */
00235   /*      Part types - everything but SHPT_MULTIPATCH just uses           */
00236   /*      SHPP_RING.                                                      */
00237   /* -------------------------------------------------------------------- */
00238 
00239 #define SHPP_TRISTRIP 0
00240 #define SHPP_TRIFAN 1
00241 #define SHPP_OUTERRING 2
00242 #define SHPP_INNERRING 3
00243 #define SHPP_FIRSTRING 4
00244 #define SHPP_RING 5
00245 
00246   /* -------------------------------------------------------------------- */
00247   /*      SHPObject - represents on shape (without attributes) read       */
00248   /*      from the .shp file.                                             */
00249   /* -------------------------------------------------------------------- */
00250   typedef struct
00251   {
00252     int  nSHPType;
00253 
00254     int  nShapeId; /* -1 is unknown/unassigned */
00255 
00256     int  nParts;
00257     int  *panPartStart;
00258     int  *panPartType;
00259 
00260     int  nVertices;
00261     double *padfX;
00262     double *padfY;
00263     double *padfZ;
00264     double *padfM;
00265 
00266     double dfXMin;
00267     double dfYMin;
00268     double dfZMin;
00269     double dfMMin;
00270 
00271     double dfXMax;
00272     double dfYMax;
00273     double dfZMax;
00274     double dfMMax;
00275   } SHPObject;
00276 
00277   /* -------------------------------------------------------------------- */
00278   /*      SHP API Prototypes                                              */
00279   /* -------------------------------------------------------------------- */
00280   SHPHandle SHPAPI_CALL
00281   SHPOpen( const char * pszShapeFile, const char * pszAccess );
00282   SHPHandle SHPAPI_CALL
00283   SHPCreate( const char * pszShapeFile, int nShapeType );
00284   void SHPAPI_CALL
00285   SHPGetInfo( SHPHandle hSHP, int * pnEntities, int * pnShapeType,
00286               double * padfMinBound, double * padfMaxBound );
00287 
00288   SHPObject SHPAPI_CALL1( * )
00289   SHPReadObject( SHPHandle hSHP, int iShape );
00290   int SHPAPI_CALL
00291   SHPWriteObject( SHPHandle hSHP, int iShape, SHPObject * psObject );
00292 
00293   void SHPAPI_CALL
00294   SHPDestroyObject( SHPObject * psObject );
00295   void SHPAPI_CALL
00296   SHPComputeExtents( SHPObject * psObject );
00297   SHPObject SHPAPI_CALL1( * )
00298   SHPCreateObject( int nSHPType, int nShapeId,
00299                    int nParts, int * panPartStart, int * panPartType,
00300                    int nVertices, double * padfX, double * padfY,
00301                    double * padfZ, double * padfM );
00302   SHPObject SHPAPI_CALL1( * )
00303   SHPCreateSimpleObject( int nSHPType, int nVertices,
00304                          double * padfX, double * padfY, double * padfZ );
00305 
00306   int SHPAPI_CALL
00307   SHPRewindObject( SHPHandle hSHP, SHPObject * psObject );
00308 
00309   void SHPAPI_CALL
00310   SHPClose( SHPHandle hSHP );
00311 
00312   const char SHPAPI_CALL1( * )
00313   SHPTypeName( int nSHPType );
00314   const char SHPAPI_CALL1( * )
00315   SHPPartTypeName( int nPartType );
00316 
00317   /* -------------------------------------------------------------------- */
00318   /*      Shape quadtree indexing API.                                    */
00319   /* -------------------------------------------------------------------- */
00320 
00321   /* this can be two or four for binary or quad tree */
00322 #define MAX_SUBNODE 4
00323 
00324   typedef struct shape_tree_node
00325   {
00326     /* region covered by this node */
00327     double adfBoundsMin[4];
00328     double adfBoundsMax[4];
00329 
00330     /* list of shapes stored at this node.  The papsShapeObj pointers
00331        or the whole list can be NULL */
00332     int  nShapeCount;
00333     int  *panShapeIds;
00334     SHPObject   **papsShapeObj;
00335 
00336     int  nSubNodes;
00337     struct shape_tree_node *apsSubNode[MAX_SUBNODE];
00338 
00339   } SHPTreeNode;
00340 
00341   typedef struct
00342   {
00343     SHPHandle   hSHP;
00344 
00345     int  nMaxDepth;
00346     int  nDimension;
00347 
00348     SHPTreeNode *psRoot;
00349   } SHPTree;
00350 
00351   SHPTree SHPAPI_CALL1( * )
00352   SHPCreateTree( SHPHandle hSHP, int nDimension, int nMaxDepth,
00353                  double *padfBoundsMin, double *padfBoundsMax );
00354   void    SHPAPI_CALL
00355   SHPDestroyTree( SHPTree * hTree );
00356 
00357   int SHPAPI_CALL
00358   SHPWriteTree( SHPTree *hTree, const char * pszFileName );
00359   SHPTree SHPAPI_CALL
00360   SHPReadTree( const char * pszFileName );
00361 
00362   int SHPAPI_CALL
00363   SHPTreeAddObject( SHPTree * hTree, SHPObject * psObject );
00364   int SHPAPI_CALL
00365   SHPTreeAddShapeId( SHPTree * hTree, SHPObject * psObject );
00366   int SHPAPI_CALL
00367   SHPTreeRemoveShapeId( SHPTree * hTree, int nShapeId );
00368 
00369   void  SHPAPI_CALL
00370   SHPTreeTrimExtraNodes( SHPTree * hTree );
00371 
00372   int    SHPAPI_CALL1( * )
00373   SHPTreeFindLikelyShapes( SHPTree * hTree,
00374                            double * padfBoundsMin,
00375                            double * padfBoundsMax,
00376                            int * );
00377   int     SHPAPI_CALL
00378   SHPCheckBoundsOverlap( double *, double *, double *, double *, int );
00379 
00380   /************************************************************************/
00381   /*                             DBF Support.                             */
00382   /************************************************************************/
00383   typedef struct
00384   {
00385     FILE *fp;
00386 
00387     int         nRecords;
00388 
00389     int  nRecordLength;
00390     int  nHeaderLength;
00391     int  nFields;
00392     int  *panFieldOffset;
00393     int  *panFieldSize;
00394     int  *panFieldDecimals;
00395     char *pachFieldType;
00396 
00397     char *pszHeader;
00398 
00399     int  nCurrentRecord;
00400     int  bCurrentRecordModified;
00401     char *pszCurrentRecord;
00402 
00403     int  bNoHeader;
00404     int  bUpdated;
00405   } DBFInfo;
00406 
00407   typedef DBFInfo * DBFHandle;
00408 
00409   typedef enum
00410   {
00411     FTString,
00412     FTInteger,
00413     FTDouble,
00414     FTLogical,
00415     FTInvalid
00416   } DBFFieldType;
00417 
00418 #define XBASE_FLDHDR_SZ       32
00419 
00420   DBFHandle SHPAPI_CALL
00421   DBFOpen( const char * pszDBFFile, const char * pszAccess );
00422   DBFHandle SHPAPI_CALL
00423   DBFCreate( const char * pszDBFFile );
00424 
00425   int SHPAPI_CALL
00426   DBFGetFieldCount( DBFHandle psDBF );
00427   int SHPAPI_CALL
00428   DBFGetRecordCount( DBFHandle psDBF );
00429   int SHPAPI_CALL
00430   DBFAddField( DBFHandle hDBF, const char * pszFieldName,
00431                DBFFieldType eType, int nWidth, int nDecimals );
00432 
00433   DBFFieldType SHPAPI_CALL
00434   DBFGetFieldInfo( DBFHandle psDBF, int iField,
00435                    char * pszFieldName, int * pnWidth, int * pnDecimals );
00436 
00437   int SHPAPI_CALL
00438   DBFGetFieldIndex( DBFHandle psDBF, const char *pszFieldName );
00439 
00440   int  SHPAPI_CALL
00441   DBFReadIntegerAttribute( DBFHandle hDBF, int iShape, int iField );
00442   double  SHPAPI_CALL
00443   DBFReadDoubleAttribute( DBFHandle hDBF, int iShape, int iField );
00444   const char SHPAPI_CALL1( * )
00445   DBFReadStringAttribute( DBFHandle hDBF, int iShape, int iField );
00446   const char SHPAPI_CALL1( * )
00447   DBFReadLogicalAttribute( DBFHandle hDBF, int iShape, int iField );
00448   int     SHPAPI_CALL
00449   DBFIsAttributeNULL( DBFHandle hDBF, int iShape, int iField );
00450 
00451   int SHPAPI_CALL
00452   DBFWriteIntegerAttribute( DBFHandle hDBF, int iShape, int iField,
00453                             int nFieldValue );
00454   int SHPAPI_CALL
00455   DBFWriteDoubleAttribute( DBFHandle hDBF, int iShape, int iField,
00456                            double dFieldValue );
00457   int SHPAPI_CALL
00458   DBFWriteStringAttribute( DBFHandle hDBF, int iShape, int iField,
00459                            const char * pszFieldValue );
00460   int SHPAPI_CALL
00461   DBFWriteNULLAttribute( DBFHandle hDBF, int iShape, int iField );
00462 
00463   int SHPAPI_CALL
00464   DBFWriteLogicalAttribute( DBFHandle hDBF, int iShape, int iField,
00465                             const char lFieldValue );
00466   int SHPAPI_CALL
00467   DBFWriteAttributeDirectly( DBFHandle psDBF, int hEntity, int iField,
00468                              void * pValue );
00469   const char SHPAPI_CALL1( * )
00470   DBFReadTuple( DBFHandle psDBF, int hEntity );
00471   int SHPAPI_CALL
00472   DBFWriteTuple( DBFHandle psDBF, int hEntity, void * pRawTuple );
00473 
00474   DBFHandle SHPAPI_CALL
00475   DBFCloneEmpty( DBFHandle psDBF, const char * pszFileName );
00476 
00477   void SHPAPI_CALL
00478   DBFClose( DBFHandle hDBF );
00479   char    SHPAPI_CALL
00480   DBFGetNativeFieldType( DBFHandle hDBF, int iField );
00481 
00482 #ifdef __cplusplus
00483 }
00484 #endif
00485 
00486 #endif /* ndef _SHAPEFILE_H_INCLUDED */

Generated on Tue Oct 28 16:51:34 2008 for Quantum GIS API Documentation by  doxygen 1.5.1