1
#ifndef _SHAPEFILE_H_INCLUDED
2
#define _SHAPEFILE_H_INCLUDED
4
/******************************************************************************
5
* $Id: shapefile.h 1155 2004-04-05 15:39:45Z timlinux $
8
* Purpose: Primary include file for Shapelib.
9
* Author: Frank Warmerdam, warmerda@home.com
11
******************************************************************************
12
* Copyright (c) 1999, Frank Warmerdam
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.
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:
27
* The above copyright notice and this permission notice shall be included
28
* in all copies or substantial portions of the Software.
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
******************************************************************************
40
* Revision 1.1 2004/04/05 15:39:45 timlinux
41
* Initial commit of new plugin to build graticules - not working yet! And thus not added to higher level makefiles yet.
43
* Revision 1.1 2004/03/31 11:54:03 jobi
45
* ** renamed plugins/grid_maker/shapefil.h to shapefile.h
47
* Revision 1.1 2004/03/22 23:38:26 timlinux
48
* This is a c++ first draft of a port of a perl script by Schuyler to import Garmin gps dump files as a shapefile. The resulting imported file will be displayed in the map view. At the moment it only generates a point layer of the waypoints but a future version will generate polylines and perhaps polygons too using similar logic to that used by Shuylers perl stuff. Note this plugin is still under construction and I am commiting it mainly so that other developers can assist me when I get stuck. Also note that the plugins Makefile builds a standalone app based on the plugin gui that can be run separately from qgis.
50
* Revision 1.15 2000/02/16 16:03:51 warmerda
51
* added null shape support
53
* Revision 1.14 1999/11/05 14:12:05 warmerda
54
* updated license terms
56
* Revision 1.13 1999/06/02 18:24:21 warmerda
59
* Revision 1.12 1999/06/02 17:56:12 warmerda
60
* added quad'' subnode support for trees
62
* Revision 1.11 1999/05/18 19:11:11 warmerda
63
* Added example searching capability
65
* Revision 1.10 1999/05/18 17:49:38 warmerda
66
* added initial quadtree support
68
* Revision 1.9 1999/05/11 03:19:28 warmerda
69
* added new Tuple api, and improved extension handling - add from candrsn
71
* Revision 1.8 1999/03/23 17:22:27 warmerda
72
* Added extern "C" protection for C++ users of shapefil.h.
74
* Revision 1.7 1998/12/31 15:31:07 warmerda
75
* Added the TRIM_DBF_WHITESPACE and DISABLE_MULTIPATCH_MEASURE options.
77
* Revision 1.6 1998/12/03 15:48:15 warmerda
78
* Added SHPCalculateExtents().
80
* Revision 1.5 1998/11/09 20:57:16 warmerda
81
* Altered SHPGetInfo() call.
83
* Revision 1.4 1998/11/09 20:19:33 warmerda
84
* Added 3D support, and use of SHPObject.
86
* Revision 1.3 1995/08/23 02:24:05 warmerda
87
* Added support for reading bounds.
89
* Revision 1.2 1995/08/04 03:17:39 warmerda
104
/************************************************************************/
105
/* Configuration options. */
106
/************************************************************************/
108
/* -------------------------------------------------------------------- */
109
/* Should the DBFReadStringAttribute() strip leading and */
110
/* trailing white space? */
111
/* -------------------------------------------------------------------- */
112
#define TRIM_DBF_WHITESPACE
114
/* -------------------------------------------------------------------- */
115
/* Should we write measure values to the Multipatch object? */
116
/* Reportedly ArcView crashes if we do write it, so for now it */
118
/* -------------------------------------------------------------------- */
119
#define DISABLE_MULTIPATCH_MEASURE
121
/************************************************************************/
123
/************************************************************************/
129
int nShapeType; /* SHPT_* */
131
int nFileSize; /* SHP file */
138
double adBoundsMin[4];
139
double adBoundsMax[4];
144
typedef SHPInfo * SHPHandle;
146
/* -------------------------------------------------------------------- */
147
/* Shape types (nSHPType) */
148
/* -------------------------------------------------------------------- */
152
#define SHPT_POLYGON 5
153
#define SHPT_MULTIPOINT 8
154
#define SHPT_POINTZ 11
156
#define SHPT_POLYGONZ 15
157
#define SHPT_MULTIPOINTZ 18
158
#define SHPT_POINTM 21
160
#define SHPT_POLYGONM 25
161
#define SHPT_MULTIPOINTM 28
162
#define SHPT_MULTIPATCH 31
165
/* -------------------------------------------------------------------- */
166
/* Part types - everything but SHPT_MULTIPATCH just uses */
168
/* -------------------------------------------------------------------- */
170
#define SHPP_TRISTRIP 0
171
#define SHPP_TRIFAN 1
172
#define SHPP_OUTERRING 2
173
#define SHPP_INNERRING 3
174
#define SHPP_FIRSTRING 4
177
/* -------------------------------------------------------------------- */
178
/* SHPObject - represents on shape (without attributes) read */
179
/* from the .shp file. */
180
/* -------------------------------------------------------------------- */
185
int nShapeId; /* -1 is unknown/unassigned */
208
/* -------------------------------------------------------------------- */
209
/* SHP API Prototypes */
210
/* -------------------------------------------------------------------- */
211
SHPHandle SHPOpen( const char * pszShapeFile, const char * pszAccess );
212
SHPHandle SHPCreate( const char * pszShapeFile, int nShapeType );
213
void SHPGetInfo( SHPHandle hSHP, int * pnEntities, int * pnShapeType,
214
double * padfMinBound, double * padfMaxBound );
216
SHPObject *SHPReadObject( SHPHandle hSHP, int iShape );
217
int SHPWriteObject( SHPHandle hSHP, int iShape, SHPObject * psObject );
219
void SHPDestroyObject( SHPObject * psObject );
220
void SHPComputeExtents( SHPObject * psObject );
221
SHPObject *SHPCreateObject( int nSHPType, int nShapeId,
222
int nParts, int * panPartStart, int * panPartType,
223
int nVertices, double * padfX, double * padfY,
224
double * padfZ, double * padfM );
225
SHPObject *SHPCreateSimpleObject( int nSHPType, int nVertices,
226
double * padfX, double * padfY, double * padfZ );
228
void SHPClose( SHPHandle hSHP );
230
const char *SHPTypeName( int nSHPType );
231
const char *SHPPartTypeName( int nPartType );
233
/* -------------------------------------------------------------------- */
234
/* Shape quadtree indexing API. */
235
/* -------------------------------------------------------------------- */
237
/* this can be two or four for binary or quad tree */
238
#define MAX_SUBNODE 4
240
typedef struct shape_tree_node
242
/* region covered by this node */
243
double adfBoundsMin[4];
244
double adfBoundsMax[4];
246
/* list of shapes stored at this node. The papsShapeObj pointers
247
or the whole list can be NULL */
250
SHPObject **papsShapeObj;
253
struct shape_tree_node *apsSubNode[MAX_SUBNODE];
267
SHPTree *SHPCreateTree( SHPHandle hSHP, int nDimension, int nMaxDepth,
268
double *padfBoundsMin, double *padfBoundsMax );
269
void SHPDestroyTree( SHPTree * hTree );
271
int SHPWriteTree( SHPTree *hTree, const char * pszFilename );
272
SHPTree SHPReadTree( const char * pszFilename );
274
int SHPTreeAddObject( SHPTree * hTree, SHPObject * psObject );
275
int SHPTreeAddShapeId( SHPTree * hTree, SHPObject * psObject );
276
int SHPTreeRemoveShapeId( SHPTree * hTree, int nShapeId );
278
void SHPTreeTrimExtraNodes( SHPTree * hTree );
280
int *SHPTreeFindLikelyShapes( SHPTree * hTree,
281
double * padfBoundsMin,
282
double * padfBoundsMax,
284
int SHPCheckBoundsOverlap( double *, double *, double *, double *, int );
286
/************************************************************************/
288
/************************************************************************/
300
int *panFieldDecimals;
306
int bCurrentRecordModified;
307
char *pszCurrentRecord;
313
typedef DBFInfo * DBFHandle;
322
#define XBASE_FLDHDR_SZ 32
324
DBFHandle DBFOpen( const char * pszDBFFile, const char * pszAccess );
325
DBFHandle DBFCreate( const char * pszDBFFile );
327
int DBFGetFieldCount( DBFHandle psDBF );
328
int DBFGetRecordCount( DBFHandle psDBF );
329
int DBFAddField( DBFHandle hDBF, const char * pszFieldName,
330
DBFFieldType eType, int nWidth, int nDecimals );
332
DBFFieldType DBFGetFieldInfo( DBFHandle psDBF, int iField,
334
int * pnWidth, int * pnDecimals );
336
int DBFReadIntegerAttribute( DBFHandle hDBF, int iShape, int iField );
337
double DBFReadDoubleAttribute( DBFHandle hDBF, int iShape, int iField );
338
const char *DBFReadStringAttribute( DBFHandle hDBF, int iShape, int iField );
340
int DBFWriteIntegerAttribute( DBFHandle hDBF, int iShape, int iField,
342
int DBFWriteDoubleAttribute( DBFHandle hDBF, int iShape, int iField,
343
double dFieldValue );
344
int DBFWriteStringAttribute( DBFHandle hDBF, int iShape, int iField,
345
const char * pszFieldValue );
347
const char *DBFReadTuple(DBFHandle psDBF, int hEntity );
348
int DBFWriteTuple(DBFHandle psDBF, int hEntity, void * pRawTuple );
350
DBFHandle DBFCloneEmpty(DBFHandle psDBF, const char * pszFilename );
352
void DBFClose( DBFHandle hDBF );
358
#endif /* ndef _SHAPEFILE_H_INCLUDED */