1 #ifndef SHAPEFILE_H_INCLUDED
2 #define SHAPEFILE_H_INCLUDED
3 
4 /*
5    Based on shapefil.h in Frank Warmerdam's shapelib version 1.5.0
6    and modified for use in gretl. Original copyright notice below.
7 */
8 
9 /******************************************************************************
10  * Copyright (c) 1999, Frank Warmerdam
11  * Copyright (c) 2012-2016, Even Rouault <even dot rouault at mines-paris dot org>
12  *
13  * This software is available under the following "MIT Style" license,
14  * or at the option of the licensee under the LGPL (see COPYING).  This
15  * option is discussed in more detail in shapelib.html.
16  *
17  *
18  * Permission is hereby granted, free of charge, to any person obtaining a
19  * copy of this software and associated documentation files (the "Software"),
20  * to deal in the Software without restriction, including without limitation
21  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
22  * and/or sell copies of the Software, and to permit persons to whom the
23  * Software is furnished to do so, subject to the following conditions:
24  *
25  * The above copyright notice and this permission notice shall be included
26  * in all copies or substantial portions of the Software.
27  *
28  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
29  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
30  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
31  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
32  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
33  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
34  * DEALINGS IN THE SOFTWARE.
35  ******************************************************************************
36  */
37 
38 #include <stdio.h>
39 
40 /************************************************************************/
41 /*                             SHP Support.                             */
42 /************************************************************************/
43 
44 typedef struct SHPInfo_ *SHPHandle;
45 
46 typedef struct SHPObject_
47 {
48     int nSHPType;
49     int nShapeId;  /* -1 is unknown/unassigned */
50     int nParts;
51     int *PartStart;
52     int *PartType;
53 
54     int nVertices;
55     double *fX;
56     double *fY;
57     double *fZ;
58     double *fM;
59 
60     double XMin;
61     double YMin;
62     double ZMin;
63     double MMin;
64 
65     double XMax;
66     double YMax;
67     double ZMax;
68     double MMax;
69 
70     int bMeasureIsUsed;
71     int bFastModeReadObject;
72 } SHPObject;
73 
74 /* If Access is read-only, the fpSHX field of the returned structure
75    will be NULL as it is not necessary to keep the SHX file open.
76 */
77 SHPHandle SHPOpen (const char *ShapeFile, const char *Access);
78 
79 /* If setting bFastMode = TRUE, the content of SHPReadObject() is owned
80    by the SHPHandle. So you cannot have more than 1 valid instance of
81    SHPReadObject() simultaneously. The SHPObject fZ and fM members
82    may be NULL depending on the geometry type.
83 */
84 void SHPSetFastModeReadObject (SHPHandle SHP, int bFastMode);
85 
86 SHPHandle SHPCreate (const char *ShapeFile, int nShapeType);
87 
88 void SHPGetInfo (SHPHandle SHP, int *pnEntities, int *pnShapeType,
89 		 double *MinBound, double *MaxBound);
90 
91 SHPObject *SHPReadObject (SHPHandle SHP, int iShape);
92 
93 void SHPDestroyObject (SHPObject *psObject);
94 
95 void SHPComputeExtents (SHPObject *psObject);
96 
97 void SHPClose (SHPHandle SHP);
98 
99 const char *SHPTypeName (int nSHPType);
100 const char *SHPPartTypeName (int nPartType);
101 
102 /************************************************************************/
103 /*                             DBF Support                              */
104 /************************************************************************/
105 
106 typedef struct DBFInfo_ *DBFHandle;
107 
108 typedef enum {
109   FTString,
110   FTInteger,
111   FTDouble,
112   FTLogical,
113   FTDate,
114   FTInvalid
115 } DBFFieldType;
116 
117 DBFHandle DBFOpen (const char *DBFFile, const char *Access);
118 
119 int DBFGetFieldCount (DBFHandle DBF);
120 int DBFGetRecordCount (DBFHandle DBF);
121 
122 DBFFieldType DBFGetFieldInfo (DBFHandle DBF, int iField,
123 			      char *FieldName, int *pnWidth,
124 			      int *pnDecimals);
125 
126 int DBFGetFieldIndex (DBFHandle DBF, const char *FieldName);
127 
128 int DBFReadIntegerAttribute (DBFHandle DBF, int iShape, int iField);
129 double DBFReadDoubleAttribute (DBFHandle DBF, int iShape, int iField);
130 const char *DBFReadStringAttribute (DBFHandle DBF, int iShape, int iField);
131 const char *DBFReadLogicalAttribute (DBFHandle DBF, int iShape, int iField);
132 int DBFIsAttributeNULL (DBFHandle DBF, int iShape, int iField);
133 
134 int DBFIsRecordDeleted (DBFHandle DBF, int iShape);
135 
136 void DBFClose (DBFHandle DBF);
137 char DBFGetNativeFieldType (DBFHandle DBF, int iField);
138 
139 const char *DBFGetCodePage (DBFHandle DBF);
140 
141 void DBFSetWriteEndOfFileChar (DBFHandle DBF, int bWriteFlag);
142 
143 #endif /* SHAPEFILE_H_INCLUDED */
144