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 #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
00130
00131
00132
00133
00134
00135
00136 #define TRIM_DBF_WHITESPACE
00137
00138
00139
00140
00141
00142
00143 #define DISABLE_MULTIPATCH_MEASURE
00144
00145
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 #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
00189
00190 typedef struct
00191 {
00192 FILE *fpSHP;
00193 FILE *fpSHX;
00194
00195 int nShapeType;
00196
00197 int nFileSize;
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
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
00236
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
00248
00249
00250 typedef struct
00251 {
00252 int nSHPType;
00253
00254 int nShapeId;
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
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
00319
00320
00321
00322 #define MAX_SUBNODE 4
00323
00324 typedef struct shape_tree_node
00325 {
00326
00327 double adfBoundsMin[4];
00328 double adfBoundsMax[4];
00329
00330
00331
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
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