1 : /******************************************************************************
2 : * $Id: ogr_vrt.h 23575 2011-12-14 20:24:08Z 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 :
37 : #include <vector>
38 : #include <string>
39 : #include <set>
40 :
41 : typedef enum {
42 : VGS_None,
43 : VGS_Direct,
44 : VGS_PointFromColumns,
45 : VGS_WKT,
46 : VGS_WKB,
47 : VGS_Shape
48 : } OGRVRTGeometryStyle;
49 :
50 : /************************************************************************/
51 : /* OGRVRTLayer */
52 : /************************************************************************/
53 :
54 : class OGRVRTDataSource;
55 :
56 : class OGRVRTLayer : public OGRLayer
57 : {
58 : protected:
59 : OGRVRTDataSource* poDS;
60 :
61 : int bHasFullInitialized;
62 : CPLString osName;
63 : OGRwkbGeometryType eGeomType;
64 : CPLXMLNode *psLTree;
65 : CPLString osVRTDirectory;
66 :
67 : OGRFeatureDefn *poFeatureDefn;
68 :
69 : OGRDataSource *poSrcDS;
70 : OGRLayer *poSrcLayer;
71 : int bNeedReset;
72 : int bSrcLayerFromSQL;
73 : int bSrcDSShared;
74 : int bAttrFilterPassThrough;
75 :
76 : // Layer spatial reference system, and srid.
77 : OGRSpatialReference *poSRS;
78 :
79 : char *pszAttrFilter;
80 :
81 : int bSrcClip;
82 : OGRGeometry *poSrcRegion;
83 :
84 : int iFIDField; // -1 means pass through.
85 : int iStyleField; // -1 means pass through.
86 :
87 : // Geometry interpretation related.
88 : OGRVRTGeometryStyle eGeometryStyle;
89 :
90 : int iGeomField;
91 :
92 : // VGS_PointFromColumn
93 : int iGeomXField, iGeomYField, iGeomZField;
94 :
95 : int bUseSpatialSubquery;
96 :
97 : // Attribute Mapping
98 : std::vector<int> anSrcField;
99 : std::vector<int> abDirectCopy;
100 :
101 : int bUpdate;
102 :
103 : OGRFeature *TranslateFeature( OGRFeature*& , int bUseSrcRegion );
104 : OGRErr createFromShapeBin( GByte *, OGRGeometry **, int );
105 :
106 : OGRFeature *TranslateVRTFeatureToSrcFeature( OGRFeature* poVRTFeature);
107 :
108 : int ResetSourceReading();
109 :
110 : int FullInitialize();
111 :
112 : public:
113 : OGRVRTLayer(OGRVRTDataSource* poDSIn);
114 : virtual ~OGRVRTLayer();
115 :
116 : int FastInitialize( CPLXMLNode *psLTree,
117 : const char *pszVRTDirectory,
118 : int bUpdate);
119 :
120 208 : virtual const char *GetName() { return osName.c_str(); }
121 : virtual OGRwkbGeometryType GetGeomType();
122 :
123 : /* -------------------------------------------------------------------- */
124 : /* Caution : all the below methods should care of calling */
125 : /* FullInitialize() if not already done */
126 : /* -------------------------------------------------------------------- */
127 :
128 : virtual void ResetReading();
129 : virtual OGRFeature *GetNextFeature();
130 :
131 : virtual OGRFeature *GetFeature( long nFeatureId );
132 :
133 : virtual OGRErr SetNextByIndex( long nIndex );
134 :
135 : virtual OGRFeatureDefn *GetLayerDefn();
136 :
137 : virtual OGRSpatialReference *GetSpatialRef();
138 :
139 : virtual int GetFeatureCount( int );
140 :
141 : virtual OGRErr SetAttributeFilter( const char * );
142 :
143 : virtual int TestCapability( const char * );
144 :
145 : virtual OGRErr GetExtent( OGREnvelope *psExtent, int bForce );
146 :
147 : virtual void SetSpatialFilter( OGRGeometry * poGeomIn );
148 :
149 : virtual OGRErr CreateFeature( OGRFeature* poFeature );
150 :
151 : virtual OGRErr SetFeature( OGRFeature* poFeature );
152 :
153 : virtual OGRErr DeleteFeature( long nFID );
154 :
155 : virtual OGRErr SyncToDisk();
156 : };
157 :
158 : /************************************************************************/
159 : /* OGRVRTDataSource */
160 : /************************************************************************/
161 :
162 : class OGRVRTDataSource : public OGRDataSource
163 : {
164 : OGRVRTLayer **papoLayers;
165 : int nLayers;
166 :
167 : char *pszName;
168 :
169 : CPLXMLNode *psTree;
170 :
171 : int nCallLevel;
172 :
173 : std::set<std::string> aosOtherDSNameSet;
174 :
175 : public:
176 : OGRVRTDataSource();
177 : ~OGRVRTDataSource();
178 :
179 : int Initialize( CPLXMLNode *psXML, const char *pszName,
180 : int bUpdate );
181 :
182 53 : const char *GetName() { return pszName; }
183 215 : int GetLayerCount() { return nLayers; }
184 : OGRLayer *GetLayer( int );
185 :
186 : int TestCapability( const char * );
187 :
188 : /* Anti-recursion mechanism for standard Open */
189 32 : void SetCallLevel(int nCallLevelIn) { nCallLevel = nCallLevelIn; }
190 105 : int GetCallLevel() { return nCallLevel; }
191 :
192 : /* Anti-recursion mechanism for shared Open */
193 : void AddForbiddenNames(const char* pszOtherDSName);
194 : int IsInForbiddenNames(const char* pszOtherDSName);
195 : };
196 :
197 : /************************************************************************/
198 : /* OGRVRTDriver */
199 : /************************************************************************/
200 :
201 : class OGRVRTDriver : public OGRSFDriver
202 178 : {
203 : public:
204 : ~OGRVRTDriver();
205 :
206 : const char *GetName();
207 : OGRDataSource *Open( const char *, int );
208 : int TestCapability( const char * );
209 : };
210 :
211 :
212 : #endif /* ndef _OGR_VRT_H_INCLUDED */
213 :
214 :
|