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 #endif
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135 #define TRIM_DBF_WHITESPACE
00136
00137
00138
00139
00140
00141
00142 #define DISABLE_MULTIPATCH_MEASURE
00143
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 #ifdef SHAPELIB_DLLEXPORT
00174 # define SHPAPI_CALL __declspec(dllexport)
00175 # define SHPAPI_CALL1(x) __declspec(dllexport) x
00176 #endif
00177
00178 #ifndef SHPAPI_CALL
00179 # define SHPAPI_CALL
00180 #endif
00181
00182 #ifndef SHPAPI_CALL1
00183 # define SHPAPI_CALL1(x) x SHPAPI_CALL
00184 #endif
00185
00186
00187
00188
00189 typedef struct
00190 {
00191 FILE *fpSHP;
00192 FILE *fpSHX;
00193
00194 int nShapeType;
00195
00196 int nFileSize;
00197
00198 int nRecords;
00199 int nMaxRecords;
00200 int *panRecOffset;
00201 int *panRecSize;
00202
00203 double adBoundsMin[4];
00204 double adBoundsMax[4];
00205
00206 int bUpdated;
00207
00208 unsigned char *pabyRec;
00209 int nBufSize;
00210 } SHPInfo;
00211
00212 typedef SHPInfo * SHPHandle;
00213
00214
00215
00216
00217 #define SHPT_NULL 0
00218 #define SHPT_POINT 1
00219 #define SHPT_ARC 3
00220 #define SHPT_POLYGON 5
00221 #define SHPT_MULTIPOINT 8
00222 #define SHPT_POINTZ 11
00223 #define SHPT_ARCZ 13
00224 #define SHPT_POLYGONZ 15
00225 #define SHPT_MULTIPOINTZ 18
00226 #define SHPT_POINTM 21
00227 #define SHPT_ARCM 23
00228 #define SHPT_POLYGONM 25
00229 #define SHPT_MULTIPOINTM 28
00230 #define SHPT_MULTIPATCH 31
00231
00232
00233
00234
00235
00236
00237
00238 #define SHPP_TRISTRIP 0
00239 #define SHPP_TRIFAN 1
00240 #define SHPP_OUTERRING 2
00241 #define SHPP_INNERRING 3
00242 #define SHPP_FIRSTRING 4
00243 #define SHPP_RING 5
00244
00245
00246
00247
00248
00249 typedef struct
00250 {
00251 int nSHPType;
00252
00253 int nShapeId;
00254
00255 int nParts;
00256 int *panPartStart;
00257 int *panPartType;
00258
00259 int nVertices;
00260 double *padfX;
00261 double *padfY;
00262 double *padfZ;
00263 double *padfM;
00264
00265 double dfXMin;
00266 double dfYMin;
00267 double dfZMin;
00268 double dfMMin;
00269
00270 double dfXMax;
00271 double dfYMax;
00272 double dfZMax;
00273 double dfMMax;
00274 } SHPObject;
00275
00276
00277
00278
00279 SHPHandle SHPAPI_CALL
00280 SHPOpen( const char * pszShapeFile, const char * pszAccess );
00281 SHPHandle SHPAPI_CALL
00282 SHPCreate( const char * pszShapeFile, int nShapeType );
00283 void SHPAPI_CALL
00284 SHPGetInfo( SHPHandle hSHP, int * pnEntities, int * pnShapeType,
00285 double * padfMinBound, double * padfMaxBound );
00286
00287 SHPObject SHPAPI_CALL1(*)
00288 SHPReadObject( SHPHandle hSHP, int iShape );
00289 int SHPAPI_CALL
00290 SHPWriteObject( SHPHandle hSHP, int iShape, SHPObject * psObject );
00291
00292 void SHPAPI_CALL
00293 SHPDestroyObject( SHPObject * psObject );
00294 void SHPAPI_CALL
00295 SHPComputeExtents( SHPObject * psObject );
00296 SHPObject SHPAPI_CALL1(*)
00297 SHPCreateObject( int nSHPType, int nShapeId,
00298 int nParts, int * panPartStart, int * panPartType,
00299 int nVertices, double * padfX, double * padfY,
00300 double * padfZ, double * padfM );
00301 SHPObject SHPAPI_CALL1(*)
00302 SHPCreateSimpleObject( int nSHPType, int nVertices,
00303 double * padfX, double * padfY, double * padfZ );
00304
00305 int SHPAPI_CALL
00306 SHPRewindObject( SHPHandle hSHP, SHPObject * psObject );
00307
00308 void SHPAPI_CALL
00309 SHPClose( SHPHandle hSHP );
00310
00311 const char SHPAPI_CALL1(*)
00312 SHPTypeName( int nSHPType );
00313 const char SHPAPI_CALL1(*)
00314 SHPPartTypeName( int nPartType );
00315
00316
00317
00318
00319
00320
00321 #define MAX_SUBNODE 4
00322
00323 typedef struct shape_tree_node
00324 {
00325
00326 double adfBoundsMin[4];
00327 double adfBoundsMax[4];
00328
00329
00330
00331 int nShapeCount;
00332 int *panShapeIds;
00333 SHPObject **papsShapeObj;
00334
00335 int nSubNodes;
00336 struct shape_tree_node *apsSubNode[MAX_SUBNODE];
00337
00338 } SHPTreeNode;
00339
00340 typedef struct
00341 {
00342 SHPHandle hSHP;
00343
00344 int nMaxDepth;
00345 int nDimension;
00346
00347 SHPTreeNode *psRoot;
00348 } SHPTree;
00349
00350 SHPTree SHPAPI_CALL1(*)
00351 SHPCreateTree( SHPHandle hSHP, int nDimension, int nMaxDepth,
00352 double *padfBoundsMin, double *padfBoundsMax );
00353 void SHPAPI_CALL
00354 SHPDestroyTree( SHPTree * hTree );
00355
00356 int SHPAPI_CALL
00357 SHPWriteTree( SHPTree *hTree, const char * pszFilename );
00358 SHPTree SHPAPI_CALL
00359 SHPReadTree( const char * pszFilename );
00360
00361 int SHPAPI_CALL
00362 SHPTreeAddObject( SHPTree * hTree, SHPObject * psObject );
00363 int SHPAPI_CALL
00364 SHPTreeAddShapeId( SHPTree * hTree, SHPObject * psObject );
00365 int SHPAPI_CALL
00366 SHPTreeRemoveShapeId( SHPTree * hTree, int nShapeId );
00367
00368 void SHPAPI_CALL
00369 SHPTreeTrimExtraNodes( SHPTree * hTree );
00370
00371 int SHPAPI_CALL1(*)
00372 SHPTreeFindLikelyShapes( SHPTree * hTree,
00373 double * padfBoundsMin,
00374 double * padfBoundsMax,
00375 int * );
00376 int SHPAPI_CALL
00377 SHPCheckBoundsOverlap( double *, double *, double *, double *, int );
00378
00379
00380
00381
00382 typedef struct
00383 {
00384 FILE *fp;
00385
00386 int nRecords;
00387
00388 int nRecordLength;
00389 int nHeaderLength;
00390 int nFields;
00391 int *panFieldOffset;
00392 int *panFieldSize;
00393 int *panFieldDecimals;
00394 char *pachFieldType;
00395
00396 char *pszHeader;
00397
00398 int nCurrentRecord;
00399 int bCurrentRecordModified;
00400 char *pszCurrentRecord;
00401
00402 int bNoHeader;
00403 int bUpdated;
00404 } DBFInfo;
00405
00406 typedef DBFInfo * DBFHandle;
00407
00408 typedef enum {
00409 FTString,
00410 FTInteger,
00411 FTDouble,
00412 FTLogical,
00413 FTInvalid
00414 } DBFFieldType;
00415
00416 #define XBASE_FLDHDR_SZ 32
00417
00418 DBFHandle SHPAPI_CALL
00419 DBFOpen( const char * pszDBFFile, const char * pszAccess );
00420 DBFHandle SHPAPI_CALL
00421 DBFCreate( const char * pszDBFFile );
00422
00423 int SHPAPI_CALL
00424 DBFGetFieldCount( DBFHandle psDBF );
00425 int SHPAPI_CALL
00426 DBFGetRecordCount( DBFHandle psDBF );
00427 int SHPAPI_CALL
00428 DBFAddField( DBFHandle hDBF, const char * pszFieldName,
00429 DBFFieldType eType, int nWidth, int nDecimals );
00430
00431 DBFFieldType SHPAPI_CALL
00432 DBFGetFieldInfo( DBFHandle psDBF, int iField,
00433 char * pszFieldName, int * pnWidth, int * pnDecimals );
00434
00435 int SHPAPI_CALL
00436 DBFGetFieldIndex(DBFHandle psDBF, const char *pszFieldName);
00437
00438 int SHPAPI_CALL
00439 DBFReadIntegerAttribute( DBFHandle hDBF, int iShape, int iField );
00440 double SHPAPI_CALL
00441 DBFReadDoubleAttribute( DBFHandle hDBF, int iShape, int iField );
00442 const char SHPAPI_CALL1(*)
00443 DBFReadStringAttribute( DBFHandle hDBF, int iShape, int iField );
00444 const char SHPAPI_CALL1(*)
00445 DBFReadLogicalAttribute( DBFHandle hDBF, int iShape, int iField );
00446 int SHPAPI_CALL
00447 DBFIsAttributeNULL( DBFHandle hDBF, int iShape, int iField );
00448
00449 int SHPAPI_CALL
00450 DBFWriteIntegerAttribute( DBFHandle hDBF, int iShape, int iField,
00451 int nFieldValue );
00452 int SHPAPI_CALL
00453 DBFWriteDoubleAttribute( DBFHandle hDBF, int iShape, int iField,
00454 double dFieldValue );
00455 int SHPAPI_CALL
00456 DBFWriteStringAttribute( DBFHandle hDBF, int iShape, int iField,
00457 const char * pszFieldValue );
00458 int SHPAPI_CALL
00459 DBFWriteNULLAttribute( DBFHandle hDBF, int iShape, int iField );
00460
00461 int SHPAPI_CALL
00462 DBFWriteLogicalAttribute( DBFHandle hDBF, int iShape, int iField,
00463 const char lFieldValue);
00464 int SHPAPI_CALL
00465 DBFWriteAttributeDirectly(DBFHandle psDBF, int hEntity, int iField,
00466 void * pValue );
00467 const char SHPAPI_CALL1(*)
00468 DBFReadTuple(DBFHandle psDBF, int hEntity );
00469 int SHPAPI_CALL
00470 DBFWriteTuple(DBFHandle psDBF, int hEntity, void * pRawTuple );
00471
00472 DBFHandle SHPAPI_CALL
00473 DBFCloneEmpty(DBFHandle psDBF, const char * pszFilename );
00474
00475 void SHPAPI_CALL
00476 DBFClose( DBFHandle hDBF );
00477 char SHPAPI_CALL
00478 DBFGetNativeFieldType( DBFHandle hDBF, int iField );
00479
00480 #ifdef __cplusplus
00481 }
00482 #endif
00483
00484 #endif