GRASS Programmer's Manual
6.4.2(2012)
Main Page
Related Pages
Namespaces
Data Structures
Files
File List
Globals
All
Data Structures
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Pages
shapefil.h
Go to the documentation of this file.
1
#ifndef _SHAPEFILE_H_INCLUDED
2
#define _SHAPEFILE_H_INCLUDED
3
4
/******************************************************************************
5
* $Id: shapefil.h 32581 2008-08-06 19:30:45Z neteler $
6
*
7
* Project: Shapelib
8
* Purpose: Primary include file for Shapelib.
9
* Author: Frank Warmerdam, warmerdam@pobox.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: shapefil.h,v $
40
* Revision 1.40 2007/12/06 07:00:25 fwarmerdam
41
* dbfopen now using SAHooks for fileio
42
*
43
* Revision 1.39 2007/12/04 20:37:56 fwarmerdam
44
* preliminary implementation of hooks api for io and errors
45
*
46
* Revision 1.38 2007/11/21 22:39:56 fwarmerdam
47
* close shx file in readonly mode (GDAL #1956)
48
*
49
* Revision 1.37 2007/10/27 03:31:14 fwarmerdam
50
* limit default depth of tree to 12 levels (gdal ticket #1594)
51
*
52
* Revision 1.36 2007/09/10 23:33:15 fwarmerdam
53
* Upstreamed support for visibility flag in SHPAPI_CALL for the needs
54
* of GDAL (gdal ticket #1810).
55
*
56
* Revision 1.35 2007/09/03 19:48:10 fwarmerdam
57
* move DBFReadAttribute() static dDoubleField into dbfinfo
58
*
59
* Revision 1.34 2006/06/17 15:33:32 fwarmerdam
60
* added pszWorkField - bug 1202 (rso)
61
*
62
* Revision 1.33 2006/02/15 01:14:30 fwarmerdam
63
* added DBFAddNativeFieldType
64
*
65
* Revision 1.32 2006/01/26 15:07:32 fwarmerdam
66
* add bMeasureIsUsed flag from Craig Bruce: Bug 1249
67
*
68
* Revision 1.31 2006/01/05 01:27:27 fwarmerdam
69
* added dbf deletion mark/fetch
70
*
71
* Revision 1.30 2005/01/03 22:30:13 fwarmerdam
72
* added support for saved quadtrees
73
*
74
* Revision 1.29 2004/09/26 20:09:35 fwarmerdam
75
* avoid rcsid warnings
76
*
77
* Revision 1.28 2003/12/29 06:02:18 fwarmerdam
78
* added cpl_error.h option
79
*
80
* Revision 1.27 2003/04/21 18:30:37 warmerda
81
* added header write/update public methods
82
*
83
* Revision 1.26 2002/09/29 00:00:08 warmerda
84
* added FTLogical and logical attribute read/write calls
85
*
86
* Revision 1.25 2002/05/07 13:46:30 warmerda
87
* added DBFWriteAttributeDirectly().
88
*
89
* Revision 1.24 2002/04/10 16:59:54 warmerda
90
* added SHPRewindObject
91
*
92
* Revision 1.23 2002/01/15 14:36:07 warmerda
93
* updated email address
94
*
95
* Revision 1.22 2002/01/15 14:32:00 warmerda
96
* try to improve SHPAPI_CALL docs
97
*/
98
99
#include <stdio.h>
100
101
#ifdef USE_DBMALLOC
102
#include <dbmalloc.h>
103
#endif
104
105
#ifdef USE_CPL
106
#include "cpl_error.h"
107
#include "cpl_vsi.h"
108
#endif
109
110
#ifdef __cplusplus
111
extern
"C"
{
112
#endif
113
114
/************************************************************************/
115
/* Configuration options. */
116
/************************************************************************/
117
118
/* -------------------------------------------------------------------- */
119
/* Should the DBFReadStringAttribute() strip leading and */
120
/* trailing white space? */
121
/* -------------------------------------------------------------------- */
122
#define TRIM_DBF_WHITESPACE
123
124
/* -------------------------------------------------------------------- */
125
/* Should we write measure values to the Multipatch object? */
126
/* Reportedly ArcView crashes if we do write it, so for now it */
127
/* is disabled. */
128
/* -------------------------------------------------------------------- */
129
#define DISABLE_MULTIPATCH_MEASURE
130
131
/* -------------------------------------------------------------------- */
132
/* SHPAPI_CALL */
133
/* */
134
/* The following two macros are present to allow forcing */
135
/* various calling conventions on the Shapelib API. */
136
/* */
137
/* To force __stdcall conventions (needed to call Shapelib */
138
/* from Visual Basic and/or Dephi I believe) the makefile could */
139
/* be modified to define: */
140
/* */
141
/* /DSHPAPI_CALL=__stdcall */
142
/* */
143
/* If it is desired to force export of the Shapelib API without */
144
/* using the shapelib.def file, use the following definition. */
145
/* */
146
/* /DSHAPELIB_DLLEXPORT */
147
/* */
148
/* To get both at once it will be necessary to hack this */
149
/* include file to define: */
150
/* */
151
/* #define SHPAPI_CALL __declspec(dllexport) __stdcall */
152
/* #define SHPAPI_CALL1 __declspec(dllexport) * __stdcall */
153
/* */
154
/* The complexity of the situtation is partly caused by the */
155
/* peculiar requirement of Visual C++ that __stdcall appear */
156
/* after any "*"'s in the return value of a function while the */
157
/* __declspec(dllexport) must appear before them. */
158
/* -------------------------------------------------------------------- */
159
160
#ifdef SHAPELIB_DLLEXPORT
161
# define SHPAPI_CALL __declspec(dllexport)
162
# define SHPAPI_CALL1(x) __declspec(dllexport) x
163
#endif
164
165
#ifndef SHPAPI_CALL
166
# if defined(USE_GCC_VISIBILITY_FLAG)
167
# define SHPAPI_CALL __attribute__ ((visibility("default")))
168
# define SHPAPI_CALL1(x) __attribute__ ((visibility("default"))) x
169
# else
170
# define SHPAPI_CALL
171
# endif
172
#endif
173
174
#ifndef SHPAPI_CALL1
175
# define SHPAPI_CALL1(x) x SHPAPI_CALL
176
#endif
177
178
/* -------------------------------------------------------------------- */
179
/* Macros for controlling CVSID and ensuring they don't appear */
180
/* as unreferenced variables resulting in lots of warnings. */
181
/* -------------------------------------------------------------------- */
182
#ifndef DISABLE_CVSID
183
# define SHP_CVSID(string) static char cpl_cvsid[] = string; \
184
static char *cvsid_aw() { return( cvsid_aw() ? ((char *) NULL) : cpl_cvsid ); }
185
#else
186
# define SHP_CVSID(string)
187
#endif
188
189
/* -------------------------------------------------------------------- */
190
/* IO/Error hook functions. */
191
/* -------------------------------------------------------------------- */
192
typedef
int
*
SAFile
;
193
194
#ifndef SAOffset
195
typedef
unsigned
long
SAOffset
;
196
#endif
197
198
typedef
struct
{
199
SAFile
(*FOpen) (
const
char
*filename,
const
char
*path);
200
SAOffset
(*FRead) (
void
*p, SAOffset size, SAOffset nmemb, SAFile
file
);
201
SAOffset
(*FWrite)(
void
*p, SAOffset size, SAOffset nmemb, SAFile
file
);
202
SAOffset
(*FSeek) ( SAFile
file
, SAOffset offset,
int
whence );
203
SAOffset
(*FTell) ( SAFile
file
);
204
int (*FFlush)( SAFile
file
);
205
int (*FClose)( SAFile
file
);
206
207
void (*Error) (
const
char
*
message
);
208
}
SAHooks
;
209
210
void
SHPAPI_CALL
SASetupDefaultHooks
(
SAHooks
*psHooks );
211
212
/************************************************************************/
213
/* SHP Support. */
214
/************************************************************************/
215
typedef
struct
216
{
217
SAHooks
sHooks
;
218
219
SAFile
fpSHP
;
220
SAFile
fpSHX
;
221
222
int
nShapeType
;
/* SHPT_* */
223
224
int
nFileSize
;
/* SHP file */
225
226
int
nRecords
;
227
int
nMaxRecords
;
228
int
*
panRecOffset
;
229
int
*
panRecSize
;
230
231
double
adBoundsMin[4];
232
double
adBoundsMax[4];
233
234
int
bUpdated
;
235
236
unsigned
char
*
pabyRec
;
237
int
nBufSize
;
238
}
SHPInfo
;
239
240
typedef
SHPInfo
*
SHPHandle
;
241
242
/* -------------------------------------------------------------------- */
243
/* Shape types (nSHPType) */
244
/* -------------------------------------------------------------------- */
245
#define SHPT_NULL 0
246
#define SHPT_POINT 1
247
#define SHPT_ARC 3
248
#define SHPT_POLYGON 5
249
#define SHPT_MULTIPOINT 8
250
#define SHPT_POINTZ 11
251
#define SHPT_ARCZ 13
252
#define SHPT_POLYGONZ 15
253
#define SHPT_MULTIPOINTZ 18
254
#define SHPT_POINTM 21
255
#define SHPT_ARCM 23
256
#define SHPT_POLYGONM 25
257
#define SHPT_MULTIPOINTM 28
258
#define SHPT_MULTIPATCH 31
259
260
261
/* -------------------------------------------------------------------- */
262
/* Part types - everything but SHPT_MULTIPATCH just uses */
263
/* SHPP_RING. */
264
/* -------------------------------------------------------------------- */
265
266
#define SHPP_TRISTRIP 0
267
#define SHPP_TRIFAN 1
268
#define SHPP_OUTERRING 2
269
#define SHPP_INNERRING 3
270
#define SHPP_FIRSTRING 4
271
#define SHPP_RING 5
272
273
/* -------------------------------------------------------------------- */
274
/* SHPObject - represents on shape (without attributes) read */
275
/* from the .shp file. */
276
/* -------------------------------------------------------------------- */
277
typedef
struct
278
{
279
int
nSHPType
;
280
281
int
nShapeId
;
/* -1 is unknown/unassigned */
282
283
int
nParts
;
284
int
*
panPartStart
;
285
int
*
panPartType
;
286
287
int
nVertices
;
288
double
*
padfX
;
289
double
*
padfY
;
290
double
*
padfZ
;
291
double
*
padfM
;
292
293
double
dfXMin
;
294
double
dfYMin
;
295
double
dfZMin
;
296
double
dfMMin
;
297
298
double
dfXMax
;
299
double
dfYMax
;
300
double
dfZMax
;
301
double
dfMMax
;
302
303
int
bMeasureIsUsed
;
304
}
SHPObject
;
305
306
/* -------------------------------------------------------------------- */
307
/* SHP API Prototypes */
308
/* -------------------------------------------------------------------- */
309
310
/* If pszAccess is read-only, the fpSHX field of the returned structure */
311
/* will be NULL as it is not necessary to keep the SHX file open */
312
SHPHandle
SHPAPI_CALL
313
SHPOpen
(
const
char
* pszShapeFile,
const
char
* pszAccess );
314
SHPHandle
SHPAPI_CALL
315
SHPOpenLL
(
const
char
*pszShapeFile,
const
char
*pszAccess,
316
SAHooks
*psHooks );
317
SHPHandle
SHPAPI_CALL
318
SHPCreate
(
const
char
* pszShapeFile,
int
nShapeType );
319
SHPHandle
SHPAPI_CALL
320
SHPCreateLL
(
const
char
* pszShapeFile,
int
nShapeType,
321
SAHooks
*psHooks );
322
void
SHPAPI_CALL
323
SHPGetInfo
( SHPHandle hSHP,
int
* pnEntities,
int
* pnShapeType,
324
double
* padfMinBound,
double
* padfMaxBound );
325
326
SHPObject
SHPAPI_CALL1
(*)
327
SHPReadObject
( SHPHandle hSHP,
int
iShape );
328
int
SHPAPI_CALL
329
SHPWriteObject
( SHPHandle hSHP,
int
iShape,
SHPObject
* psObject );
330
331
void
SHPAPI_CALL
332
SHPDestroyObject
(
SHPObject
* psObject );
333
void
SHPAPI_CALL
334
SHPComputeExtents
(
SHPObject
* psObject );
335
SHPObject
SHPAPI_CALL1
(*)
336
SHPCreateObject
(
int
nSHPType
,
int
nShapeId
,
int
nParts,
337
const
int
* panPartStart, const
int
* panPartType,
338
int
nVertices,
339
const
double
* padfX, const
double
* padfY,
340
const
double
* padfZ, const
double
* padfM );
341
SHPObject
SHPAPI_CALL1
(*)
342
SHPCreateSimpleObject
(
int
nSHPType,
int
nVertices,
343
const
double
* padfX,
344
const
double
* padfY,
345
const
double
* padfZ );
346
347
int
SHPAPI_CALL
348
SHPRewindObject
( SHPHandle hSHP,
SHPObject
* psObject );
349
350
void
SHPAPI_CALL
SHPClose
( SHPHandle hSHP );
351
void
SHPAPI_CALL
SHPWriteHeader
( SHPHandle hSHP );
352
353
const
char
SHPAPI_CALL1
(*)
354
SHPTypeName
(
int
nSHPType );
355
const
char
SHPAPI_CALL1
(*)
356
SHPPartTypeName
(
int
nPartType );
357
358
/* -------------------------------------------------------------------- */
359
/* Shape quadtree indexing API. */
360
/* -------------------------------------------------------------------- */
361
362
/* this can be two or four for binary or quad tree */
363
#define MAX_SUBNODE 4
364
365
/* upper limit of tree levels for automatic estimation */
366
#define MAX_DEFAULT_TREE_DEPTH 12
367
368
typedef
struct
shape_tree_node
369
{
370
/* region covered by this node */
371
double
adfBoundsMin
[4];
372
double
adfBoundsMax
[4];
373
374
/* list of shapes stored at this node. The papsShapeObj pointers
375
or the whole list can be NULL */
376
int
nShapeCount
;
377
int
*
panShapeIds
;
378
SHPObject
**
papsShapeObj
;
379
380
int
nSubNodes
;
381
struct
shape_tree_node
*
apsSubNode
[
MAX_SUBNODE
];
382
383
}
SHPTreeNode
;
384
385
typedef
struct
386
{
387
SHPHandle
hSHP
;
388
389
int
nMaxDepth
;
390
int
nDimension
;
391
int
nTotalCount
;
392
393
SHPTreeNode
*
psRoot
;
394
}
SHPTree
;
395
396
SHPTree
SHPAPI_CALL1
(*)
397
SHPCreateTree
( SHPHandle hSHP,
int
nDimension,
int
nMaxDepth,
398
double
*padfBoundsMin,
double
*padfBoundsMax );
399
void
SHPAPI_CALL
400
SHPDestroyTree(
SHPTree
* hTree );
401
402
int
SHPAPI_CALL
403
SHPWriteTree
(
SHPTree
*hTree, const
char
* pszFilename );
404
SHPTree
SHPAPI_CALL
405
SHPReadTree
( const
char
* pszFilename );
406
407
int
SHPAPI_CALL
408
SHPTreeAddObject
(
SHPTree
* hTree,
SHPObject
* psObject );
409
int
SHPAPI_CALL
410
SHPTreeAddShapeId
(
SHPTree
* hTree,
SHPObject
* psObject );
411
int
SHPAPI_CALL
412
SHPTreeRemoveShapeId
(
SHPTree
* hTree,
int
nShapeId );
413
414
void
SHPAPI_CALL
415
SHPTreeTrimExtraNodes
(
SHPTree
* hTree );
416
417
int
SHPAPI_CALL1
(*)
418
SHPTreeFindLikelyShapes
(
SHPTree
* hTree,
419
double
* padfBoundsMin,
420
double
* padfBoundsMax,
421
int
* );
422
int
SHPAPI_CALL
423
SHPCheckBoundsOverlap(
double
*,
double
*,
double
*,
double
*,
int
);
424
425
int
SHPAPI_CALL1
(*)
426
SHPSearchDiskTree
( FILE *fp,
427
double
*padfBoundsMin,
double
*padfBoundsMax,
428
int
*pnShapeCount );
429
430
/************************************************************************/
431
/* DBF Support. */
432
/************************************************************************/
433
typedef struct
434
{
435
SAHooks
sHooks;
436
437
SAFile fp;
438
439
int
nRecords;
440
441
int
nRecordLength;
442
int
nHeaderLength;
443
int
nFields;
444
int
*panFieldOffset;
445
int
*panFieldSize;
446
int
*panFieldDecimals;
447
char
*pachFieldType;
448
449
char
*pszHeader;
450
451
int
nCurrentRecord;
452
int
bCurrentRecordModified;
453
char
*pszCurrentRecord;
454
455
int
nWorkFieldLength;
456
char
*pszWorkField;
457
458
int
bNoHeader;
459
int
bUpdated;
460
461
double
dfDoubleField;
462
} DBFInfo;
463
464
typedef
DBFInfo * DBFHandle;
465
466
typedef
enum
{
467
FTString,
468
FTInteger,
469
FTDouble,
470
FTLogical,
471
FTInvalid
472
} DBFFieldType;
473
474
#define XBASE_FLDHDR_SZ 32
475
476
477
DBFHandle
SHPAPI_CALL
478
DBFOpen
(
const
char
* pszDBFFile,
const
char
* pszAccess );
479
DBFHandle
SHPAPI_CALL
480
DBFOpenLL
(
const
char
* pszDBFFile,
const
char
* pszAccess,
481
SAHooks
*psHooks );
482
DBFHandle
SHPAPI_CALL
483
DBFCreate
(
const
char
* pszDBFFile );
484
DBFHandle
SHPAPI_CALL
485
DBFCreateLL
(
const
char
* pszDBFFile,
SAHooks
*psHooks );
486
487
int
SHPAPI_CALL
488
DBFGetFieldCount
( DBFHandle psDBF );
489
int
SHPAPI_CALL
490
DBFGetRecordCount
( DBFHandle psDBF );
491
int
SHPAPI_CALL
492
DBFAddField
( DBFHandle hDBF,
const
char
* pszFieldName,
493
DBFFieldType eType,
int
nWidth,
int
nDecimals );
494
495
int
SHPAPI_CALL
496
DBFAddNativeFieldType
( DBFHandle hDBF,
const
char
* pszFieldName,
497
char
chType,
int
nWidth,
int
nDecimals );
498
499
DBFFieldType
SHPAPI_CALL
500
DBFGetFieldInfo
( DBFHandle psDBF,
int
iField,
501
char
* pszFieldName,
int
* pnWidth,
int
* pnDecimals );
502
503
int
SHPAPI_CALL
504
DBFGetFieldIndex
(DBFHandle psDBF,
const
char
*pszFieldName);
505
506
int
SHPAPI_CALL
507
DBFReadIntegerAttribute
( DBFHandle hDBF,
int
iShape,
int
iField );
508
double
SHPAPI_CALL
509
DBFReadDoubleAttribute
( DBFHandle hDBF,
int
iShape,
int
iField );
510
const
char
SHPAPI_CALL1
(*)
511
DBFReadStringAttribute
( DBFHandle hDBF,
int
iShape,
int
iField );
512
const
char
SHPAPI_CALL1
(*)
513
DBFReadLogicalAttribute
( DBFHandle hDBF,
int
iShape,
int
iField );
514
int
SHPAPI_CALL
515
DBFIsAttributeNULL
( DBFHandle hDBF,
int
iShape,
int
iField );
516
517
int
SHPAPI_CALL
518
DBFWriteIntegerAttribute
( DBFHandle hDBF,
int
iShape,
int
iField,
519
int
nFieldValue );
520
int
SHPAPI_CALL
521
DBFWriteDoubleAttribute
( DBFHandle hDBF,
int
iShape,
int
iField,
522
double
dFieldValue );
523
int
SHPAPI_CALL
524
DBFWriteStringAttribute
( DBFHandle hDBF,
int
iShape,
int
iField,
525
const
char
* pszFieldValue );
526
int
SHPAPI_CALL
527
DBFWriteNULLAttribute
( DBFHandle hDBF,
int
iShape,
int
iField );
528
529
int
SHPAPI_CALL
530
DBFWriteLogicalAttribute
( DBFHandle hDBF,
int
iShape,
int
iField,
531
const
char
lFieldValue);
532
int
SHPAPI_CALL
533
DBFWriteAttributeDirectly
(DBFHandle psDBF,
int
hEntity,
int
iField,
534
void
* pValue );
535
const
char
SHPAPI_CALL1
(*)
536
DBFReadTuple
(DBFHandle psDBF,
int
hEntity );
537
int
SHPAPI_CALL
538
DBFWriteTuple
(DBFHandle psDBF,
int
hEntity,
void
* pRawTuple );
539
540
int
SHPAPI_CALL
DBFIsRecordDeleted
( DBFHandle psDBF,
int
iShape );
541
int
SHPAPI_CALL
DBFMarkRecordDeleted
( DBFHandle psDBF,
int
iShape,
542
int
bIsDeleted );
543
544
DBFHandle
SHPAPI_CALL
545
DBFCloneEmpty
(DBFHandle psDBF, const
char
* pszFilename );
546
547
void
SHPAPI_CALL
548
DBFClose
( DBFHandle hDBF );
549
void
SHPAPI_CALL
550
DBFUpdateHeader
( DBFHandle hDBF );
551
char
SHPAPI_CALL
552
DBFGetNativeFieldType
( DBFHandle hDBF,
int
iField );
553
554
#ifdef __cplusplus
555
}
556
#endif
557
558
#endif
/* ndef _SHAPEFILE_H_INCLUDED */
lib
external
shapelib
shapefil.h
Generated on Sun Sep 9 2012 18:55:34 for GRASS Programmer's Manual by
1.8.1.2