LCOV - code coverage report
Current view: top level - ogr/ogrsf_frmts/vrt - ogr_vrt.h (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 19 19 100.0 %
Date: 2025-02-20 10:14:44 Functions: 8 8 100.0 %

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

Generated by: LCOV version 1.14