~ubuntu-branches/ubuntu/wily/qgis/wily

« back to all changes in this revision

Viewing changes to src/plugins/grid_maker/shapefile.h

  • Committer: Bazaar Package Importer
  • Author(s): Johan Van de Wauw
  • Date: 2010-07-11 20:23:24 UTC
  • mfrom: (3.1.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100711202324-5ktghxa7hracohmr
Tags: 1.4.0+12730-3ubuntu1
* Merge from Debian unstable (LP: #540941).
* Fix compilation issues with QT 4.7
* Add build-depends on libqt4-webkit-dev 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#ifndef _SHAPEFILE_H_INCLUDED
2
 
#define _SHAPEFILE_H_INCLUDED
3
 
 
4
 
/******************************************************************************
5
 
 * $Id: shapefile.h 1155 2004-04-05 15:39:45Z timlinux $
6
 
 *
7
 
 * Project:  Shapelib
8
 
 * Purpose:  Primary include file for Shapelib.
9
 
 * Author:   Frank Warmerdam, warmerda@home.com
10
 
 *
11
 
 ******************************************************************************
12
 
 * Copyright (c) 1999, Frank Warmerdam
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$
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.
42
 
 *
43
 
 * Revision 1.1  2004/03/31 11:54:03  jobi
44
 
 * ** fixed small bug
45
 
 * ** renamed plugins/grid_maker/shapefil.h to shapefile.h
46
 
 *
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.
49
 
 *
50
 
 * Revision 1.15  2000/02/16 16:03:51  warmerda
51
 
 * added null shape support
52
 
 *
53
 
 * Revision 1.14  1999/11/05 14:12:05  warmerda
54
 
 * updated license terms
55
 
 *
56
 
 * Revision 1.13  1999/06/02 18:24:21  warmerda
57
 
 * added trimming code
58
 
 *
59
 
 * Revision 1.12  1999/06/02 17:56:12  warmerda
60
 
 * added quad'' subnode support for trees
61
 
 *
62
 
 * Revision 1.11  1999/05/18 19:11:11  warmerda
63
 
 * Added example searching capability
64
 
 *
65
 
 * Revision 1.10  1999/05/18 17:49:38  warmerda
66
 
 * added initial quadtree support
67
 
 *
68
 
 * Revision 1.9  1999/05/11 03:19:28  warmerda
69
 
 * added new Tuple api, and improved extension handling - add from candrsn
70
 
 *
71
 
 * Revision 1.8  1999/03/23 17:22:27  warmerda
72
 
 * Added extern "C" protection for C++ users of shapefil.h.
73
 
 *
74
 
 * Revision 1.7  1998/12/31 15:31:07  warmerda
75
 
 * Added the TRIM_DBF_WHITESPACE and DISABLE_MULTIPATCH_MEASURE options.
76
 
 *
77
 
 * Revision 1.6  1998/12/03 15:48:15  warmerda
78
 
 * Added SHPCalculateExtents().
79
 
 *
80
 
 * Revision 1.5  1998/11/09 20:57:16  warmerda
81
 
 * Altered SHPGetInfo() call.
82
 
 *
83
 
 * Revision 1.4  1998/11/09 20:19:33  warmerda
84
 
 * Added 3D support, and use of SHPObject.
85
 
 *
86
 
 * Revision 1.3  1995/08/23 02:24:05  warmerda
87
 
 * Added support for reading bounds.
88
 
 *
89
 
 * Revision 1.2  1995/08/04  03:17:39  warmerda
90
 
 * Added header.
91
 
 *
92
 
 */
93
 
 
94
 
#include <stdio.h>
95
 
 
96
 
#ifdef USE_DBMALLOC
97
 
#include <dbmalloc.h>
98
 
#endif
99
 
 
100
 
#ifdef __cplusplus
101
 
extern "C" {
102
 
#endif
103
 
    
104
 
/************************************************************************/
105
 
/*                        Configuration options.                        */
106
 
/************************************************************************/
107
 
 
108
 
/* -------------------------------------------------------------------- */
109
 
/*      Should the DBFReadStringAttribute() strip leading and           */
110
 
/*      trailing white space?                                           */
111
 
/* -------------------------------------------------------------------- */
112
 
#define TRIM_DBF_WHITESPACE
113
 
 
114
 
/* -------------------------------------------------------------------- */
115
 
/*      Should we write measure values to the Multipatch object?        */
116
 
/*      Reportedly ArcView crashes if we do write it, so for now it     */
117
 
/*      is disabled.                                                    */
118
 
/* -------------------------------------------------------------------- */
119
 
#define DISABLE_MULTIPATCH_MEASURE
120
 
 
121
 
/************************************************************************/
122
 
/*                             SHP Support.                             */
123
 
/************************************************************************/
124
 
typedef struct
125
 
{
126
 
    FILE        *fpSHP;
127
 
    FILE        *fpSHX;
128
 
 
129
 
    int         nShapeType;                             /* SHPT_* */
130
 
    
131
 
    int         nFileSize;                              /* SHP file */
132
 
 
133
 
    int         nRecords;
134
 
    int         nMaxRecords;
135
 
    int         *panRecOffset;
136
 
    int         *panRecSize;
137
 
 
138
 
    double      adBoundsMin[4];
139
 
    double      adBoundsMax[4];
140
 
 
141
 
    int         bUpdated;
142
 
} SHPInfo;
143
 
 
144
 
typedef SHPInfo * SHPHandle;
145
 
 
146
 
/* -------------------------------------------------------------------- */
147
 
/*      Shape types (nSHPType)                                          */
148
 
/* -------------------------------------------------------------------- */
149
 
#define SHPT_NULL       0
150
 
#define SHPT_POINT      1
151
 
#define SHPT_ARC        3
152
 
#define SHPT_POLYGON    5
153
 
#define SHPT_MULTIPOINT 8
154
 
#define SHPT_POINTZ     11
155
 
#define SHPT_ARCZ       13
156
 
#define SHPT_POLYGONZ   15
157
 
#define SHPT_MULTIPOINTZ 18
158
 
#define SHPT_POINTM     21
159
 
#define SHPT_ARCM       23
160
 
#define SHPT_POLYGONM   25
161
 
#define SHPT_MULTIPOINTM 28
162
 
#define SHPT_MULTIPATCH 31
163
 
 
164
 
 
165
 
/* -------------------------------------------------------------------- */
166
 
/*      Part types - everything but SHPT_MULTIPATCH just uses           */
167
 
/*      SHPP_RING.                                                      */
168
 
/* -------------------------------------------------------------------- */
169
 
 
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
175
 
#define SHPP_RING       5
176
 
 
177
 
/* -------------------------------------------------------------------- */
178
 
/*      SHPObject - represents on shape (without attributes) read       */
179
 
/*      from the .shp file.                                             */
180
 
/* -------------------------------------------------------------------- */
181
 
typedef struct
182
 
{
183
 
    int         nSHPType;
184
 
 
185
 
    int         nShapeId; /* -1 is unknown/unassigned */
186
 
 
187
 
    int         nParts;
188
 
    int         *panPartStart;
189
 
    int         *panPartType;
190
 
    
191
 
    int         nVertices;
192
 
    double      *padfX;
193
 
    double      *padfY;
194
 
    double      *padfZ;
195
 
    double      *padfM;
196
 
 
197
 
    double      dfXMin;
198
 
    double      dfYMin;
199
 
    double      dfZMin;
200
 
    double      dfMMin;
201
 
 
202
 
    double      dfXMax;
203
 
    double      dfYMax;
204
 
    double      dfZMax;
205
 
    double      dfMMax;
206
 
} SHPObject;
207
 
 
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 );
215
 
 
216
 
SHPObject *SHPReadObject( SHPHandle hSHP, int iShape );
217
 
int     SHPWriteObject( SHPHandle hSHP, int iShape, SHPObject * psObject );
218
 
 
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 );
227
 
 
228
 
void    SHPClose( SHPHandle hSHP );
229
 
 
230
 
const char *SHPTypeName( int nSHPType );
231
 
const char *SHPPartTypeName( int nPartType );
232
 
 
233
 
/* -------------------------------------------------------------------- */
234
 
/*      Shape quadtree indexing API.                                    */
235
 
/* -------------------------------------------------------------------- */
236
 
 
237
 
/* this can be two or four for binary or quad tree */
238
 
#define MAX_SUBNODE     4
239
 
 
240
 
typedef struct shape_tree_node
241
 
{
242
 
    /* region covered by this node */
243
 
    double      adfBoundsMin[4];
244
 
    double      adfBoundsMax[4];
245
 
 
246
 
    /* list of shapes stored at this node.  The papsShapeObj pointers
247
 
       or the whole list can be NULL */
248
 
    int         nShapeCount;
249
 
    int         *panShapeIds;
250
 
    SHPObject   **papsShapeObj;
251
 
 
252
 
    int         nSubNodes;
253
 
    struct shape_tree_node *apsSubNode[MAX_SUBNODE];
254
 
    
255
 
} SHPTreeNode;
256
 
 
257
 
typedef struct
258
 
{
259
 
    SHPHandle   hSHP;
260
 
    
261
 
    int         nMaxDepth;
262
 
    int         nDimension;
263
 
    
264
 
    SHPTreeNode *psRoot;
265
 
} SHPTree;
266
 
 
267
 
SHPTree *SHPCreateTree( SHPHandle hSHP, int nDimension, int nMaxDepth,
268
 
                        double *padfBoundsMin, double *padfBoundsMax );
269
 
void     SHPDestroyTree( SHPTree * hTree );
270
 
 
271
 
int     SHPWriteTree( SHPTree *hTree, const char * pszFilename );
272
 
SHPTree SHPReadTree( const char * pszFilename );
273
 
 
274
 
int     SHPTreeAddObject( SHPTree * hTree, SHPObject * psObject );
275
 
int     SHPTreeAddShapeId( SHPTree * hTree, SHPObject * psObject );
276
 
int     SHPTreeRemoveShapeId( SHPTree * hTree, int nShapeId );
277
 
 
278
 
void    SHPTreeTrimExtraNodes( SHPTree * hTree );
279
 
 
280
 
int    *SHPTreeFindLikelyShapes( SHPTree * hTree,
281
 
                                 double * padfBoundsMin,
282
 
                                 double * padfBoundsMax,
283
 
                                 int * );
284
 
int     SHPCheckBoundsOverlap( double *, double *, double *, double *, int );
285
 
 
286
 
/************************************************************************/
287
 
/*                             DBF Support.                             */
288
 
/************************************************************************/
289
 
typedef struct
290
 
{
291
 
    FILE        *fp;
292
 
 
293
 
    int         nRecords;
294
 
 
295
 
    int         nRecordLength;
296
 
    int         nHeaderLength;
297
 
    int         nFields;
298
 
    int         *panFieldOffset;
299
 
    int         *panFieldSize;
300
 
    int         *panFieldDecimals;
301
 
    char        *pachFieldType;
302
 
 
303
 
    char        *pszHeader;
304
 
 
305
 
    int         nCurrentRecord;
306
 
    int         bCurrentRecordModified;
307
 
    char        *pszCurrentRecord;
308
 
    
309
 
    int         bNoHeader;
310
 
    int         bUpdated;
311
 
} DBFInfo;
312
 
 
313
 
typedef DBFInfo * DBFHandle;
314
 
 
315
 
typedef enum {
316
 
  FTString,
317
 
  FTInteger,
318
 
  FTDouble,
319
 
  FTInvalid
320
 
} DBFFieldType;
321
 
 
322
 
#define XBASE_FLDHDR_SZ       32
323
 
 
324
 
DBFHandle DBFOpen( const char * pszDBFFile, const char * pszAccess );
325
 
DBFHandle DBFCreate( const char * pszDBFFile );
326
 
 
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 );
331
 
 
332
 
DBFFieldType DBFGetFieldInfo( DBFHandle psDBF, int iField, 
333
 
                              char * pszFieldName, 
334
 
                              int * pnWidth, int * pnDecimals );
335
 
 
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 );
339
 
 
340
 
int DBFWriteIntegerAttribute( DBFHandle hDBF, int iShape, int iField, 
341
 
                              int nFieldValue );
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 );
346
 
 
347
 
const char *DBFReadTuple(DBFHandle psDBF, int hEntity );
348
 
int DBFWriteTuple(DBFHandle psDBF, int hEntity, void * pRawTuple );
349
 
 
350
 
DBFHandle DBFCloneEmpty(DBFHandle psDBF, const char * pszFilename );
351
 
 
352
 
void    DBFClose( DBFHandle hDBF );
353
 
 
354
 
#ifdef __cplusplus
355
 
}
356
 
#endif
357
 
 
358
 
#endif /* ndef _SHAPEFILE_H_INCLUDED */