1 : /******************************************************************************
2 : * $Id: ogrshape.h 16076 2009-01-13 00:51:04Z warmerdam $
3 : *
4 : * Project: OpenGIS Simple Features Reference Implementation
5 : * Purpose: Private definitions within the Shapefile driver to implement
6 : * integration with OGR.
7 : * Author: Frank Warmerdam, warmerdam@pobox.com
8 : *
9 : ******************************************************************************
10 : * Copyright (c) 1999, Les Technologies SoftMap Inc.
11 : *
12 : * Permission is hereby granted, free of charge, to any person obtaining a
13 : * copy of this software and associated documentation files (the "Software"),
14 : * to deal in the Software without restriction, including without limitation
15 : * the rights to use, copy, modify, merge, publish, distribute, sublicense,
16 : * and/or sell copies of the Software, and to permit persons to whom the
17 : * Software is furnished to do so, subject to the following conditions:
18 : *
19 : * The above copyright notice and this permission notice shall be included
20 : * in all copies or substantial portions of the Software.
21 : *
22 : * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23 : * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 : * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
25 : * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 : * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27 : * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
28 : * DEALINGS IN THE SOFTWARE.
29 : ****************************************************************************/
30 :
31 : #ifndef _OGRSHAPE_H_INCLUDED
32 : #define _OGRSHAPE_H_INCLUDED
33 :
34 : #include "ogrsf_frmts.h"
35 : #include "shapefil.h"
36 :
37 : /* ==================================================================== */
38 : /* Functions from Shape2ogr.cpp. */
39 : /* ==================================================================== */
40 : OGRFeature *SHPReadOGRFeature( SHPHandle hSHP, DBFHandle hDBF,
41 : OGRFeatureDefn * poDefn, int iShape,
42 : SHPObject *psShape );
43 : OGRGeometry *SHPReadOGRObject( SHPHandle hSHP, int iShape, SHPObject *psShape );
44 : OGRFeatureDefn *SHPReadOGRFeatureDefn( const char * pszName,
45 : SHPHandle hSHP, DBFHandle hDBF );
46 : OGRErr SHPWriteOGRFeature( SHPHandle hSHP, DBFHandle hDBF,
47 : OGRFeatureDefn *poFeatureDefn,
48 : OGRFeature *poFeature );
49 :
50 : /************************************************************************/
51 : /* OGRShapeLayer */
52 : /************************************************************************/
53 :
54 : class OGRShapeLayer : public OGRLayer
55 : {
56 : OGRSpatialReference *poSRS;
57 : OGRFeatureDefn *poFeatureDefn;
58 : int iNextShapeId;
59 : int nTotalShapeCount;
60 :
61 : char *pszFullName;
62 :
63 : SHPHandle hSHP;
64 : DBFHandle hDBF;
65 :
66 : int bUpdateAccess;
67 :
68 : OGRwkbGeometryType eRequestedGeomType;
69 : int ResetGeomType( int nNewType );
70 :
71 : int ScanIndices();
72 :
73 : long *panMatchingFIDs;
74 : int iMatchingFID;
75 :
76 : int bHeaderDirty;
77 :
78 : int bCheckedForQIX;
79 : FILE *fpQIX;
80 :
81 : int CheckForQIX();
82 :
83 : public:
84 : OGRErr CreateSpatialIndex( int nMaxDepth );
85 : OGRErr DropSpatialIndex();
86 : OGRErr Repack();
87 :
88 1 : const char *GetFullName() { return pszFullName; }
89 :
90 : public:
91 : OGRShapeLayer( const char * pszName,
92 : SHPHandle hSHP, DBFHandle hDBF,
93 : OGRSpatialReference *poSRS,
94 : int bUpdate,
95 : OGRwkbGeometryType eReqType );
96 : ~OGRShapeLayer();
97 :
98 : void ResetReading();
99 : OGRFeature * FetchShape(int iShapeId);
100 : OGRFeature * GetNextFeature();
101 : virtual OGRErr SetNextByIndex( long nIndex );
102 :
103 : OGRFeature *GetFeature( long nFeatureId );
104 : OGRErr SetFeature( OGRFeature *poFeature );
105 : OGRErr DeleteFeature( long nFID );
106 : OGRErr CreateFeature( OGRFeature *poFeature );
107 : OGRErr SyncToDisk();
108 :
109 29848 : OGRFeatureDefn * GetLayerDefn() { return poFeatureDefn; }
110 :
111 : int GetFeatureCount( int );
112 : OGRErr GetExtent(OGREnvelope *psExtent, int bForce);
113 :
114 : virtual OGRErr CreateField( OGRFieldDefn *poField,
115 : int bApproxOK = TRUE );
116 :
117 : virtual OGRSpatialReference *GetSpatialRef();
118 :
119 : int TestCapability( const char * );
120 : };
121 :
122 : /************************************************************************/
123 : /* OGRShapeDataSource */
124 : /************************************************************************/
125 :
126 : class OGRShapeDataSource : public OGRDataSource
127 : {
128 : OGRShapeLayer **papoLayers;
129 : int nLayers;
130 :
131 : char *pszName;
132 :
133 : int bDSUpdate;
134 :
135 : int bSingleNewFile;
136 :
137 : public:
138 : OGRShapeDataSource();
139 : ~OGRShapeDataSource();
140 :
141 : int Open( const char *, int bUpdate, int bTestOpen,
142 : int bSingleNewFile = FALSE );
143 : int OpenFile( const char *, int bUpdate, int bTestOpen );
144 :
145 158 : const char *GetName() { return pszName; }
146 1966 : int GetLayerCount() { return nLayers; }
147 : OGRLayer *GetLayer( int );
148 :
149 : virtual OGRLayer *CreateLayer( const char *,
150 : OGRSpatialReference * = NULL,
151 : OGRwkbGeometryType = wkbUnknown,
152 : char ** = NULL );
153 :
154 : virtual OGRLayer *ExecuteSQL( const char *pszStatement,
155 : OGRGeometry *poSpatialFilter,
156 : const char *pszDialect );
157 :
158 : virtual int TestCapability( const char * );
159 : virtual OGRErr DeleteLayer( int iLayer );
160 : };
161 :
162 : /************************************************************************/
163 : /* OGRShapeDriver */
164 : /************************************************************************/
165 :
166 : class OGRShapeDriver : public OGRSFDriver
167 64 : {
168 : public:
169 : ~OGRShapeDriver();
170 :
171 : const char *GetName();
172 : OGRDataSource *Open( const char *, int );
173 :
174 : virtual OGRDataSource *CreateDataSource( const char *pszName,
175 : char ** = NULL );
176 : OGRErr DeleteDataSource( const char *pszDataSource );
177 :
178 : int TestCapability( const char * );
179 : };
180 :
181 :
182 : #endif /* ndef _OGRSHAPE_H_INCLUDED */
|