00001 #ifndef _SHAPEFILE_H_INCLUDED
00002 #define _SHAPEFILE_H_INCLUDED
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120 #include <stdio.h>
00121
00122 #ifdef USE_DBMALLOC
00123 #include <dbmalloc.h>
00124 #endif
00125
00126 #ifdef __cplusplus
00127 extern "C" {
00128 #endif
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138 #define TRIM_DBF_WHITESPACE
00139
00140
00141
00142
00143
00144
00145 #define DISABLE_MULTIPATCH_MEASURE
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176 #if defined( WIN32 ) || defined( __WIN32__ ) || defined ( _WIN32 ) || defined( WIN64 ) || defined( _WIN32_WCE )
00177
00178 #ifdef SHAPELIB_DLLEXPORT
00179 # define SHPAPI_CALL __declspec(dllexport)
00180 # define SHPAPI_CALL1(x) __declspec(dllexport) x
00181 #endif
00182
00183 #endif
00184
00185 #ifndef SHPAPI_CALL
00186 # define SHPAPI_CALL
00187 #endif
00188
00189 #ifndef SHPAPI_CALL1
00190 # define SHPAPI_CALL1(x) x SHPAPI_CALL
00191 #endif
00192
00193
00194
00195
00196 typedef struct
00197 {
00198 FILE *fpSHP;
00199 FILE *fpSHX;
00200
00201 int nShapeType;
00202
00203 int nFileSize;
00204
00205 int nRecords;
00206 int nMaxRecords;
00207 int *panRecOffset;
00208 int *panRecSize;
00209
00210 double adBoundsMin[4];
00211 double adBoundsMax[4];
00212
00213 int bUpdated;
00214
00215 unsigned char *pabyRec;
00216 int nBufSize;
00217 } SHPInfo;
00218
00219 typedef SHPInfo * SHPHandle;
00220
00221
00222
00223
00224 #define SHPT_NULL 0
00225 #define SHPT_POINT 1
00226 #define SHPT_ARC 3
00227 #define SHPT_POLYGON 5
00228 #define SHPT_MULTIPOINT 8
00229 #define SHPT_POINTZ 11
00230 #define SHPT_ARCZ 13
00231 #define SHPT_POLYGONZ 15
00232 #define SHPT_MULTIPOINTZ 18
00233 #define SHPT_POINTM 21
00234 #define SHPT_ARCM 23
00235 #define SHPT_POLYGONM 25
00236 #define SHPT_MULTIPOINTM 28
00237 #define SHPT_MULTIPATCH 31
00238
00239
00240
00241
00242
00243
00244
00245 #define SHPP_TRISTRIP 0
00246 #define SHPP_TRIFAN 1
00247 #define SHPP_OUTERRING 2
00248 #define SHPP_INNERRING 3
00249 #define SHPP_FIRSTRING 4
00250 #define SHPP_RING 5
00251
00252
00253
00254
00255
00256 typedef struct
00257 {
00258 int nSHPType;
00259
00260 int nShapeId;
00261
00262 int nParts;
00263 int *panPartStart;
00264 int *panPartType;
00265
00266 int nVertices;
00267 double *padfX;
00268 double *padfY;
00269 double *padfZ;
00270 double *padfM;
00271
00272 double dfXMin;
00273 double dfYMin;
00274 double dfZMin;
00275 double dfMMin;
00276
00277 double dfXMax;
00278 double dfYMax;
00279 double dfZMax;
00280 double dfMMax;
00281 } SHPObject;
00282
00283
00284
00285
00286 SHPHandle SHPAPI_CALL
00287 SHPOpen( const char * pszShapeFile, const char * pszAccess );
00288 SHPHandle SHPAPI_CALL
00289 SHPCreate( const char * pszShapeFile, int nShapeType );
00290 void SHPAPI_CALL
00291 SHPGetInfo( SHPHandle hSHP, int * pnEntities, int * pnShapeType,
00292 double * padfMinBound, double * padfMaxBound );
00293
00294 SHPObject SHPAPI_CALL1(*)
00295 SHPReadObject( SHPHandle hSHP, int iShape );
00296 int SHPAPI_CALL
00297 SHPWriteObject( SHPHandle hSHP, int iShape, SHPObject * psObject );
00298
00299 void SHPAPI_CALL
00300 SHPDestroyObject( SHPObject * psObject );
00301 void SHPAPI_CALL
00302 SHPComputeExtents( SHPObject * psObject );
00303 SHPObject SHPAPI_CALL1(*)
00304 SHPCreateObject( int nSHPType, int nShapeId,
00305 int nParts, int * panPartStart, int * panPartType,
00306 int nVertices, double * padfX, double * padfY,
00307 double * padfZ, double * padfM );
00308 SHPObject SHPAPI_CALL1(*)
00309 SHPCreateSimpleObject( int nSHPType, int nVertices,
00310 double * padfX, double * padfY, double * padfZ );
00311
00312 int SHPAPI_CALL
00313 SHPRewindObject( SHPHandle hSHP, SHPObject * psObject );
00314
00315 void SHPAPI_CALL
00316 SHPClose( SHPHandle hSHP );
00317
00318 const char SHPAPI_CALL1(*)
00319 SHPTypeName( int nSHPType );
00320 const char SHPAPI_CALL1(*)
00321 SHPPartTypeName( int nPartType );
00322
00323
00324
00325
00326
00327
00328 #define MAX_SUBNODE 4
00329
00330 typedef struct shape_tree_node
00331 {
00332
00333 double adfBoundsMin[4];
00334 double adfBoundsMax[4];
00335
00336
00337
00338 int nShapeCount;
00339 int *panShapeIds;
00340 SHPObject **papsShapeObj;
00341
00342 int nSubNodes;
00343 struct shape_tree_node *apsSubNode[MAX_SUBNODE];
00344
00345 } SHPTreeNode;
00346
00347 typedef struct
00348 {
00349 SHPHandle hSHP;
00350
00351 int nMaxDepth;
00352 int nDimension;
00353
00354 SHPTreeNode *psRoot;
00355 } SHPTree;
00356
00357 SHPTree SHPAPI_CALL1(*)
00358 SHPCreateTree( SHPHandle hSHP, int nDimension, int nMaxDepth,
00359 double *padfBoundsMin, double *padfBoundsMax );
00360 void SHPAPI_CALL
00361 SHPDestroyTree( SHPTree * hTree );
00362
00363 int SHPAPI_CALL
00364 SHPWriteTree( SHPTree *hTree, const char * pszFilename );
00365 SHPTree SHPAPI_CALL
00366 SHPReadTree( const char * pszFilename );
00367
00368 int SHPAPI_CALL
00369 SHPTreeAddObject( SHPTree * hTree, SHPObject * psObject );
00370 int SHPAPI_CALL
00371 SHPTreeAddShapeId( SHPTree * hTree, SHPObject * psObject );
00372 int SHPAPI_CALL
00373 SHPTreeRemoveShapeId( SHPTree * hTree, int nShapeId );
00374
00375 void SHPAPI_CALL
00376 SHPTreeTrimExtraNodes( SHPTree * hTree );
00377
00378 int SHPAPI_CALL1(*)
00379 SHPTreeFindLikelyShapes( SHPTree * hTree,
00380 double * padfBoundsMin,
00381 double * padfBoundsMax,
00382 int * );
00383 int SHPAPI_CALL
00384 SHPCheckBoundsOverlap( double *, double *, double *, double *, int );
00385
00386
00387
00388
00389 typedef struct
00390 {
00391 FILE *fp;
00392
00393 int nRecords;
00394
00395 int nRecordLength;
00396 int nHeaderLength;
00397 int nFields;
00398 int *panFieldOffset;
00399 int *panFieldSize;
00400 int *panFieldDecimals;
00401 char *pachFieldType;
00402
00403 char *pszHeader;
00404
00405 int nCurrentRecord;
00406 int bCurrentRecordModified;
00407 char *pszCurrentRecord;
00408
00409 int bNoHeader;
00410 int bUpdated;
00411 } DBFInfo;
00412
00413 typedef DBFInfo * DBFHandle;
00414
00415 typedef enum {
00416 FTString,
00417 FTInteger,
00418 FTDouble,
00419 FTLogical,
00420 FTInvalid,
00421 FTDate,
00422 } DBFFieldType;
00423
00424 #define XBASE_FLDHDR_SZ 32
00425
00426 DBFHandle SHPAPI_CALL
00427 DBFOpen( const char * pszDBFFile, const char * pszAccess );
00428 DBFHandle SHPAPI_CALL
00429 DBFCreate( const char * pszDBFFile );
00430
00431 int SHPAPI_CALL
00432 DBFGetFieldCount( DBFHandle psDBF );
00433 int SHPAPI_CALL
00434 DBFGetRecordCount( DBFHandle psDBF );
00435 int SHPAPI_CALL
00436 DBFAddField( DBFHandle hDBF, const char * pszFieldName,
00437 DBFFieldType eType, int nWidth, int nDecimals );
00438
00439 DBFFieldType SHPAPI_CALL
00440 DBFGetFieldInfo( DBFHandle psDBF, int iField,
00441 char * pszFieldName, int * pnWidth, int * pnDecimals );
00442
00443 int SHPAPI_CALL
00444 DBFGetFieldIndex(DBFHandle psDBF, const char *pszFieldName);
00445
00446 int SHPAPI_CALL
00447 DBFReadIntegerAttribute( DBFHandle hDBF, int iShape, int iField );
00448 double SHPAPI_CALL
00449 DBFReadDoubleAttribute( DBFHandle hDBF, int iShape, int iField );
00450 const char SHPAPI_CALL1(*)
00451 DBFReadStringAttribute( DBFHandle hDBF, int iShape, int iField );
00452 const char SHPAPI_CALL1(*)
00453 DBFReadDatettribute( DBFHandle hDBF, int iShape, int iField );
00454 const char SHPAPI_CALL1(*)
00455 DBFReadLogicalAttribute( DBFHandle hDBF, int iShape, int iField );
00456 int SHPAPI_CALL
00457 DBFIsAttributeNULL( DBFHandle hDBF, int iShape, int iField );
00458
00459 int SHPAPI_CALL
00460 DBFWriteIntegerAttribute( DBFHandle hDBF, int iShape, int iField,
00461 int nFieldValue );
00462 int SHPAPI_CALL
00463 DBFWriteDoubleAttribute( DBFHandle hDBF, int iShape, int iField,
00464 double dFieldValue );
00465 int SHPAPI_CALL
00466 DBFWriteStringAttribute( DBFHandle hDBF, int iShape, int iField,
00467 const char * pszFieldValue );
00468 int SHPAPI_CALL
00469 DBFWriteDateAttribute( DBFHandle hDBF, int iShape, int iField,
00470 const char * pszFieldValue );
00471 int SHPAPI_CALL
00472 DBFWriteNULLAttribute( DBFHandle hDBF, int iShape, int iField );
00473
00474 int SHPAPI_CALL
00475 DBFWriteLogicalAttribute( DBFHandle hDBF, int iShape, int iField,
00476 const char lFieldValue);
00477 int SHPAPI_CALL
00478 DBFWriteAttributeDirectly(DBFHandle psDBF, int hEntity, int iField,
00479 void * pValue );
00480 const char SHPAPI_CALL1(*)
00481 DBFReadTuple(DBFHandle psDBF, int hEntity );
00482 int SHPAPI_CALL
00483 DBFWriteTuple(DBFHandle psDBF, int hEntity, void * pRawTuple );
00484
00485 DBFHandle SHPAPI_CALL
00486 DBFCloneEmpty(DBFHandle psDBF, const char * pszFilename );
00487
00488 void SHPAPI_CALL
00489 DBFClose( DBFHandle hDBF );
00490 char SHPAPI_CALL
00491 DBFGetNativeFieldType( DBFHandle hDBF, int iField );
00492
00493 #ifdef __cplusplus
00494 }
00495 #endif
00496
00497 #endif