shapefil.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712
  1. #ifndef SHAPEFILE_H_INCLUDED
  2. #define SHAPEFILE_H_INCLUDED
  3. /******************************************************************************
  4. * $Id$
  5. *
  6. * Project: Shapelib
  7. * Purpose: Primary include file for Shapelib.
  8. * Author: Frank Warmerdam, warmerdam@pobox.com
  9. *
  10. ******************************************************************************
  11. * Copyright (c) 1999, Frank Warmerdam
  12. * Copyright (c) 2012-2013, Even Rouault <even dot rouault at mines-paris dot org>
  13. *
  14. * This software is available under the following "MIT Style" license,
  15. * or at the option of the licensee under the LGPL (see LICENSE.LGPL). This
  16. * option is discussed in more detail in shapelib.html.
  17. *
  18. * --
  19. *
  20. * Permission is hereby granted, free of charge, to any person obtaining a
  21. * copy of this software and associated documentation files (the "Software"),
  22. * to deal in the Software without restriction, including without limitation
  23. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  24. * and/or sell copies of the Software, and to permit persons to whom the
  25. * Software is furnished to do so, subject to the following conditions:
  26. *
  27. * The above copyright notice and this permission notice shall be included
  28. * in all copies or substantial portions of the Software.
  29. *
  30. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  31. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  32. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  33. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  34. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  35. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  36. * DEALINGS IN THE SOFTWARE.
  37. ******************************************************************************
  38. *
  39. * $Log: shapefil.h,v $
  40. * Revision 1.52 2011-12-11 22:26:46 fwarmerdam
  41. * upgrade .qix access code to use SAHooks (gdal #3365)
  42. *
  43. * Revision 1.51 2011-07-24 05:59:25 fwarmerdam
  44. * minimize use of CPLError in favor of SAHooks.Error()
  45. *
  46. * Revision 1.50 2011-05-13 17:35:17 fwarmerdam
  47. * added DBFReorderFields() and DBFAlterFields() functions (from Even)
  48. *
  49. * Revision 1.49 2011-04-16 14:38:21 fwarmerdam
  50. * avoid warnings with gcc on SHP_CVSID
  51. *
  52. * Revision 1.48 2010-08-27 23:42:52 fwarmerdam
  53. * add SHPAPI_CALL attribute in code
  54. *
  55. * Revision 1.47 2010-01-28 11:34:34 fwarmerdam
  56. * handle the shape file length limits more gracefully (#3236)
  57. *
  58. * Revision 1.46 2008-11-12 14:28:15 fwarmerdam
  59. * DBFCreateField() now works on files with records
  60. *
  61. * Revision 1.45 2008/11/11 17:47:10 fwarmerdam
  62. * added DBFDeleteField() function
  63. *
  64. * Revision 1.44 2008/01/16 20:05:19 bram
  65. * Add file hooks that accept UTF-8 encoded filenames on some platforms. Use SASetupUtf8Hooks
  66. * tosetup the hooks and check SHPAPI_UTF8_HOOKS for its availability. Currently, this
  67. * is only available on the Windows platform that decodes the UTF-8 filenames to wide
  68. * character strings and feeds them to _wfopen and _wremove.
  69. *
  70. * Revision 1.43 2008/01/10 16:35:30 fwarmerdam
  71. * avoid _ prefix on #defined symbols (bug 1840)
  72. *
  73. * Revision 1.42 2007/12/18 18:28:14 bram
  74. * - create hook for client specific atof (bugzilla ticket 1615)
  75. * - check for NULL handle before closing cpCPG file, and close after reading.
  76. *
  77. * Revision 1.41 2007/12/15 20:25:32 bram
  78. * dbfopen.c now reads the Code Page information from the DBF file, and exports
  79. * this information as a string through the DBFGetCodePage function. This is
  80. * either the number from the LDID header field ("LDID/<number>") or as the
  81. * content of an accompanying .CPG file. When creating a DBF file, the code can
  82. * be set using DBFCreateEx.
  83. *
  84. * Revision 1.40 2007/12/06 07:00:25 fwarmerdam
  85. * dbfopen now using SAHooks for fileio
  86. *
  87. * Revision 1.39 2007/12/04 20:37:56 fwarmerdam
  88. * preliminary implementation of hooks api for io and errors
  89. *
  90. * Revision 1.38 2007/11/21 22:39:56 fwarmerdam
  91. * close shx file in readonly mode (GDAL #1956)
  92. *
  93. * Revision 1.37 2007/10/27 03:31:14 fwarmerdam
  94. * limit default depth of tree to 12 levels (gdal ticket #1594)
  95. *
  96. * Revision 1.36 2007/09/10 23:33:15 fwarmerdam
  97. * Upstreamed support for visibility flag in SHPAPI_CALL for the needs
  98. * of GDAL (gdal ticket #1810).
  99. *
  100. * Revision 1.35 2007/09/03 19:48:10 fwarmerdam
  101. * move DBFReadAttribute() static dDoubleField into dbfinfo
  102. *
  103. * Revision 1.34 2006/06/17 15:33:32 fwarmerdam
  104. * added pszWorkField - bug 1202 (rso)
  105. *
  106. * Revision 1.33 2006/02/15 01:14:30 fwarmerdam
  107. * added DBFAddNativeFieldType
  108. *
  109. * Revision 1.32 2006/01/26 15:07:32 fwarmerdam
  110. * add bMeasureIsUsed flag from Craig Bruce: Bug 1249
  111. *
  112. * Revision 1.31 2006/01/05 01:27:27 fwarmerdam
  113. * added dbf deletion mark/fetch
  114. *
  115. * Revision 1.30 2005/01/03 22:30:13 fwarmerdam
  116. * added support for saved quadtrees
  117. *
  118. * Revision 1.29 2004/09/26 20:09:35 fwarmerdam
  119. * avoid rcsid warnings
  120. *
  121. * Revision 1.28 2003/12/29 06:02:18 fwarmerdam
  122. * added cpl_error.h option
  123. *
  124. * Revision 1.27 2003/04/21 18:30:37 warmerda
  125. * added header write/update public methods
  126. *
  127. * Revision 1.26 2002/09/29 00:00:08 warmerda
  128. * added FTLogical and logical attribute read/write calls
  129. *
  130. * Revision 1.25 2002/05/07 13:46:30 warmerda
  131. * added DBFWriteAttributeDirectly().
  132. *
  133. * Revision 1.24 2002/04/10 16:59:54 warmerda
  134. * added SHPRewindObject
  135. *
  136. * Revision 1.23 2002/01/15 14:36:07 warmerda
  137. * updated email address
  138. *
  139. * Revision 1.22 2002/01/15 14:32:00 warmerda
  140. * try to improve SHPAPI_CALL docs
  141. */
  142. #include <stdio.h>
  143. #ifdef USE_DBMALLOC
  144. #include <dbmalloc.h>
  145. #endif
  146. #ifdef USE_CPL
  147. #include "cpl_conv.h"
  148. #endif
  149. #ifdef __cplusplus
  150. extern "C" {
  151. #endif
  152. /************************************************************************/
  153. /* Configuration options. */
  154. /************************************************************************/
  155. /* -------------------------------------------------------------------- */
  156. /* Should the DBFReadStringAttribute() strip leading and */
  157. /* trailing white space? */
  158. /* -------------------------------------------------------------------- */
  159. #define TRIM_DBF_WHITESPACE
  160. /* -------------------------------------------------------------------- */
  161. /* Should we write measure values to the Multipatch object? */
  162. /* Reportedly ArcView crashes if we do write it, so for now it */
  163. /* is disabled. */
  164. /* -------------------------------------------------------------------- */
  165. #define DISABLE_MULTIPATCH_MEASURE
  166. /* -------------------------------------------------------------------- */
  167. /* SHPAPI_CALL */
  168. /* */
  169. /* The following two macros are present to allow forcing */
  170. /* various calling conventions on the Shapelib API. */
  171. /* */
  172. /* To force __stdcall conventions (needed to call Shapelib */
  173. /* from Visual Basic and/or Dephi I believe) the makefile could */
  174. /* be modified to define: */
  175. /* */
  176. /* /DSHPAPI_CALL=__stdcall */
  177. /* */
  178. /* If it is desired to force export of the Shapelib API without */
  179. /* using the shapelib.def file, use the following definition. */
  180. /* */
  181. /* /DSHAPELIB_DLLEXPORT */
  182. /* */
  183. /* To get both at once it will be necessary to hack this */
  184. /* include file to define: */
  185. /* */
  186. /* #define SHPAPI_CALL __declspec(dllexport) __stdcall */
  187. /* #define SHPAPI_CALL1 __declspec(dllexport) * __stdcall */
  188. /* */
  189. /* The complexity of the situation is partly caused by the */
  190. /* peculiar requirement of Visual C++ that __stdcall appear */
  191. /* after any "*"'s in the return value of a function while the */
  192. /* __declspec(dllexport) must appear before them. */
  193. /* -------------------------------------------------------------------- */
  194. #ifdef SHAPELIB_DLLEXPORT
  195. # define SHPAPI_CALL __declspec(dllexport)
  196. # define SHPAPI_CALL1(x) __declspec(dllexport) x
  197. #endif
  198. #ifndef SHPAPI_CALL
  199. # if defined(USE_GCC_VISIBILITY_FLAG)
  200. # define SHPAPI_CALL __attribute__ ((visibility("default")))
  201. # define SHPAPI_CALL1(x) __attribute__ ((visibility("default"))) x
  202. # else
  203. # define SHPAPI_CALL
  204. # endif
  205. #endif
  206. #ifndef SHPAPI_CALL1
  207. # define SHPAPI_CALL1(x) x SHPAPI_CALL
  208. #endif
  209. /* -------------------------------------------------------------------- */
  210. /* Macros for controlling CVSID and ensuring they don't appear */
  211. /* as unreferenced variables resulting in lots of warnings. */
  212. /* -------------------------------------------------------------------- */
  213. #ifndef DISABLE_CVSID
  214. # if defined(__GNUC__) && __GNUC__ >= 4
  215. # define SHP_CVSID(string) static const char cpl_cvsid[] __attribute__((used)) = string;
  216. # else
  217. # define SHP_CVSID(string) static const char cpl_cvsid[] = string; \
  218. static const char *cvsid_aw() { return( cvsid_aw() ? NULL : cpl_cvsid ); }
  219. # endif
  220. #else
  221. # define SHP_CVSID(string)
  222. #endif
  223. /* -------------------------------------------------------------------- */
  224. /* On some platforms, additional file IO hooks are defined that */
  225. /* UTF-8 encoded filenames Unicode filenames */
  226. /* -------------------------------------------------------------------- */
  227. #if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
  228. # define SHPAPI_WINDOWS
  229. # define SHPAPI_UTF8_HOOKS
  230. #endif
  231. /* -------------------------------------------------------------------- */
  232. /* IO/Error hook functions. */
  233. /* -------------------------------------------------------------------- */
  234. typedef int *SAFile;
  235. #ifndef SAOffset
  236. typedef unsigned long SAOffset;
  237. #endif
  238. typedef struct {
  239. SAFile (*FOpen) ( const char *filename, const char *access);
  240. SAOffset (*FRead) ( void *p, SAOffset size, SAOffset nmemb, SAFile file);
  241. SAOffset (*FWrite)( void *p, SAOffset size, SAOffset nmemb, SAFile file);
  242. SAOffset (*FSeek) ( SAFile file, SAOffset offset, int whence );
  243. SAOffset (*FTell) ( SAFile file );
  244. int (*FFlush)( SAFile file );
  245. int (*FClose)( SAFile file );
  246. int (*Remove) ( const char *filename );
  247. void (*Error) ( const char *message );
  248. double (*Atof) ( const char *str );
  249. } SAHooks;
  250. void SHPAPI_CALL SASetupDefaultHooks( SAHooks *psHooks );
  251. #ifdef SHPAPI_UTF8_HOOKS
  252. void SHPAPI_CALL SASetupUtf8Hooks( SAHooks *psHooks );
  253. #endif
  254. /************************************************************************/
  255. /* SHP Support. */
  256. /************************************************************************/
  257. typedef struct tagSHPObject SHPObject;
  258. typedef struct
  259. {
  260. SAHooks sHooks;
  261. SAFile fpSHP;
  262. SAFile fpSHX;
  263. int nShapeType; /* SHPT_* */
  264. unsigned int nFileSize; /* SHP file */
  265. int nRecords;
  266. int nMaxRecords;
  267. unsigned int *panRecOffset;
  268. unsigned int *panRecSize;
  269. double adBoundsMin[4];
  270. double adBoundsMax[4];
  271. int bUpdated;
  272. unsigned char *pabyRec;
  273. int nBufSize;
  274. int bFastModeReadObject;
  275. unsigned char *pabyObjectBuf;
  276. int nObjectBufSize;
  277. SHPObject* psCachedObject;
  278. } SHPInfo;
  279. typedef SHPInfo * SHPHandle;
  280. /* -------------------------------------------------------------------- */
  281. /* Shape types (nSHPType) */
  282. /* -------------------------------------------------------------------- */
  283. #define SHPT_NULL 0
  284. #define SHPT_POINT 1
  285. #define SHPT_ARC 3
  286. #define SHPT_POLYGON 5
  287. #define SHPT_MULTIPOINT 8
  288. #define SHPT_POINTZ 11
  289. #define SHPT_ARCZ 13
  290. #define SHPT_POLYGONZ 15
  291. #define SHPT_MULTIPOINTZ 18
  292. #define SHPT_POINTM 21
  293. #define SHPT_ARCM 23
  294. #define SHPT_POLYGONM 25
  295. #define SHPT_MULTIPOINTM 28
  296. #define SHPT_MULTIPATCH 31
  297. /* -------------------------------------------------------------------- */
  298. /* Part types - everything but SHPT_MULTIPATCH just uses */
  299. /* SHPP_RING. */
  300. /* -------------------------------------------------------------------- */
  301. #define SHPP_TRISTRIP 0
  302. #define SHPP_TRIFAN 1
  303. #define SHPP_OUTERRING 2
  304. #define SHPP_INNERRING 3
  305. #define SHPP_FIRSTRING 4
  306. #define SHPP_RING 5
  307. /* -------------------------------------------------------------------- */
  308. /* SHPObject - represents on shape (without attributes) read */
  309. /* from the .shp file. */
  310. /* -------------------------------------------------------------------- */
  311. struct tagSHPObject
  312. {
  313. int nSHPType;
  314. int nShapeId; /* -1 is unknown/unassigned */
  315. int nParts;
  316. int *panPartStart;
  317. int *panPartType;
  318. int nVertices;
  319. double *padfX;
  320. double *padfY;
  321. double *padfZ;
  322. double *padfM;
  323. double dfXMin;
  324. double dfYMin;
  325. double dfZMin;
  326. double dfMMin;
  327. double dfXMax;
  328. double dfYMax;
  329. double dfZMax;
  330. double dfMMax;
  331. int bMeasureIsUsed;
  332. int bFastModeReadObject;
  333. };
  334. /* -------------------------------------------------------------------- */
  335. /* SHP API Prototypes */
  336. /* -------------------------------------------------------------------- */
  337. /* If pszAccess is read-only, the fpSHX field of the returned structure */
  338. /* will be NULL as it is not necessary to keep the SHX file open */
  339. SHPHandle SHPAPI_CALL
  340. SHPOpen( const char * pszShapeFile, const char * pszAccess );
  341. SHPHandle SHPAPI_CALL
  342. SHPOpenLL( const char *pszShapeFile, const char *pszAccess,
  343. SAHooks *psHooks );
  344. SHPHandle SHPAPI_CALL
  345. SHPOpenLLEx( const char *pszShapeFile, const char *pszAccess,
  346. SAHooks *psHooks, int bRestoreSHX );
  347. int SHPAPI_CALL
  348. SHPRestoreSHX( const char *pszShapeFile, const char *pszAccess,
  349. SAHooks *psHooks );
  350. /* If setting bFastMode = TRUE, the content of SHPReadObject() is owned by the SHPHandle. */
  351. /* So you cannot have 2 valid instances of SHPReadObject() simultaneously. */
  352. /* The SHPObject padfZ and padfM members may be NULL depending on the geometry */
  353. /* type. It is illegal to free at hand any of the pointer members of the SHPObject structure */
  354. void SHPAPI_CALL SHPSetFastModeReadObject( SHPHandle hSHP, int bFastMode );
  355. SHPHandle SHPAPI_CALL
  356. SHPCreate( const char * pszShapeFile, int nShapeType );
  357. SHPHandle SHPAPI_CALL
  358. SHPCreateLL( const char * pszShapeFile, int nShapeType,
  359. SAHooks *psHooks );
  360. void SHPAPI_CALL
  361. SHPGetInfo( SHPHandle hSHP, int * pnEntities, int * pnShapeType,
  362. double * padfMinBound, double * padfMaxBound );
  363. SHPObject SHPAPI_CALL1(*)
  364. SHPReadObject( SHPHandle hSHP, int iShape );
  365. int SHPAPI_CALL
  366. SHPWriteObject( SHPHandle hSHP, int iShape, SHPObject * psObject );
  367. void SHPAPI_CALL
  368. SHPDestroyObject( SHPObject * psObject );
  369. void SHPAPI_CALL
  370. SHPComputeExtents( SHPObject * psObject );
  371. SHPObject SHPAPI_CALL1(*)
  372. SHPCreateObject( int nSHPType, int nShapeId, int nParts,
  373. const int * panPartStart, const int * panPartType,
  374. int nVertices,
  375. const double * padfX, const double * padfY,
  376. const double * padfZ, const double * padfM );
  377. SHPObject SHPAPI_CALL1(*)
  378. SHPCreateSimpleObject( int nSHPType, int nVertices,
  379. const double * padfX,
  380. const double * padfY,
  381. const double * padfZ );
  382. int SHPAPI_CALL
  383. SHPRewindObject( SHPHandle hSHP, SHPObject * psObject );
  384. void SHPAPI_CALL SHPClose( SHPHandle hSHP );
  385. void SHPAPI_CALL SHPWriteHeader( SHPHandle hSHP );
  386. const char SHPAPI_CALL1(*)
  387. SHPTypeName( int nSHPType );
  388. const char SHPAPI_CALL1(*)
  389. SHPPartTypeName( int nPartType );
  390. /* -------------------------------------------------------------------- */
  391. /* Shape quadtree indexing API. */
  392. /* -------------------------------------------------------------------- */
  393. /* this can be two or four for binary or quad tree */
  394. #define MAX_SUBNODE 4
  395. /* upper limit of tree levels for automatic estimation */
  396. #define MAX_DEFAULT_TREE_DEPTH 12
  397. typedef struct shape_tree_node
  398. {
  399. /* region covered by this node */
  400. double adfBoundsMin[4];
  401. double adfBoundsMax[4];
  402. /* list of shapes stored at this node. The papsShapeObj pointers
  403. or the whole list can be NULL */
  404. int nShapeCount;
  405. int *panShapeIds;
  406. SHPObject **papsShapeObj;
  407. int nSubNodes;
  408. struct shape_tree_node *apsSubNode[MAX_SUBNODE];
  409. } SHPTreeNode;
  410. typedef struct
  411. {
  412. SHPHandle hSHP;
  413. int nMaxDepth;
  414. int nDimension;
  415. int nTotalCount;
  416. SHPTreeNode *psRoot;
  417. } SHPTree;
  418. SHPTree SHPAPI_CALL1(*)
  419. SHPCreateTree( SHPHandle hSHP, int nDimension, int nMaxDepth,
  420. double *padfBoundsMin, double *padfBoundsMax );
  421. void SHPAPI_CALL
  422. SHPDestroyTree( SHPTree * hTree );
  423. int SHPAPI_CALL
  424. SHPWriteTree( SHPTree *hTree, const char * pszFilename );
  425. int SHPAPI_CALL
  426. SHPTreeAddShapeId( SHPTree * hTree, SHPObject * psObject );
  427. int SHPAPI_CALL
  428. SHPTreeRemoveShapeId( SHPTree * hTree, int nShapeId );
  429. void SHPAPI_CALL
  430. SHPTreeTrimExtraNodes( SHPTree * hTree );
  431. int SHPAPI_CALL1(*)
  432. SHPTreeFindLikelyShapes( SHPTree * hTree,
  433. double * padfBoundsMin,
  434. double * padfBoundsMax,
  435. int * );
  436. int SHPAPI_CALL
  437. SHPCheckBoundsOverlap( double *, double *, double *, double *, int );
  438. int SHPAPI_CALL1(*)
  439. SHPSearchDiskTree( FILE *fp,
  440. double *padfBoundsMin, double *padfBoundsMax,
  441. int *pnShapeCount );
  442. typedef struct SHPDiskTreeInfo* SHPTreeDiskHandle;
  443. SHPTreeDiskHandle SHPAPI_CALL
  444. SHPOpenDiskTree( const char* pszQIXFilename,
  445. SAHooks *psHooks );
  446. void SHPAPI_CALL
  447. SHPCloseDiskTree( SHPTreeDiskHandle hDiskTree );
  448. int SHPAPI_CALL1(*)
  449. SHPSearchDiskTreeEx( SHPTreeDiskHandle hDiskTree,
  450. double *padfBoundsMin, double *padfBoundsMax,
  451. int *pnShapeCount );
  452. int SHPAPI_CALL
  453. SHPWriteTreeLL(SHPTree *hTree, const char *pszFilename, SAHooks *psHooks );
  454. /* -------------------------------------------------------------------- */
  455. /* SBN Search API */
  456. /* -------------------------------------------------------------------- */
  457. typedef struct SBNSearchInfo* SBNSearchHandle;
  458. SBNSearchHandle SHPAPI_CALL
  459. SBNOpenDiskTree( const char* pszSBNFilename,
  460. SAHooks *psHooks );
  461. void SHPAPI_CALL
  462. SBNCloseDiskTree( SBNSearchHandle hSBN );
  463. int SHPAPI_CALL1(*)
  464. SBNSearchDiskTree( SBNSearchHandle hSBN,
  465. double *padfBoundsMin, double *padfBoundsMax,
  466. int *pnShapeCount );
  467. int SHPAPI_CALL1(*)
  468. SBNSearchDiskTreeInteger( SBNSearchHandle hSBN,
  469. int bMinX, int bMinY, int bMaxX, int bMaxY,
  470. int *pnShapeCount );
  471. void SHPAPI_CALL SBNSearchFreeIds( int* panShapeId );
  472. /************************************************************************/
  473. /* DBF Support. */
  474. /************************************************************************/
  475. typedef struct
  476. {
  477. SAHooks sHooks;
  478. SAFile fp;
  479. int nRecords;
  480. int nRecordLength;
  481. int nHeaderLength;
  482. int nFields;
  483. int *panFieldOffset;
  484. int *panFieldSize;
  485. int *panFieldDecimals;
  486. char *pachFieldType;
  487. char *pszHeader;
  488. int nCurrentRecord;
  489. int bCurrentRecordModified;
  490. char *pszCurrentRecord;
  491. int nWorkFieldLength;
  492. char *pszWorkField;
  493. int bNoHeader;
  494. int bUpdated;
  495. union
  496. {
  497. double dfDoubleField;
  498. int nIntField;
  499. } fieldValue;
  500. int iLanguageDriver;
  501. char *pszCodePage;
  502. int nUpdateYearSince1900; /* 0-255 */
  503. int nUpdateMonth; /* 1-12 */
  504. int nUpdateDay; /* 1-31 */
  505. } DBFInfo;
  506. typedef DBFInfo * DBFHandle;
  507. typedef enum {
  508. FTString,
  509. FTInteger,
  510. FTDouble,
  511. FTLogical,
  512. FTInvalid
  513. } DBFFieldType;
  514. #define XBASE_FLDHDR_SZ 32
  515. DBFHandle SHPAPI_CALL
  516. DBFOpen( const char * pszDBFFile, const char * pszAccess );
  517. DBFHandle SHPAPI_CALL
  518. DBFOpenLL( const char * pszDBFFile, const char * pszAccess,
  519. SAHooks *psHooks );
  520. DBFHandle SHPAPI_CALL
  521. DBFCreate( const char * pszDBFFile );
  522. DBFHandle SHPAPI_CALL
  523. DBFCreateEx( const char * pszDBFFile, const char * pszCodePage );
  524. DBFHandle SHPAPI_CALL
  525. DBFCreateLL( const char * pszDBFFile, const char * pszCodePage, SAHooks *psHooks );
  526. int SHPAPI_CALL
  527. DBFGetFieldCount( DBFHandle psDBF );
  528. int SHPAPI_CALL
  529. DBFGetRecordCount( DBFHandle psDBF );
  530. int SHPAPI_CALL
  531. DBFAddField( DBFHandle hDBF, const char * pszFieldName,
  532. DBFFieldType eType, int nWidth, int nDecimals );
  533. int SHPAPI_CALL
  534. DBFAddNativeFieldType( DBFHandle hDBF, const char * pszFieldName,
  535. char chType, int nWidth, int nDecimals );
  536. int SHPAPI_CALL
  537. DBFDeleteField( DBFHandle hDBF, int iField );
  538. int SHPAPI_CALL
  539. DBFReorderFields( DBFHandle psDBF, int* panMap );
  540. int SHPAPI_CALL
  541. DBFAlterFieldDefn( DBFHandle psDBF, int iField, const char * pszFieldName,
  542. char chType, int nWidth, int nDecimals );
  543. DBFFieldType SHPAPI_CALL
  544. DBFGetFieldInfo( DBFHandle psDBF, int iField,
  545. char * pszFieldName, int * pnWidth, int * pnDecimals );
  546. int SHPAPI_CALL
  547. DBFGetFieldIndex(DBFHandle psDBF, const char *pszFieldName);
  548. int SHPAPI_CALL
  549. DBFReadIntegerAttribute( DBFHandle hDBF, int iShape, int iField );
  550. double SHPAPI_CALL
  551. DBFReadDoubleAttribute( DBFHandle hDBF, int iShape, int iField );
  552. const char SHPAPI_CALL1(*)
  553. DBFReadStringAttribute( DBFHandle hDBF, int iShape, int iField );
  554. const char SHPAPI_CALL1(*)
  555. DBFReadLogicalAttribute( DBFHandle hDBF, int iShape, int iField );
  556. int SHPAPI_CALL
  557. DBFIsAttributeNULL( DBFHandle hDBF, int iShape, int iField );
  558. int SHPAPI_CALL
  559. DBFWriteIntegerAttribute( DBFHandle hDBF, int iShape, int iField,
  560. int nFieldValue );
  561. int SHPAPI_CALL
  562. DBFWriteDoubleAttribute( DBFHandle hDBF, int iShape, int iField,
  563. double dFieldValue );
  564. int SHPAPI_CALL
  565. DBFWriteStringAttribute( DBFHandle hDBF, int iShape, int iField,
  566. const char * pszFieldValue );
  567. int SHPAPI_CALL
  568. DBFWriteNULLAttribute( DBFHandle hDBF, int iShape, int iField );
  569. int SHPAPI_CALL
  570. DBFWriteLogicalAttribute( DBFHandle hDBF, int iShape, int iField,
  571. const char lFieldValue);
  572. int SHPAPI_CALL
  573. DBFWriteAttributeDirectly(DBFHandle psDBF, int hEntity, int iField,
  574. void * pValue );
  575. const char SHPAPI_CALL1(*)
  576. DBFReadTuple(DBFHandle psDBF, int hEntity );
  577. int SHPAPI_CALL
  578. DBFWriteTuple(DBFHandle psDBF, int hEntity, void * pRawTuple );
  579. int SHPAPI_CALL DBFIsRecordDeleted( DBFHandle psDBF, int iShape );
  580. int SHPAPI_CALL DBFMarkRecordDeleted( DBFHandle psDBF, int iShape,
  581. int bIsDeleted );
  582. DBFHandle SHPAPI_CALL
  583. DBFCloneEmpty(DBFHandle psDBF, const char * pszFilename );
  584. void SHPAPI_CALL
  585. DBFClose( DBFHandle hDBF );
  586. void SHPAPI_CALL
  587. DBFUpdateHeader( DBFHandle hDBF );
  588. char SHPAPI_CALL
  589. DBFGetNativeFieldType( DBFHandle hDBF, int iField );
  590. const char SHPAPI_CALL1(*)
  591. DBFGetCodePage(DBFHandle psDBF );
  592. void SHPAPI_CALL
  593. DBFSetLastModifiedDate( DBFHandle psDBF, int nYYSince1900, int nMM, int nDD );
  594. #ifdef __cplusplus
  595. }
  596. #endif
  597. #endif /* ndef SHAPEFILE_H_INCLUDED */