diff options
Diffstat (limited to 'navit/support/shapefile/shapefil.h')
-rw-r--r-- | navit/support/shapefile/shapefil.h | 394 |
1 files changed, 266 insertions, 128 deletions
diff --git a/navit/support/shapefile/shapefil.h b/navit/support/shapefile/shapefil.h index 059244b03..08c645996 100644 --- a/navit/support/shapefile/shapefil.h +++ b/navit/support/shapefile/shapefil.h @@ -2,7 +2,7 @@ #define SHAPEFILE_H_INCLUDED /****************************************************************************** - * $Id: shapefil.h 15715 2008-11-12 15:15:21Z warmerdam $ + * $Id: shapefil.h,v 1.55 2016-12-05 18:44:08 erouault Exp $ * * Project: Shapelib * Purpose: Primary include file for Shapelib. @@ -10,13 +10,14 @@ * ****************************************************************************** * Copyright (c) 1999, Frank Warmerdam + * Copyright (c) 2012-2016, Even Rouault <even dot rouault at mines-paris dot org> * * This software is available under the following "MIT Style" license, - * or at the option of the licensee under the LGPL (see LICENSE.LGPL). This + * or at the option of the licensee under the LGPL (see COPYING). This * option is discussed in more detail in shapelib.html. * * -- - * + * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation @@ -37,7 +38,52 @@ ****************************************************************************** * * $Log: shapefil.h,v $ - * Revision 1.46 2008/11/12 14:28:15 fwarmerdam + * Revision 1.55 2016-12-05 18:44:08 erouault + * * dbfopen.c, shapefil.h: write DBF end-of-file character 0x1A by default. + * This behaviour can be controlled with the DBFSetWriteEndOfFileChar() + * function. + * + * Revision 1.54 2016-12-05 12:44:05 erouault + * * Major overhaul of Makefile build system to use autoconf/automake. + * + * * Warning fixes in contrib/ + * + * Revision 1.53 2016-12-04 15:30:15 erouault + * * shpopen.c, dbfopen.c, shptree.c, shapefil.h: resync with + * GDAL Shapefile driver. Mostly cleanups. SHPObject and DBFInfo + * structures extended with new members. New functions: + * DBFSetLastModifiedDate, SHPOpenLLEx, SHPRestoreSHX, + * SHPSetFastModeReadObject + * + * * sbnsearch.c: new file to implement original ESRI .sbn spatial + * index reading. (no write support). New functions: + * SBNOpenDiskTree, SBNCloseDiskTree, SBNSearchDiskTree, + * SBNSearchDiskTreeInteger, SBNSearchFreeIds + * + * * Makefile, makefile.vc, CMakeLists.txt, shapelib.def: updates + * with new file and symbols. + * + * * commit: helper script to cvs commit + * + * Revision 1.52 2011-12-11 22:26:46 fwarmerdam + * upgrade .qix access code to use SAHooks (gdal #3365) + * + * Revision 1.51 2011-07-24 05:59:25 fwarmerdam + * minimize use of CPLError in favor of SAHooks.Error() + * + * Revision 1.50 2011-05-13 17:35:17 fwarmerdam + * added DBFReorderFields() and DBFAlterFields() functions (from Even) + * + * Revision 1.49 2011-04-16 14:38:21 fwarmerdam + * avoid warnings with gcc on SHP_CVSID + * + * Revision 1.48 2010-08-27 23:42:52 fwarmerdam + * add SHPAPI_CALL attribute in code + * + * Revision 1.47 2010-01-28 11:34:34 fwarmerdam + * handle the shape file length limits more gracefully (#3236) + * + * Revision 1.46 2008-11-12 14:28:15 fwarmerdam * DBFCreateField() now works on files with records * * Revision 1.45 2008/11/11 17:47:10 fwarmerdam @@ -129,8 +175,7 @@ #endif #ifdef USE_CPL -#include "cpl_error.h" -#include "cpl_vsi.h" +#include "cpl_conv.h" #endif #ifdef __cplusplus @@ -153,7 +198,7 @@ extern "C" { /* is disabled. */ /* -------------------------------------------------------------------- */ #define DISABLE_MULTIPATCH_MEASURE - + /* -------------------------------------------------------------------- */ /* SHPAPI_CALL */ /* */ @@ -177,7 +222,7 @@ extern "C" { /* #define SHPAPI_CALL __declspec(dllexport) __stdcall */ /* #define SHPAPI_CALL1 __declspec(dllexport) * __stdcall */ /* */ -/* The complexity of the situtation is partly caused by the */ +/* The complexity of the situation is partly caused by the */ /* peculiar requirement of Visual C++ that __stdcall appear */ /* after any "*"'s in the return value of a function while the */ /* __declspec(dllexport) must appear before them. */ @@ -200,14 +245,18 @@ extern "C" { #ifndef SHPAPI_CALL1 # define SHPAPI_CALL1(x) x SHPAPI_CALL #endif - + /* -------------------------------------------------------------------- */ /* Macros for controlling CVSID and ensuring they don't appear */ /* as unreferenced variables resulting in lots of warnings. */ /* -------------------------------------------------------------------- */ #ifndef DISABLE_CVSID -# define SHP_CVSID(string) static char cpl_cvsid[] = string; \ -static char *cvsid_aw() { return( cvsid_aw() ? ((char *) NULL) : cpl_cvsid ); } +# if defined(__GNUC__) && __GNUC__ >= 4 +# define SHP_CVSID(string) static const char cpl_cvsid[] __attribute__((used)) = string; +# else +# define SHP_CVSID(string) static const char cpl_cvsid[] = string; \ +static const char *cvsid_aw() { return( cvsid_aw() ? NULL : cpl_cvsid ); } +# endif #else # define SHP_CVSID(string) #endif @@ -217,8 +266,8 @@ static char *cvsid_aw() { return( cvsid_aw() ? ((char *) NULL) : cpl_cvsid ); } /* UTF-8 encoded filenames Unicode filenames */ /* -------------------------------------------------------------------- */ #if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) -# define SHPAPI_WINDOWS -# define SHPAPI_UTF8_HOOKS +# define SHPAPI_WINDOWS +# define SHPAPI_UTF8_HOOKS #endif /* -------------------------------------------------------------------- */ @@ -252,29 +301,36 @@ void SHPAPI_CALL SASetupUtf8Hooks( SAHooks *psHooks ); /************************************************************************/ /* SHP Support. */ /************************************************************************/ -typedef struct +typedef struct tagSHPObject SHPObject; + +typedef struct { SAHooks sHooks; SAFile fpSHP; - SAFile fpSHX; + SAFile fpSHX; + + int nShapeType; /* SHPT_* */ - int nShapeType; /* SHPT_* */ - - int nFileSize; /* SHP file */ + unsigned int nFileSize; /* SHP file */ int nRecords; - int nMaxRecords; - int *panRecOffset; - int *panRecSize; + int nMaxRecords; + unsigned int*panRecOffset; + unsigned int *panRecSize; - double adBoundsMin[4]; - double adBoundsMax[4]; + double adBoundsMin[4]; + double adBoundsMax[4]; - int bUpdated; + int bUpdated; unsigned char *pabyRec; int nBufSize; + + int bFastModeReadObject; + unsigned char *pabyObjectBuf; + int nObjectBufSize; + SHPObject* psCachedObject; } SHPInfo; typedef SHPInfo * SHPHandle; @@ -282,66 +338,66 @@ typedef SHPInfo * SHPHandle; /* -------------------------------------------------------------------- */ /* Shape types (nSHPType) */ /* -------------------------------------------------------------------- */ -#define SHPT_NULL 0 -#define SHPT_POINT 1 -#define SHPT_ARC 3 -#define SHPT_POLYGON 5 -#define SHPT_MULTIPOINT 8 -#define SHPT_POINTZ 11 -#define SHPT_ARCZ 13 -#define SHPT_POLYGONZ 15 +#define SHPT_NULL 0 +#define SHPT_POINT 1 +#define SHPT_ARC 3 +#define SHPT_POLYGON 5 +#define SHPT_MULTIPOINT 8 +#define SHPT_POINTZ 11 +#define SHPT_ARCZ 13 +#define SHPT_POLYGONZ 15 #define SHPT_MULTIPOINTZ 18 -#define SHPT_POINTM 21 -#define SHPT_ARCM 23 -#define SHPT_POLYGONM 25 +#define SHPT_POINTM 21 +#define SHPT_ARCM 23 +#define SHPT_POLYGONM 25 #define SHPT_MULTIPOINTM 28 #define SHPT_MULTIPATCH 31 - /* -------------------------------------------------------------------- */ /* Part types - everything but SHPT_MULTIPATCH just uses */ /* SHPP_RING. */ /* -------------------------------------------------------------------- */ -#define SHPP_TRISTRIP 0 -#define SHPP_TRIFAN 1 -#define SHPP_OUTERRING 2 -#define SHPP_INNERRING 3 -#define SHPP_FIRSTRING 4 -#define SHPP_RING 5 +#define SHPP_TRISTRIP 0 +#define SHPP_TRIFAN 1 +#define SHPP_OUTERRING 2 +#define SHPP_INNERRING 3 +#define SHPP_FIRSTRING 4 +#define SHPP_RING 5 /* -------------------------------------------------------------------- */ /* SHPObject - represents on shape (without attributes) read */ /* from the .shp file. */ /* -------------------------------------------------------------------- */ -typedef struct +struct tagSHPObject { - int nSHPType; + int nSHPType; - int nShapeId; /* -1 is unknown/unassigned */ + int nShapeId; /* -1 is unknown/unassigned */ - int nParts; - int *panPartStart; - int *panPartType; - - int nVertices; - double *padfX; - double *padfY; - double *padfZ; - double *padfM; + int nParts; + int *panPartStart; + int *panPartType; - double dfXMin; - double dfYMin; - double dfZMin; - double dfMMin; + int nVertices; + double *padfX; + double *padfY; + double *padfZ; + double *padfM; - double dfXMax; - double dfYMax; - double dfZMax; - double dfMMax; + double dfXMin; + double dfYMin; + double dfZMin; + double dfMMin; - int bMeasureIsUsed; -} SHPObject; + double dfXMax; + double dfYMax; + double dfZMax; + double dfMMax; + + int bMeasureIsUsed; + int bFastModeReadObject; +}; /* -------------------------------------------------------------------- */ /* SHP API Prototypes */ @@ -352,9 +408,23 @@ typedef struct SHPHandle SHPAPI_CALL SHPOpen( const char * pszShapeFile, const char * pszAccess ); SHPHandle SHPAPI_CALL - SHPOpenLL( const char *pszShapeFile, const char *pszAccess, + SHPOpenLL( const char *pszShapeFile, const char *pszAccess, SAHooks *psHooks ); SHPHandle SHPAPI_CALL + SHPOpenLLEx( const char *pszShapeFile, const char *pszAccess, + SAHooks *psHooks, int bRestoreSHX ); + +int SHPAPI_CALL + SHPRestoreSHX( const char *pszShapeFile, const char *pszAccess, + SAHooks *psHooks ); + +/* If setting bFastMode = TRUE, the content of SHPReadObject() is owned by the SHPHandle. */ +/* So you cannot have 2 valid instances of SHPReadObject() simultaneously. */ +/* The SHPObject padfZ and padfM members may be NULL depending on the geometry */ +/* type. It is illegal to free at hand any of the pointer members of the SHPObject structure */ +void SHPAPI_CALL SHPSetFastModeReadObject( SHPHandle hSHP, int bFastMode ); + +SHPHandle SHPAPI_CALL SHPCreate( const char * pszShapeFile, int nShapeType ); SHPHandle SHPAPI_CALL SHPCreateLL( const char * pszShapeFile, int nShapeType, @@ -373,15 +443,15 @@ void SHPAPI_CALL void SHPAPI_CALL SHPComputeExtents( SHPObject * psObject ); SHPObject SHPAPI_CALL1(*) - SHPCreateObject( int nSHPType, int nShapeId, int nParts, + SHPCreateObject( int nSHPType, int nShapeId, int nParts, const int * panPartStart, const int * panPartType, - int nVertices, + int nVertices, const double * padfX, const double * padfY, const double * padfZ, const double * padfM ); SHPObject SHPAPI_CALL1(*) SHPCreateSimpleObject( int nSHPType, int nVertices, - const double * padfX, - const double * padfY, + const double * padfX, + const double * padfY, const double * padfZ ); int SHPAPI_CALL @@ -400,7 +470,7 @@ const char SHPAPI_CALL1(*) /* -------------------------------------------------------------------- */ /* this can be two or four for binary or quad tree */ -#define MAX_SUBNODE 4 +#define MAX_SUBNODE 4 /* upper limit of tree levels for automatic estimation */ #define MAX_DEFAULT_TREE_DEPTH 12 @@ -408,100 +478,150 @@ const char SHPAPI_CALL1(*) typedef struct shape_tree_node { /* region covered by this node */ - double adfBoundsMin[4]; - double adfBoundsMax[4]; + double adfBoundsMin[4]; + double adfBoundsMax[4]; /* list of shapes stored at this node. The papsShapeObj pointers or the whole list can be NULL */ - int nShapeCount; - int *panShapeIds; + int nShapeCount; + int *panShapeIds; SHPObject **papsShapeObj; - int nSubNodes; + int nSubNodes; struct shape_tree_node *apsSubNode[MAX_SUBNODE]; - + } SHPTreeNode; typedef struct { SHPHandle hSHP; - - int nMaxDepth; - int nDimension; + + int nMaxDepth; + int nDimension; int nTotalCount; - - SHPTreeNode *psRoot; + + SHPTreeNode *psRoot; } SHPTree; SHPTree SHPAPI_CALL1(*) SHPCreateTree( SHPHandle hSHP, int nDimension, int nMaxDepth, double *padfBoundsMin, double *padfBoundsMax ); -void SHPAPI_CALL +void SHPAPI_CALL SHPDestroyTree( SHPTree * hTree ); -int SHPAPI_CALL +int SHPAPI_CALL SHPWriteTree( SHPTree *hTree, const char * pszFilename ); -SHPTree SHPAPI_CALL - SHPReadTree( const char * pszFilename ); -int SHPAPI_CALL - SHPTreeAddObject( SHPTree * hTree, SHPObject * psObject ); -int SHPAPI_CALL +int SHPAPI_CALL SHPTreeAddShapeId( SHPTree * hTree, SHPObject * psObject ); -int SHPAPI_CALL +int SHPAPI_CALL SHPTreeRemoveShapeId( SHPTree * hTree, int nShapeId ); -void SHPAPI_CALL +void SHPAPI_CALL SHPTreeTrimExtraNodes( SHPTree * hTree ); -int SHPAPI_CALL1(*) +int SHPAPI_CALL1(*) SHPTreeFindLikelyShapes( SHPTree * hTree, double * padfBoundsMin, double * padfBoundsMax, int * ); -int SHPAPI_CALL +int SHPAPI_CALL SHPCheckBoundsOverlap( double *, double *, double *, double *, int ); -int SHPAPI_CALL1(*) -SHPSearchDiskTree( FILE *fp, +int SHPAPI_CALL1(*) +SHPSearchDiskTree( FILE *fp, double *padfBoundsMin, double *padfBoundsMax, int *pnShapeCount ); +typedef struct SHPDiskTreeInfo* SHPTreeDiskHandle; + +SHPTreeDiskHandle SHPAPI_CALL + SHPOpenDiskTree( const char* pszQIXFilename, + SAHooks *psHooks ); + +void SHPAPI_CALL + SHPCloseDiskTree( SHPTreeDiskHandle hDiskTree ); + +int SHPAPI_CALL1(*) +SHPSearchDiskTreeEx( SHPTreeDiskHandle hDiskTree, + double *padfBoundsMin, double *padfBoundsMax, + int *pnShapeCount ); + +int SHPAPI_CALL + SHPWriteTreeLL(SHPTree *hTree, const char *pszFilename, SAHooks *psHooks ); + +/* -------------------------------------------------------------------- */ +/* SBN Search API */ +/* -------------------------------------------------------------------- */ + +typedef struct SBNSearchInfo* SBNSearchHandle; + +SBNSearchHandle SHPAPI_CALL + SBNOpenDiskTree( const char* pszSBNFilename, + SAHooks *psHooks ); + +void SHPAPI_CALL + SBNCloseDiskTree( SBNSearchHandle hSBN ); + +int SHPAPI_CALL1(*) +SBNSearchDiskTree( SBNSearchHandle hSBN, + double *padfBoundsMin, double *padfBoundsMax, + int *pnShapeCount ); + +int SHPAPI_CALL1(*) +SBNSearchDiskTreeInteger( SBNSearchHandle hSBN, + int bMinX, int bMinY, int bMaxX, int bMaxY, + int *pnShapeCount ); + +void SHPAPI_CALL SBNSearchFreeIds( int* panShapeId ); + /************************************************************************/ /* DBF Support. */ /************************************************************************/ -typedef struct +typedef struct { SAHooks sHooks; - SAFile fp; + SAFile fp; int nRecords; - int nRecordLength; - int nHeaderLength; - int nFields; - int *panFieldOffset; - int *panFieldSize; - int *panFieldDecimals; - char *pachFieldType; + int nRecordLength; /* Must fit on uint16 */ + int nHeaderLength; /* File header length (32) + field + descriptor length + spare space. + Must fit on uint16 */ + int nFields; + int *panFieldOffset; + int *panFieldSize; + int *panFieldDecimals; + char *pachFieldType; - char *pszHeader; + char *pszHeader; /* Field descriptors */ - int nCurrentRecord; - int bCurrentRecordModified; - char *pszCurrentRecord; + int nCurrentRecord; + int bCurrentRecordModified; + char *pszCurrentRecord; int nWorkFieldLength; char *pszWorkField; - - int bNoHeader; - int bUpdated; - double dfDoubleField; + int bNoHeader; + int bUpdated; + + union + { + double dfDoubleField; + int nIntField; + } fieldValue; int iLanguageDriver; char *pszCodePage; + + int nUpdateYearSince1900; /* 0-255 */ + int nUpdateMonth; /* 1-12 */ + int nUpdateDay; /* 1-31 */ + + int bWriteEndOfFileChar; /* defaults to TRUE */ } DBFInfo; typedef DBFInfo * DBFHandle; @@ -514,8 +634,14 @@ typedef enum { FTInvalid } DBFFieldType; -#define XBASE_FLDHDR_SZ 32 - +/* Field descriptor/header size */ +#define XBASE_FLDHDR_SZ 32 +/* Shapelib read up to 11 characters, even if only 10 should normally be used */ +#define XBASE_FLDNAME_LEN_READ 11 +/* On writing, we limit to 10 characters */ +#define XBASE_FLDNAME_LEN_WRITE 10 +/* Normally only 254 characters should be used. We tolerate 255 historically */ +#define XBASE_FLD_MAX_WIDTH 255 DBFHandle SHPAPI_CALL DBFOpen( const char * pszDBFFile, const char * pszAccess ); @@ -529,41 +655,48 @@ DBFHandle SHPAPI_CALL DBFHandle SHPAPI_CALL DBFCreateLL( const char * pszDBFFile, const char * pszCodePage, SAHooks *psHooks ); -int SHPAPI_CALL +int SHPAPI_CALL DBFGetFieldCount( DBFHandle psDBF ); -int SHPAPI_CALL +int SHPAPI_CALL DBFGetRecordCount( DBFHandle psDBF ); -int SHPAPI_CALL +int SHPAPI_CALL DBFAddField( DBFHandle hDBF, const char * pszFieldName, DBFFieldType eType, int nWidth, int nDecimals ); -int SHPAPI_CALL +int SHPAPI_CALL DBFAddNativeFieldType( DBFHandle hDBF, const char * pszFieldName, char chType, int nWidth, int nDecimals ); -int SHPAPI_CALL +int SHPAPI_CALL DBFDeleteField( DBFHandle hDBF, int iField ); +int SHPAPI_CALL + DBFReorderFields( DBFHandle psDBF, int* panMap ); + +int SHPAPI_CALL + DBFAlterFieldDefn( DBFHandle psDBF, int iField, const char * pszFieldName, + char chType, int nWidth, int nDecimals ); + DBFFieldType SHPAPI_CALL - DBFGetFieldInfo( DBFHandle psDBF, int iField, + DBFGetFieldInfo( DBFHandle psDBF, int iField, char * pszFieldName, int * pnWidth, int * pnDecimals ); int SHPAPI_CALL DBFGetFieldIndex(DBFHandle psDBF, const char *pszFieldName); -int SHPAPI_CALL +int SHPAPI_CALL DBFReadIntegerAttribute( DBFHandle hDBF, int iShape, int iField ); -double SHPAPI_CALL +double SHPAPI_CALL DBFReadDoubleAttribute( DBFHandle hDBF, int iShape, int iField ); const char SHPAPI_CALL1(*) DBFReadStringAttribute( DBFHandle hDBF, int iShape, int iField ); const char SHPAPI_CALL1(*) DBFReadLogicalAttribute( DBFHandle hDBF, int iShape, int iField ); -int SHPAPI_CALL +int SHPAPI_CALL DBFIsAttributeNULL( DBFHandle hDBF, int iShape, int iField ); int SHPAPI_CALL - DBFWriteIntegerAttribute( DBFHandle hDBF, int iShape, int iField, + DBFWriteIntegerAttribute( DBFHandle hDBF, int iShape, int iField, int nFieldValue ); int SHPAPI_CALL DBFWriteDoubleAttribute( DBFHandle hDBF, int iShape, int iField, @@ -576,7 +709,7 @@ int SHPAPI_CALL int SHPAPI_CALL DBFWriteLogicalAttribute( DBFHandle hDBF, int iShape, int iField, - const char lFieldValue); + const char lFieldValue); int SHPAPI_CALL DBFWriteAttributeDirectly(DBFHandle psDBF, int hEntity, int iField, void * pValue ); @@ -586,22 +719,27 @@ int SHPAPI_CALL DBFWriteTuple(DBFHandle psDBF, int hEntity, void * pRawTuple ); int SHPAPI_CALL DBFIsRecordDeleted( DBFHandle psDBF, int iShape ); -int SHPAPI_CALL DBFMarkRecordDeleted( DBFHandle psDBF, int iShape, +int SHPAPI_CALL DBFMarkRecordDeleted( DBFHandle psDBF, int iShape, int bIsDeleted ); DBFHandle SHPAPI_CALL DBFCloneEmpty(DBFHandle psDBF, const char * pszFilename ); - -void SHPAPI_CALL + +void SHPAPI_CALL DBFClose( DBFHandle hDBF ); void SHPAPI_CALL DBFUpdateHeader( DBFHandle hDBF ); -char SHPAPI_CALL +char SHPAPI_CALL DBFGetNativeFieldType( DBFHandle hDBF, int iField ); const char SHPAPI_CALL1(*) DBFGetCodePage(DBFHandle psDBF ); +void SHPAPI_CALL + DBFSetLastModifiedDate( DBFHandle psDBF, int nYYSince1900, int nMM, int nDD ); + +void SHPAPI_CALL DBFSetWriteEndOfFileChar( DBFHandle psDBF, int bWriteFlag ); + #ifdef __cplusplus } #endif |