1 : /******************************************************************************
2 : * $Id: ogrsf_frmts.h 18449 2010-01-07 09:09:09Z martinl $
3 : *
4 : * Project: OpenGIS Simple Features Reference Implementation
5 : * Purpose: Classes related to format registration, and file opening.
6 : * Author: Frank Warmerdam, warmerda@home.com
7 : *
8 : ******************************************************************************
9 : * Copyright (c) 1999, Les Technologies SoftMap Inc.
10 : *
11 : * Permission is hereby granted, free of charge, to any person obtaining a
12 : * copy of this software and associated documentation files (the "Software"),
13 : * to deal in the Software without restriction, including without limitation
14 : * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15 : * and/or sell copies of the Software, and to permit persons to whom the
16 : * Software is furnished to do so, subject to the following conditions:
17 : *
18 : * The above copyright notice and this permission notice shall be included
19 : * in all copies or substantial portions of the Software.
20 : *
21 : * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22 : * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 : * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24 : * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 : * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26 : * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27 : * DEALINGS IN THE SOFTWARE.
28 : ****************************************************************************/
29 :
30 : #ifndef _OGRSF_FRMTS_H_INCLUDED
31 : #define _OGRSF_FRMTS_H_INCLUDED
32 :
33 : #include "ogr_feature.h"
34 : #include "ogr_featurestyle.h"
35 :
36 : /**
37 : * \file ogrsf_frmts.h
38 : *
39 : * Classes related to registration of format support, and opening datasets.
40 : */
41 :
42 : class OGRLayerAttrIndex;
43 : class OGRSFDriver;
44 :
45 : /************************************************************************/
46 : /* OGRLayer */
47 : /************************************************************************/
48 :
49 : /**
50 : * This class represents a layer of simple features, with access methods.
51 : *
52 : */
53 :
54 : class CPL_DLL OGRLayer
55 : {
56 : protected:
57 : int m_bFilterIsEnvelope;
58 : OGRGeometry *m_poFilterGeom;
59 : OGREnvelope m_sFilterEnvelope;
60 :
61 : int FilterGeometry( OGRGeometry * );
62 : int InstallFilter( OGRGeometry * );
63 :
64 : public:
65 : OGRLayer();
66 : virtual ~OGRLayer();
67 :
68 : virtual OGRGeometry *GetSpatialFilter();
69 : virtual void SetSpatialFilter( OGRGeometry * );
70 : virtual void SetSpatialFilterRect( double dfMinX, double dfMinY,
71 : double dfMaxX, double dfMaxY );
72 :
73 : virtual OGRErr SetAttributeFilter( const char * );
74 :
75 : virtual void ResetReading() = 0;
76 : virtual OGRFeature *GetNextFeature() = 0;
77 : virtual OGRErr SetNextByIndex( long nIndex );
78 : virtual OGRFeature *GetFeature( long nFID );
79 : virtual OGRErr SetFeature( OGRFeature *poFeature );
80 : virtual OGRErr CreateFeature( OGRFeature *poFeature );
81 : virtual OGRErr DeleteFeature( long nFID );
82 :
83 : virtual OGRFeatureDefn *GetLayerDefn() = 0;
84 :
85 : virtual OGRSpatialReference *GetSpatialRef() { return NULL; }
86 :
87 : virtual int GetFeatureCount( int bForce = TRUE );
88 : virtual OGRErr GetExtent(OGREnvelope *psExtent, int bForce = TRUE);
89 :
90 : virtual int TestCapability( const char * ) = 0;
91 :
92 : virtual const char *GetInfo( const char * );
93 :
94 : virtual OGRErr CreateField( OGRFieldDefn *poField,
95 : int bApproxOK = TRUE );
96 :
97 : virtual OGRErr SyncToDisk();
98 :
99 : OGRStyleTable *GetStyleTable(){ return m_poStyleTable; }
100 : void SetStyleTableDirectly( OGRStyleTable *poStyleTable )
101 : { if ( m_poStyleTable ) delete m_poStyleTable;
102 : m_poStyleTable = poStyleTable; }
103 : void SetStyleTable(OGRStyleTable *poStyleTable)
104 : {
105 : if ( m_poStyleTable ) delete m_poStyleTable;
106 : if ( poStyleTable )
107 : m_poStyleTable = poStyleTable->Clone();
108 : }
109 :
110 : virtual OGRErr StartTransaction();
111 : virtual OGRErr CommitTransaction();
112 : virtual OGRErr RollbackTransaction();
113 :
114 : virtual const char *GetFIDColumn();
115 : virtual const char *GetGeometryColumn();
116 :
117 : int Reference();
118 : int Dereference();
119 : int GetRefCount() const;
120 :
121 : GIntBig GetFeaturesRead();
122 :
123 : /* consider these private */
124 : OGRErr InitializeIndexSupport( const char * );
125 156 : OGRLayerAttrIndex *GetIndex() { return m_poAttrIndex; }
126 :
127 : protected:
128 : OGRStyleTable *m_poStyleTable;
129 : OGRFeatureQuery *m_poAttrQuery;
130 : OGRLayerAttrIndex *m_poAttrIndex;
131 :
132 : int m_nRefCount;
133 :
134 : GIntBig m_nFeaturesRead;
135 : };
136 :
137 :
138 : /************************************************************************/
139 : /* OGRDataSource */
140 : /************************************************************************/
141 :
142 : /**
143 : * This class represents a data source. A data source potentially
144 : * consists of many layers (OGRLayer). A data source normally consists
145 : * of one, or a related set of files, though the name doesn't have to be
146 : * a real item in the file system.
147 : *
148 : * When an OGRDataSource is destroyed, all it's associated OGRLayers objects
149 : * are also destroyed.
150 : */
151 :
152 : class CPL_DLL OGRDataSource
153 : {
154 : friend class OGRSFDriverRegistrar;
155 :
156 : void *m_hMutex;
157 :
158 : public:
159 :
160 : OGRDataSource();
161 : virtual ~OGRDataSource();
162 : static void DestroyDataSource( OGRDataSource * );
163 :
164 : virtual const char *GetName() = 0;
165 :
166 : virtual int GetLayerCount() = 0;
167 : virtual OGRLayer *GetLayer(int) = 0;
168 : virtual OGRLayer *GetLayerByName(const char *);
169 : virtual OGRErr DeleteLayer(int);
170 :
171 : virtual int TestCapability( const char * ) = 0;
172 :
173 : virtual OGRLayer *CreateLayer( const char *pszName,
174 : OGRSpatialReference *poSpatialRef = NULL,
175 : OGRwkbGeometryType eGType = wkbUnknown,
176 : char ** papszOptions = NULL );
177 : virtual OGRLayer *CopyLayer( OGRLayer *poSrcLayer,
178 : const char *pszNewName,
179 : char **papszOptions = NULL );
180 :
181 : OGRStyleTable *GetStyleTable(){ return m_poStyleTable; }
182 : void SetStyleTableDirectly( OGRStyleTable *poStyleTable )
183 : { if ( m_poStyleTable ) delete m_poStyleTable;
184 : m_poStyleTable = poStyleTable; }
185 : void SetStyleTable(OGRStyleTable *poStyleTable)
186 : {
187 : if ( m_poStyleTable ) delete m_poStyleTable;
188 : if ( poStyleTable )
189 : m_poStyleTable = poStyleTable->Clone();
190 : }
191 :
192 : virtual OGRLayer * ExecuteSQL( const char *pszStatement,
193 : OGRGeometry *poSpatialFilter,
194 : const char *pszDialect );
195 : virtual void ReleaseResultSet( OGRLayer * poResultsSet );
196 :
197 : virtual OGRErr SyncToDisk();
198 :
199 : int Reference();
200 : int Dereference();
201 : int GetRefCount() const;
202 : int GetSummaryRefCount() const;
203 : OGRErr Release();
204 :
205 : OGRSFDriver *GetDriver() const;
206 : void SetDriver( OGRSFDriver *poDriver );
207 :
208 : protected:
209 :
210 : OGRErr ProcessSQLCreateIndex( const char * );
211 : OGRErr ProcessSQLDropIndex( const char * );
212 :
213 : OGRStyleTable *m_poStyleTable;
214 : int m_nRefCount;
215 : OGRSFDriver *m_poDriver;
216 : };
217 :
218 : /************************************************************************/
219 : /* OGRSFDriver */
220 : /************************************************************************/
221 :
222 : /**
223 : * Represents an operational format driver.
224 : *
225 : * One OGRSFDriver derived class will normally exist for each file format
226 : * registered for use, regardless of whether a file has or will be opened.
227 : * The list of available drivers is normally managed by the
228 : * OGRSFDriverRegistrar.
229 : */
230 :
231 : class CPL_DLL OGRSFDriver
232 0 : {
233 : public:
234 : virtual ~OGRSFDriver();
235 :
236 : virtual const char *GetName() = 0;
237 :
238 : virtual OGRDataSource *Open( const char *pszName, int bUpdate=FALSE ) = 0;
239 :
240 : virtual int TestCapability( const char * ) = 0;
241 :
242 : virtual OGRDataSource *CreateDataSource( const char *pszName,
243 : char ** = NULL );
244 : virtual OGRErr DeleteDataSource( const char *pszName );
245 :
246 : virtual OGRDataSource *CopyDataSource( OGRDataSource *poSrcDS,
247 : const char *pszNewName,
248 : char **papszOptions = NULL );
249 : };
250 :
251 :
252 : /************************************************************************/
253 : /* OGRSFDriverRegistrar */
254 : /************************************************************************/
255 :
256 : /**
257 : * Singleton manager for OGRSFDriver instances that will be used to try
258 : * and open datasources. Normally the registrar is populated with
259 : * standard drivers using the OGRRegisterAll() function and does not need
260 : * to be directly accessed. The driver registrar and all registered drivers
261 : * may be cleaned up on shutdown using OGRCleanupAll().
262 : */
263 :
264 : class CPL_DLL OGRSFDriverRegistrar
265 : {
266 : int nDrivers;
267 : OGRSFDriver **papoDrivers;
268 :
269 : OGRSFDriverRegistrar();
270 :
271 : int nOpenDSCount;
272 : char **papszOpenDSRawName;
273 : OGRDataSource **papoOpenDS;
274 : OGRSFDriver **papoOpenDSDriver;
275 : GIntBig *panOpenDSPID;
276 :
277 : public:
278 :
279 : ~OGRSFDriverRegistrar();
280 :
281 : static OGRSFDriverRegistrar *GetRegistrar();
282 : static OGRDataSource *Open( const char *pszName, int bUpdate=FALSE,
283 : OGRSFDriver ** ppoDriver = NULL );
284 :
285 : OGRDataSource *OpenShared( const char *pszName, int bUpdate=FALSE,
286 : OGRSFDriver ** ppoDriver = NULL );
287 : OGRErr ReleaseDataSource( OGRDataSource * );
288 :
289 : void RegisterDriver( OGRSFDriver * poDriver );
290 :
291 : int GetDriverCount( void );
292 : OGRSFDriver *GetDriver( int iDriver );
293 : OGRSFDriver *GetDriverByName( const char * );
294 :
295 : int GetOpenDSCount() { return nOpenDSCount; }
296 : OGRDataSource *GetOpenDS( int );
297 :
298 : void AutoLoadDrivers();
299 : };
300 :
301 : /* -------------------------------------------------------------------- */
302 : /* Various available registration methods. */
303 : /* -------------------------------------------------------------------- */
304 : CPL_C_START
305 : void CPL_DLL OGRRegisterAll();
306 :
307 : void CPL_DLL RegisterOGRShape();
308 : void CPL_DLL RegisterOGRNTF();
309 : void CPL_DLL RegisterOGRFME();
310 : void CPL_DLL RegisterOGRSDTS();
311 : void CPL_DLL RegisterOGRTiger();
312 : void CPL_DLL RegisterOGRS57();
313 : void CPL_DLL RegisterOGRTAB();
314 : void CPL_DLL RegisterOGRMIF();
315 : void CPL_DLL RegisterOGROGDI();
316 : void CPL_DLL RegisterOGRODBC();
317 : void CPL_DLL RegisterOGRPG();
318 : void CPL_DLL RegisterOGRMySQL();
319 : void CPL_DLL RegisterOGROCI();
320 : void CPL_DLL RegisterOGRDGN();
321 : void CPL_DLL RegisterOGRGML();
322 : void CPL_DLL RegisterOGRKML();
323 : void CPL_DLL RegisterOGRGeoJSON();
324 : void CPL_DLL RegisterOGRAVCBin();
325 : void CPL_DLL RegisterOGRAVCE00();
326 : void CPL_DLL RegisterOGRREC();
327 : void CPL_DLL RegisterOGRMEM();
328 : void CPL_DLL RegisterOGRVRT();
329 : void CPL_DLL RegisterOGRDODS();
330 : void CPL_DLL RegisterOGRSQLite();
331 : void CPL_DLL RegisterOGRCSV();
332 : void CPL_DLL RegisterOGRILI1();
333 : void CPL_DLL RegisterOGRILI2();
334 : void CPL_DLL RegisterOGRGRASS();
335 : void CPL_DLL RegisterOGRPGeo();
336 : void CPL_DLL RegisterOGRDXFDWG();
337 : void CPL_DLL RegisterOGRDXF();
338 : void CPL_DLL RegisterOGRSDE();
339 : void CPL_DLL RegisterOGRIDB();
340 : void CPL_DLL RegisterOGRGMT();
341 : void CPL_DLL RegisterOGRBNA();
342 : void CPL_DLL RegisterOGRGPX();
343 : void CPL_DLL RegisterOGRGeoconcept();
344 : void CPL_DLL RegisterOGRIngres();
345 : void CPL_DLL RegisterOGRPCIDSK();
346 : void CPL_DLL RegisterOGRXPlane();
347 : void CPL_DLL RegisterOGRNAS();
348 : void CPL_DLL RegisterOGRGeoRSS();
349 : void CPL_DLL RegisterOGRGTM();
350 : void CPL_DLL RegisterOGRVFK();
351 :
352 : CPL_C_END
353 :
354 :
355 : #endif /* ndef _OGRSF_FRMTS_H_INCLUDED */
|