Line data Source code
1 : /****************************************************************************** 2 : * 3 : * Project: OpenGIS Simple Features Reference Implementation 4 : * Purpose: Private definitions for OGR/VRT driver. 5 : * Author: Frank Warmerdam, warmerdam@pobox.com 6 : * 7 : ****************************************************************************** 8 : * Copyright (c) 2003, Frank Warmerdam <warmerdam@pobox.com> 9 : * Copyright (c) 2009-2014, Even Rouault <even dot rouault at spatialys.com> 10 : * 11 : * SPDX-License-Identifier: MIT 12 : ****************************************************************************/ 13 : 14 : #ifndef OGR_VRT_H_INCLUDED 15 : #define OGR_VRT_H_INCLUDED 16 : 17 : #include "cpl_error.h" 18 : #include "cpl_minixml.h" 19 : #include "cpl_string.h" 20 : #include "ogrlayerpool.h" 21 : #include "ogrsf_frmts.h" 22 : 23 : #include <set> 24 : #include <string> 25 : #include <vector> 26 : 27 : typedef enum 28 : { 29 : VGS_None, 30 : VGS_Direct, 31 : VGS_PointFromColumns, 32 : VGS_WKT, 33 : VGS_WKB, 34 : VGS_Shape 35 : } OGRVRTGeometryStyle; 36 : 37 : /************************************************************************/ 38 : /* OGRVRTGeomFieldProps */ 39 : /************************************************************************/ 40 : 41 799 : class OGRVRTGeomFieldProps 42 : { 43 : public: 44 : CPLString osName{}; // Name of the VRT geometry field */ 45 : OGRwkbGeometryType eGeomType = wkbUnknown; 46 : const OGRSpatialReference *poSRS = nullptr; 47 : 48 : bool bSrcClip = false; 49 : std::unique_ptr<OGRGeometry> poSrcRegion{}; 50 : 51 : // Geometry interpretation related. 52 : OGRVRTGeometryStyle eGeometryStyle = VGS_Direct; 53 : 54 : // Points to a OGRField for VGS_WKT, VGS_WKB, VGS_Shape and OGRGeomField 55 : // for VGS_Direct. 56 : int iGeomField = -1; 57 : 58 : // VGS_PointFromColumn 59 : int iGeomXField = -1; 60 : int iGeomYField = -1; 61 : int iGeomZField = -1; 62 : int iGeomMField = -1; 63 : bool bReportSrcColumn = true; 64 : bool bUseSpatialSubquery = false; 65 : bool bNullable = true; 66 : 67 : OGREnvelope sStaticEnvelope{}; 68 : 69 : OGRGeomCoordinatePrecision sCoordinatePrecision{}; 70 : 71 : OGRVRTGeomFieldProps(); 72 : ~OGRVRTGeomFieldProps(); 73 : 74 : private: 75 : CPL_DISALLOW_COPY_ASSIGN(OGRVRTGeomFieldProps) 76 : }; 77 : 78 : /************************************************************************/ 79 : /* OGRVRTLayer */ 80 : /************************************************************************/ 81 : 82 : class OGRVRTDataSource; 83 : 84 : class OGRVRTLayer final : public OGRLayer 85 : { 86 : protected: 87 : OGRVRTDataSource *poDS = nullptr; 88 : std::vector<std::unique_ptr<OGRVRTGeomFieldProps>> apoGeomFieldProps{}; 89 : 90 : bool bHasFullInitialized = false; 91 : CPLString osName{}; 92 : CPLXMLNode *psLTree = nullptr; 93 : CPLString osVRTDirectory{}; 94 : 95 : OGRFeatureDefn *poFeatureDefn = nullptr; 96 : 97 : std::unique_ptr<GDALDataset, GDALDatasetUniquePtrReleaser> poSrcDS{}; 98 : OGRLayer *poSrcLayer = nullptr; 99 : OGRFeatureDefn *poSrcFeatureDefn = nullptr; 100 : bool bNeedReset = true; 101 : bool bSrcLayerFromSQL = false; 102 : bool bSrcDSShared = false; 103 : bool bAttrFilterPassThrough = false; 104 : 105 : char *pszAttrFilter = nullptr; 106 : 107 : int iFIDField = -1; // -1 means pass through. 108 : CPLString osFIDFieldName{}; 109 : int iStyleField = -1; // -1 means pass through. 110 : 111 : // Attribute mapping. 112 : std::vector<int> anSrcField{}; 113 : std::vector<int> abDirectCopy{}; 114 : 115 : bool bUpdate = false; 116 : 117 : GIntBig nFeatureCount = -1; 118 : 119 : bool bError = false; 120 : 121 : bool m_bEmptyResultSet = false; 122 : 123 : OGRFeature *TranslateFeature(OGRFeature *&, int bUseSrcRegion); 124 : OGRFeature *TranslateVRTFeatureToSrcFeature(OGRFeature *poVRTFeature); 125 : 126 : bool ResetSourceReading(); 127 : 128 : bool FullInitialize(); 129 : 130 : OGRFeatureDefn *GetSrcLayerDefn(); 131 : void ClipAndAssignSRS(OGRFeature *poFeature); 132 : 133 : bool ParseGeometryField(CPLXMLNode *psNode, CPLXMLNode *psNodeParent, 134 : OGRVRTGeomFieldProps *poProps); 135 : 136 : CPL_DISALLOW_COPY_ASSIGN(OGRVRTLayer) 137 : 138 : public: 139 : explicit OGRVRTLayer(OGRVRTDataSource *poDSIn); 140 : virtual ~OGRVRTLayer(); 141 : 142 : bool FastInitialize(CPLXMLNode *psLTree, const char *pszVRTDirectory, 143 : int bUpdate); 144 : 145 649 : virtual const char *GetName() override 146 : { 147 649 : return osName.c_str(); 148 : } 149 : 150 : virtual OGRwkbGeometryType GetGeomType() override; 151 : 152 : /* -------------------------------------------------------------------- */ 153 : /* Caution : all the below methods should care of calling */ 154 : /* FullInitialize() if not already done */ 155 : /* -------------------------------------------------------------------- */ 156 : 157 : virtual void ResetReading() override; 158 : virtual OGRFeature *GetNextFeature() override; 159 : 160 : virtual OGRFeature *GetFeature(GIntBig nFeatureId) override; 161 : 162 : virtual OGRErr SetNextByIndex(GIntBig nIndex) override; 163 : 164 : virtual OGRFeatureDefn *GetLayerDefn() override; 165 : 166 : virtual GIntBig GetFeatureCount(int) override; 167 : 168 : virtual OGRErr SetAttributeFilter(const char *) override; 169 : 170 : virtual int TestCapability(const char *) override; 171 : 172 : virtual OGRErr IGetExtent(int iGeomField, OGREnvelope *psExtent, 173 : bool bForce = TRUE) override; 174 : 175 : virtual OGRErr ISetSpatialFilter(int iGeomField, 176 : const OGRGeometry *poGeomIn) override; 177 : 178 : virtual OGRErr ICreateFeature(OGRFeature *poFeature) override; 179 : 180 : virtual OGRErr ISetFeature(OGRFeature *poFeature) override; 181 : 182 : virtual OGRErr DeleteFeature(GIntBig nFID) override; 183 : 184 : virtual OGRErr SyncToDisk() override; 185 : 186 : virtual const char *GetFIDColumn() override; 187 : 188 : virtual OGRErr StartTransaction() override; 189 : virtual OGRErr CommitTransaction() override; 190 : virtual OGRErr RollbackTransaction() override; 191 : 192 : virtual OGRErr SetIgnoredFields(CSLConstList papszFields) override; 193 : 194 : GDALDataset *GetSrcDataset(); 195 : }; 196 : 197 : /************************************************************************/ 198 : /* OGRVRTDataSource */ 199 : /************************************************************************/ 200 : 201 : typedef enum 202 : { 203 : OGR_VRT_PROXIED_LAYER, 204 : OGR_VRT_LAYER, 205 : OGR_VRT_OTHER_LAYER, 206 : } OGRLayerType; 207 : 208 : class OGRVRTDataSource final : public GDALDataset 209 : { 210 : std::unique_ptr<OGRLayerPool> poLayerPool{}; 211 : 212 : OGRLayer **papoLayers = nullptr; 213 : OGRLayerType *paeLayerType = nullptr; 214 : int nLayers = 0; 215 : 216 : CPLXMLNode *psTree = nullptr; 217 : 218 : int nCallLevel = 0; 219 : 220 : std::set<std::string> aosOtherDSNameSet{}; 221 : 222 : OGRVRTDataSource *poParentDS = nullptr; 223 : bool bRecursionDetected = false; 224 : 225 : OGRLayer *InstantiateWarpedLayer(CPLXMLNode *psLTree, 226 : const char *pszVRTDirectory, int bUpdate, 227 : int nRecLevel); 228 : OGRLayer *InstantiateUnionLayer(CPLXMLNode *psLTree, 229 : const char *pszVRTDirectory, int bUpdate, 230 : int nRecLevel); 231 : 232 : CPL_DISALLOW_COPY_ASSIGN(OGRVRTDataSource) 233 : 234 : public: 235 : explicit OGRVRTDataSource(GDALDriver *poDriver); 236 : virtual ~OGRVRTDataSource(); 237 : 238 : virtual int CloseDependentDatasets() override; 239 : 240 : OGRLayer *InstantiateLayer(CPLXMLNode *psLTree, const char *pszVRTDirectory, 241 : int bUpdate, int nRecLevel = 0); 242 : 243 : OGRLayer *InstantiateLayerInternal(CPLXMLNode *psLTree, 244 : const char *pszVRTDirectory, int bUpdate, 245 : int nRecLevel); 246 : 247 : bool Initialize(CPLXMLNode *psXML, const char *pszName, int bUpdate); 248 : 249 835 : int GetLayerCount() override 250 : { 251 835 : return nLayers; 252 : } 253 : 254 : OGRLayer *GetLayer(int) override; 255 : 256 : int TestCapability(const char *) override; 257 : 258 : virtual char **GetFileList() override; 259 : 260 : // Anti-recursion mechanism for standard Open. 261 66 : void SetCallLevel(int nCallLevelIn) 262 : { 263 66 : nCallLevel = nCallLevelIn; 264 66 : } 265 : 266 434 : int GetCallLevel() const 267 : { 268 434 : return nCallLevel; 269 : } 270 : 271 66 : void SetParentDS(OGRVRTDataSource *poParentDSIn) 272 : { 273 66 : poParentDS = poParentDSIn; 274 66 : } 275 : 276 66 : OGRVRTDataSource *GetParentDS() 277 : { 278 66 : return poParentDS; 279 : } 280 : 281 70 : void SetRecursionDetected() 282 : { 283 70 : bRecursionDetected = true; 284 70 : } 285 : 286 33989 : bool GetRecursionDetected() const 287 : { 288 33989 : return bRecursionDetected; 289 : } 290 : 291 : // Anti-recursion mechanism for shared Open. 292 : void AddForbiddenNames(const char *pszOtherDSName); 293 : bool IsInForbiddenNames(const char *pszOtherDSName) const; 294 : }; 295 : 296 : #endif // ndef OGR_VRT_H_INCLUDED