|
@@ -1,5 +1,5 @@
|
|
|
-#ifndef _SHAPEFILE_H_INCLUDED
|
|
|
-#define _SHAPEFILE_H_INCLUDED
|
|
|
+#ifndef SHAPEFILE_H_INCLUDED
|
|
|
+#define SHAPEFILE_H_INCLUDED
|
|
|
|
|
|
/******************************************************************************
|
|
|
* $Id$
|
|
@@ -10,13 +10,14 @@
|
|
|
*
|
|
|
******************************************************************************
|
|
|
* Copyright (c) 1999, Frank Warmerdam
|
|
|
+ * Copyright (c) 2012-2013, 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
|
|
|
* 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,6 +38,50 @@
|
|
|
******************************************************************************
|
|
|
*
|
|
|
* $Log: shapefil.h,v $
|
|
|
+ * 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
|
|
|
+ * added DBFDeleteField() function
|
|
|
+ *
|
|
|
+ * Revision 1.44 2008/01/16 20:05:19 bram
|
|
|
+ * Add file hooks that accept UTF-8 encoded filenames on some platforms. Use SASetupUtf8Hooks
|
|
|
+ * tosetup the hooks and check SHPAPI_UTF8_HOOKS for its availability. Currently, this
|
|
|
+ * is only available on the Windows platform that decodes the UTF-8 filenames to wide
|
|
|
+ * character strings and feeds them to _wfopen and _wremove.
|
|
|
+ *
|
|
|
+ * Revision 1.43 2008/01/10 16:35:30 fwarmerdam
|
|
|
+ * avoid _ prefix on #defined symbols (bug 1840)
|
|
|
+ *
|
|
|
+ * Revision 1.42 2007/12/18 18:28:14 bram
|
|
|
+ * - create hook for client specific atof (bugzilla ticket 1615)
|
|
|
+ * - check for NULL handle before closing cpCPG file, and close after reading.
|
|
|
+ *
|
|
|
+ * Revision 1.41 2007/12/15 20:25:32 bram
|
|
|
+ * dbfopen.c now reads the Code Page information from the DBF file, and exports
|
|
|
+ * this information as a string through the DBFGetCodePage function. This is
|
|
|
+ * either the number from the LDID header field ("LDID/<number>") or as the
|
|
|
+ * content of an accompanying .CPG file. When creating a DBF file, the code can
|
|
|
+ * be set using DBFCreateEx.
|
|
|
+ *
|
|
|
* Revision 1.40 2007/12/06 07:00:25 fwarmerdam
|
|
|
* dbfopen now using SAHooks for fileio
|
|
|
*
|
|
@@ -103,8 +148,7 @@
|
|
|
#endif
|
|
|
|
|
|
#ifdef USE_CPL
|
|
|
-#include "cpl_error.h"
|
|
|
-#include "cpl_vsi.h"
|
|
|
+#include "cpl_conv.h"
|
|
|
#endif
|
|
|
|
|
|
#ifdef __cplusplus
|
|
@@ -127,7 +171,7 @@ extern "C" {
|
|
|
/* is disabled. */
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
#define DISABLE_MULTIPATCH_MEASURE
|
|
|
-
|
|
|
+
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
/* SHPAPI_CALL */
|
|
|
/* */
|
|
@@ -151,7 +195,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. */
|
|
@@ -174,18 +218,31 @@ 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
|
|
|
-
|
|
|
+
|
|
|
+/* -------------------------------------------------------------------- */
|
|
|
+/* On some platforms, additional file IO hooks are defined that */
|
|
|
+/* UTF-8 encoded filenames Unicode filenames */
|
|
|
+/* -------------------------------------------------------------------- */
|
|
|
+#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
|
|
|
+# define SHPAPI_WINDOWS
|
|
|
+# define SHPAPI_UTF8_HOOKS
|
|
|
+#endif
|
|
|
+
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
/* IO/Error hook functions. */
|
|
|
/* -------------------------------------------------------------------- */
|
|
@@ -196,23 +253,30 @@ typedef unsigned long SAOffset;
|
|
|
#endif
|
|
|
|
|
|
typedef struct {
|
|
|
- SAFile (*FOpen) ( const char *filename, const char *path);
|
|
|
+ SAFile (*FOpen) ( const char *filename, const char *access);
|
|
|
SAOffset (*FRead) ( void *p, SAOffset size, SAOffset nmemb, SAFile file);
|
|
|
SAOffset (*FWrite)( void *p, SAOffset size, SAOffset nmemb, SAFile file);
|
|
|
SAOffset (*FSeek) ( SAFile file, SAOffset offset, int whence );
|
|
|
SAOffset (*FTell) ( SAFile file );
|
|
|
int (*FFlush)( SAFile file );
|
|
|
int (*FClose)( SAFile file );
|
|
|
+ int (*Remove) ( const char *filename );
|
|
|
|
|
|
void (*Error) ( const char *message );
|
|
|
+ double (*Atof) ( const char *str );
|
|
|
} SAHooks;
|
|
|
|
|
|
void SHPAPI_CALL SASetupDefaultHooks( SAHooks *psHooks );
|
|
|
+#ifdef SHPAPI_UTF8_HOOKS
|
|
|
+void SHPAPI_CALL SASetupUtf8Hooks( SAHooks *psHooks );
|
|
|
+#endif
|
|
|
|
|
|
/************************************************************************/
|
|
|
/* SHP Support. */
|
|
|
/************************************************************************/
|
|
|
-typedef struct
|
|
|
+typedef struct tagSHPObject SHPObject;
|
|
|
+
|
|
|
+typedef struct
|
|
|
{
|
|
|
SAHooks sHooks;
|
|
|
|
|
@@ -220,13 +284,13 @@ typedef struct
|
|
|
SAFile fpSHX;
|
|
|
|
|
|
int nShapeType; /* SHPT_* */
|
|
|
-
|
|
|
- int nFileSize; /* SHP file */
|
|
|
+
|
|
|
+ unsigned int nFileSize; /* SHP file */
|
|
|
|
|
|
int nRecords;
|
|
|
int nMaxRecords;
|
|
|
- int *panRecOffset;
|
|
|
- int *panRecSize;
|
|
|
+ unsigned int *panRecOffset;
|
|
|
+ unsigned int *panRecSize;
|
|
|
|
|
|
double adBoundsMin[4];
|
|
|
double adBoundsMax[4];
|
|
@@ -235,6 +299,11 @@ typedef struct
|
|
|
|
|
|
unsigned char *pabyRec;
|
|
|
int nBufSize;
|
|
|
+
|
|
|
+ int bFastModeReadObject;
|
|
|
+ unsigned char *pabyObjectBuf;
|
|
|
+ int nObjectBufSize;
|
|
|
+ SHPObject* psCachedObject;
|
|
|
} SHPInfo;
|
|
|
|
|
|
typedef SHPInfo * SHPHandle;
|
|
@@ -274,7 +343,7 @@ typedef SHPInfo * SHPHandle;
|
|
|
/* SHPObject - represents on shape (without attributes) read */
|
|
|
/* from the .shp file. */
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
-typedef struct
|
|
|
+struct tagSHPObject
|
|
|
{
|
|
|
int nSHPType;
|
|
|
|
|
@@ -283,7 +352,7 @@ typedef struct
|
|
|
int nParts;
|
|
|
int *panPartStart;
|
|
|
int *panPartType;
|
|
|
-
|
|
|
+
|
|
|
int nVertices;
|
|
|
double *padfX;
|
|
|
double *padfY;
|
|
@@ -301,7 +370,8 @@ typedef struct
|
|
|
double dfMMax;
|
|
|
|
|
|
int bMeasureIsUsed;
|
|
|
-} SHPObject;
|
|
|
+ int bFastModeReadObject;
|
|
|
+};
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
/* SHP API Prototypes */
|
|
@@ -312,9 +382,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,
|
|
@@ -333,15 +417,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
|
|
@@ -379,17 +463,17 @@ typedef struct shape_tree_node
|
|
|
|
|
|
int nSubNodes;
|
|
|
struct shape_tree_node *apsSubNode[MAX_SUBNODE];
|
|
|
-
|
|
|
+
|
|
|
} SHPTreeNode;
|
|
|
|
|
|
typedef struct
|
|
|
{
|
|
|
SHPHandle hSHP;
|
|
|
-
|
|
|
+
|
|
|
int nMaxDepth;
|
|
|
int nDimension;
|
|
|
int nTotalCount;
|
|
|
-
|
|
|
+
|
|
|
SHPTreeNode *psRoot;
|
|
|
} SHPTree;
|
|
|
|
|
@@ -401,12 +485,8 @@ void 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
|
|
|
SHPTreeAddShapeId( SHPTree * hTree, SHPObject * psObject );
|
|
|
int SHPAPI_CALL
|
|
|
SHPTreeRemoveShapeId( SHPTree * hTree, int nShapeId );
|
|
@@ -422,11 +502,55 @@ int SHPAPI_CALL1(*)
|
|
|
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. */
|
|
|
/************************************************************************/
|
|
@@ -454,11 +578,22 @@ typedef struct
|
|
|
|
|
|
int nWorkFieldLength;
|
|
|
char *pszWorkField;
|
|
|
-
|
|
|
+
|
|
|
int bNoHeader;
|
|
|
int bUpdated;
|
|
|
|
|
|
- double dfDoubleField;
|
|
|
+ union
|
|
|
+ {
|
|
|
+ double dfDoubleField;
|
|
|
+ int nIntField;
|
|
|
+ } fieldValue;
|
|
|
+
|
|
|
+ int iLanguageDriver;
|
|
|
+ char *pszCodePage;
|
|
|
+
|
|
|
+ int nUpdateYearSince1900; /* 0-255 */
|
|
|
+ int nUpdateMonth; /* 1-12 */
|
|
|
+ int nUpdateDay; /* 1-31 */
|
|
|
} DBFInfo;
|
|
|
|
|
|
typedef DBFInfo * DBFHandle;
|
|
@@ -482,7 +617,9 @@ DBFHandle SHPAPI_CALL
|
|
|
DBFHandle SHPAPI_CALL
|
|
|
DBFCreate( const char * pszDBFFile );
|
|
|
DBFHandle SHPAPI_CALL
|
|
|
- DBFCreateLL( const char * pszDBFFile, SAHooks *psHooks );
|
|
|
+ DBFCreateEx( const char * pszDBFFile, const char * pszCodePage );
|
|
|
+DBFHandle SHPAPI_CALL
|
|
|
+ DBFCreateLL( const char * pszDBFFile, const char * pszCodePage, SAHooks *psHooks );
|
|
|
|
|
|
int SHPAPI_CALL
|
|
|
DBFGetFieldCount( DBFHandle psDBF );
|
|
@@ -496,8 +633,18 @@ int SHPAPI_CALL
|
|
|
DBFAddNativeFieldType( DBFHandle hDBF, const char * pszFieldName,
|
|
|
char chType, int nWidth, int nDecimals );
|
|
|
|
|
|
+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
|
|
@@ -515,7 +662,7 @@ 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,
|
|
@@ -538,12 +685,12 @@ 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
|
|
|
DBFClose( DBFHandle hDBF );
|
|
|
void SHPAPI_CALL
|
|
@@ -551,8 +698,14 @@ void 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 );
|
|
|
+
|
|
|
#ifdef __cplusplus
|
|
|
}
|
|
|
#endif
|
|
|
|
|
|
-#endif /* ndef _SHAPEFILE_H_INCLUDED */
|
|
|
+#endif /* ndef SHAPEFILE_H_INCLUDED */
|