1 : /******************************************************************************
2 : * $Id: ogr_vrt.h 25110 2012-10-13 13:53:53Z rouault $
3 : *
4 : * Project: OpenGIS Simple Features Reference Implementation
5 : * Purpose: Private definitions for OGR/VRT driver.
6 : * Author: Frank Warmerdam, warmerdam@pobox.com
7 : *
8 : ******************************************************************************
9 : * Copyright (c) 2003, Frank Warmerdam <warmerdam@pobox.com>
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 _OGR_VRT_H_INCLUDED
31 : #define _OGR_VRT_H_INCLUDED
32 :
33 : #include "ogrsf_frmts.h"
34 : #include "cpl_error.h"
35 : #include "cpl_minixml.h"
36 : #include "ogrlayerpool.h"
37 :
38 : #include <vector>
39 : #include <string>
40 : #include <set>
41 :
42 : typedef enum {
43 : VGS_None,
44 : VGS_Direct,
45 : VGS_PointFromColumns,
46 : VGS_WKT,
47 : VGS_WKB,
48 : VGS_Shape
49 : } OGRVRTGeometryStyle;
50 :
51 : /************************************************************************/
52 : /* OGRVRTLayer */
53 : /************************************************************************/
54 :
55 : class OGRVRTDataSource;
56 :
57 : class OGRVRTLayer : public OGRLayer
58 : {
59 : protected:
60 : OGRVRTDataSource* poDS;
61 :
62 : int bHasFullInitialized;
63 : CPLString osName;
64 : OGRwkbGeometryType eGeomType;
65 : CPLXMLNode *psLTree;
66 : CPLString osVRTDirectory;
67 :
68 : OGRFeatureDefn *poFeatureDefn;
69 :
70 : OGRDataSource *poSrcDS;
71 : OGRLayer *poSrcLayer;
72 : OGRFeatureDefn *poSrcFeatureDefn;
73 : int bNeedReset;
74 : int bSrcLayerFromSQL;
75 : int bSrcDSShared;
76 : int bAttrFilterPassThrough;
77 :
78 : // Layer spatial reference system, and srid.
79 : OGRSpatialReference *poSRS;
80 :
81 : char *pszAttrFilter;
82 :
83 : int bSrcClip;
84 : OGRGeometry *poSrcRegion;
85 :
86 : int iFIDField; // -1 means pass through.
87 : int iStyleField; // -1 means pass through.
88 :
89 : // Geometry interpretation related.
90 : OGRVRTGeometryStyle eGeometryStyle;
91 :
92 : int iGeomField;
93 :
94 : // VGS_PointFromColumn
95 : int iGeomXField, iGeomYField, iGeomZField;
96 :
97 : int bUseSpatialSubquery;
98 :
99 : // Attribute Mapping
100 : std::vector<int> anSrcField;
101 : std::vector<int> abDirectCopy;
102 :
103 : int bUpdate;
104 :
105 : OGRFeature *TranslateFeature( OGRFeature*& , int bUseSrcRegion );
106 : OGRFeature *TranslateVRTFeatureToSrcFeature( OGRFeature* poVRTFeature);
107 :
108 : int ResetSourceReading();
109 :
110 : int FullInitialize();
111 :
112 : OGRFeatureDefn *GetSrcLayerDefn();
113 : void ClipAndAssignSRS(OGRFeature* poFeature);
114 :
115 : int nFeatureCount;
116 : OGREnvelope sStaticEnvelope;
117 :
118 : public:
119 : OGRVRTLayer(OGRVRTDataSource* poDSIn);
120 : virtual ~OGRVRTLayer();
121 :
122 : int FastInitialize( CPLXMLNode *psLTree,
123 : const char *pszVRTDirectory,
124 : int bUpdate);
125 :
126 391 : virtual const char *GetName() { return osName.c_str(); }
127 : virtual OGRwkbGeometryType GetGeomType();
128 :
129 : /* -------------------------------------------------------------------- */
130 : /* Caution : all the below methods should care of calling */
131 : /* FullInitialize() if not already done */
132 : /* -------------------------------------------------------------------- */
133 :
134 : virtual void ResetReading();
135 : virtual OGRFeature *GetNextFeature();
136 :
137 : virtual OGRFeature *GetFeature( long nFeatureId );
138 :
139 : virtual OGRErr SetNextByIndex( long nIndex );
140 :
141 : virtual OGRFeatureDefn *GetLayerDefn();
142 :
143 : virtual OGRSpatialReference *GetSpatialRef();
144 :
145 : virtual int GetFeatureCount( int );
146 :
147 : virtual OGRErr SetAttributeFilter( const char * );
148 :
149 : virtual int TestCapability( const char * );
150 :
151 : virtual OGRErr GetExtent( OGREnvelope *psExtent, int bForce );
152 :
153 : virtual void SetSpatialFilter( OGRGeometry * poGeomIn );
154 :
155 : virtual OGRErr CreateFeature( OGRFeature* poFeature );
156 :
157 : virtual OGRErr SetFeature( OGRFeature* poFeature );
158 :
159 : virtual OGRErr DeleteFeature( long nFID );
160 :
161 : virtual OGRErr SyncToDisk();
162 :
163 : virtual const char *GetFIDColumn();
164 :
165 : virtual OGRErr StartTransaction();
166 : virtual OGRErr CommitTransaction();
167 : virtual OGRErr RollbackTransaction();
168 :
169 : virtual OGRErr SetIgnoredFields( const char **papszFields );
170 : };
171 :
172 : /************************************************************************/
173 : /* OGRVRTDataSource */
174 : /************************************************************************/
175 :
176 : class OGRVRTDataSource : public OGRDataSource
177 : {
178 : OGRLayer **papoLayers;
179 : int nLayers;
180 :
181 : char *pszName;
182 :
183 : CPLXMLNode *psTree;
184 :
185 : int nCallLevel;
186 :
187 : std::set<std::string> aosOtherDSNameSet;
188 :
189 : OGRLayer* InstanciateWarpedLayer(CPLXMLNode *psLTree,
190 : const char *pszVRTDirectory,
191 : int bUpdate,
192 : int nRecLevel);
193 : OGRLayer* InstanciateUnionLayer(CPLXMLNode *psLTree,
194 : const char *pszVRTDirectory,
195 : int bUpdate,
196 : int nRecLevel);
197 :
198 : OGRLayerPool* poLayerPool;
199 :
200 : OGRVRTDataSource *poParentDS;
201 : int bRecursionDetected;
202 :
203 : public:
204 : OGRVRTDataSource();
205 : ~OGRVRTDataSource();
206 :
207 : OGRLayer* InstanciateLayer(CPLXMLNode *psLTree,
208 : const char *pszVRTDirectory,
209 : int bUpdate,
210 : int nRecLevel = 0);
211 :
212 : OGRLayer* InstanciateLayerInternal(CPLXMLNode *psLTree,
213 : const char *pszVRTDirectory,
214 : int bUpdate,
215 : int nRecLevel);
216 :
217 : int Initialize( CPLXMLNode *psXML, const char *pszName,
218 : int bUpdate );
219 :
220 101 : const char *GetName() { return pszName; }
221 354 : int GetLayerCount() { return nLayers; }
222 : OGRLayer *GetLayer( int );
223 :
224 : int TestCapability( const char * );
225 :
226 : /* Anti-recursion mechanism for standard Open */
227 64 : void SetCallLevel(int nCallLevelIn) { nCallLevel = nCallLevelIn; }
228 272 : int GetCallLevel() { return nCallLevel; }
229 :
230 64 : void SetParentDS(OGRVRTDataSource* poParentDSIn) { poParentDS = poParentDSIn; }
231 66 : OGRVRTDataSource* GetParentDS() { return poParentDS; }
232 :
233 69 : void SetRecursionDetected() { bRecursionDetected = TRUE; }
234 14471 : int GetRecursionDetected() { return bRecursionDetected; }
235 :
236 : /* Anti-recursion mechanism for shared Open */
237 : void AddForbiddenNames(const char* pszOtherDSName);
238 : int IsInForbiddenNames(const char* pszOtherDSName);
239 : };
240 :
241 : /************************************************************************/
242 : /* OGRVRTDriver */
243 : /************************************************************************/
244 :
245 : class OGRVRTDriver : public OGRSFDriver
246 226 : {
247 : public:
248 : ~OGRVRTDriver();
249 :
250 : const char *GetName();
251 : OGRDataSource *Open( const char *, int );
252 : int TestCapability( const char * );
253 : };
254 :
255 : OGRwkbGeometryType OGRVRTGetGeometryType(const char* pszGType, int* pbError);
256 :
257 : #endif /* ndef _OGR_VRT_H_INCLUDED */
258 :
259 :
|