LCOV - code coverage report
Current view: top level - ogr/ogrsf_frmts/gml - ogr_gml.h (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 44 44 100.0 %
Date: 2025-10-22 13:51:22 Functions: 21 21 100.0 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  *
       3             :  * Project:  GML Reader
       4             :  * Purpose:  Declarations for OGR wrapper classes for GML, and GML<->OGR
       5             :  *           translation of geometry.
       6             :  * Author:   Frank Warmerdam, warmerdam@pobox.com
       7             :  *
       8             :  ******************************************************************************
       9             :  * Copyright (c) 2002, Frank Warmerdam
      10             :  * Copyright (c) 2010-2013, Even Rouault <even dot rouault at spatialys.com>
      11             :  *
      12             :  * SPDX-License-Identifier: MIT
      13             :  ****************************************************************************/
      14             : 
      15             : #ifndef OGR_GML_H_INCLUDED
      16             : #define OGR_GML_H_INCLUDED
      17             : 
      18             : #include "ogrsf_frmts.h"
      19             : #include "gmlreader.h"
      20             : #include "gmlutils.h"
      21             : 
      22             : #include <memory>
      23             : #include <set>
      24             : #include <vector>
      25             : 
      26             : class OGRGMLDataSource;
      27             : 
      28             : typedef enum
      29             : {
      30             :     STANDARD,
      31             :     SEQUENTIAL_LAYERS,
      32             :     INTERLEAVED_LAYERS
      33             : } ReadMode;
      34             : 
      35             : /************************************************************************/
      36             : /*                            OGRGMLLayer                               */
      37             : /************************************************************************/
      38             : 
      39             : class OGRGMLLayer final : public OGRLayer
      40             : {
      41             :     OGRFeatureDefn *poFeatureDefn;
      42             : 
      43             :     GIntBig m_iNextGMLId = 0;
      44             :     bool m_bInvalidFIDFound = false;
      45             :     char *m_pszFIDPrefix = nullptr;
      46             :     std::set<GIntBig> m_oSetFIDs{};
      47             : 
      48             :     bool bWriter;
      49             : 
      50             :     OGRGMLDataSource *poDS;
      51             : 
      52             :     GMLFeatureClass *poFClass;
      53             : 
      54             :     void *hCacheSRS;
      55             : 
      56             :     bool bUseOldFIDFormat;
      57             : 
      58             :     bool bFaceHoleNegative;
      59             : 
      60             :     CPL_DISALLOW_COPY_ASSIGN(OGRGMLLayer)
      61             : 
      62             :   public:
      63             :     OGRGMLLayer(const char *pszName, bool bWriter, OGRGMLDataSource *poDS);
      64             : 
      65             :     ~OGRGMLLayer() override;
      66             : 
      67             :     GDALDataset *GetDataset() override;
      68             : 
      69             :     void ResetReading() override;
      70             :     OGRFeature *GetNextFeature() override;
      71             : 
      72             :     GIntBig GetFeatureCount(int bForce = TRUE) override;
      73             :     OGRErr IGetExtent(int iGeomField, OGREnvelope *psExtent,
      74             :                       bool bForce) override;
      75             : 
      76             :     OGRErr ICreateFeature(OGRFeature *poFeature) override;
      77             : 
      78        7212 :     const OGRFeatureDefn *GetLayerDefn() const override
      79             :     {
      80        7212 :         return poFeatureDefn;
      81             :     }
      82             : 
      83             :     virtual OGRErr CreateField(const OGRFieldDefn *poField,
      84             :                                int bApproxOK = TRUE) override;
      85             :     virtual OGRErr CreateGeomField(const OGRGeomFieldDefn *poField,
      86             :                                    int bApproxOK = TRUE) override;
      87             : 
      88             :     int TestCapability(const char *) const override;
      89             : };
      90             : 
      91             : /************************************************************************/
      92             : /*                           OGRGMLDataSource                           */
      93             : /************************************************************************/
      94             : 
      95             : class OGRGMLDataSource final : public GDALDataset
      96             : {
      97             :     OGRLayer **papoLayers;
      98             :     int nLayers;
      99             : 
     100             :     OGRLayer *TranslateGMLSchema(GMLFeatureClass *);
     101             : 
     102             :     char **papszCreateOptions;
     103             : 
     104             :     // output related parameters
     105             :     VSILFILE *fpOutput;
     106             :     bool bFpOutputIsNonSeekable;
     107             :     bool bFpOutputSingleFile;
     108             :     bool m_bWriteError = false;
     109             :     OGREnvelope3D sBoundingRect{};
     110             :     bool bBBOX3D;
     111             :     int nBoundedByLocation;
     112             : 
     113             :     int nSchemaInsertLocation;
     114             :     bool bIsOutputGML3;
     115             :     bool bIsOutputGML3Deegree; /* if TRUE, then bIsOutputGML3 is also TRUE */
     116             :     bool bIsOutputGML32;       /* if TRUE, then bIsOutputGML3 is also TRUE */
     117             :     OGRGMLSRSNameFormat eSRSNameFormat;
     118             :     bool bWriteSpaceIndentation;
     119             : 
     120             :     //! Whether all geometry fields of all layers have the same SRS (or no SRS at all)
     121             :     bool m_bWriteGlobalSRS = true;
     122             : 
     123             :     //! The global SRS (may be null), that is valid only if m_bWriteGlobalSRS == true
     124             :     std::unique_ptr<OGRSpatialReference> m_poWriteGlobalSRS{};
     125             : 
     126             :     //! Whether at least one geometry field has been created
     127             :     bool m_bWriteGlobalSRSInit = false;
     128             : 
     129             :     // input related parameters.
     130             :     CPLString osFilename{};
     131             :     CPLString osXSDFilename{};
     132             :     bool m_bUnlinkXSDFilename = false;
     133             : 
     134             :     IGMLReader *poReader;
     135             :     bool bOutIsTempFile;
     136             : 
     137             :     void InsertHeader();
     138             : 
     139             :     bool bExposeGMLId;
     140             :     bool bExposeFid;
     141             :     bool bIsWFS;
     142             : 
     143             :     bool bUseGlobalSRSName;
     144             : 
     145             :     bool m_bInvertAxisOrderIfLatLong;
     146             :     bool m_bConsiderEPSGAsURN;
     147             :     GMLSwapCoordinatesEnum m_eSwapCoordinates;
     148             :     bool m_bGetSecondaryGeometryOption;
     149             : 
     150             :     ReadMode eReadMode;
     151             :     GMLFeature *poStoredGMLFeature;
     152             :     OGRGMLLayer *poLastReadLayer;
     153             : 
     154             :     bool bEmptyAsNull;
     155             : 
     156             :     OGRSpatialReference m_oStandaloneGeomSRS{};
     157             :     std::unique_ptr<OGRGeometry> m_poStandaloneGeom{};
     158             : 
     159             :     std::vector<std::string> m_aosGMLExtraElements{};
     160             : 
     161             :     void FindAndParseTopElements(VSILFILE *fp);
     162             :     void SetExtents(double dfMinX, double dfMinY, double dfMaxX, double dfMaxY);
     163             : 
     164             :     void BuildJointClassFromXSD();
     165             :     void BuildJointClassFromScannedSchema();
     166             : 
     167             :     void WriteTopElements();
     168             : 
     169             :     // Analyze the OGR_SCHEMA open options and apply changes to the GML reader, return false in case of a critical error
     170             :     bool DealWithOgrSchemaOpenOption(const GDALOpenInfo *poOpenInfo);
     171             : 
     172             :     CPL_DISALLOW_COPY_ASSIGN(OGRGMLDataSource)
     173             : 
     174             :   public:
     175             :     OGRGMLDataSource();
     176             :     ~OGRGMLDataSource() override;
     177             : 
     178             :     bool Open(GDALOpenInfo *poOpenInfo);
     179             :     CPLErr Close() override;
     180             :     bool Create(const char *pszFile, char **papszOptions);
     181             : 
     182        1503 :     int GetLayerCount() const override
     183             :     {
     184        1503 :         return nLayers;
     185             :     }
     186             : 
     187             :     using GDALDataset::GetLayer;
     188             :     const OGRLayer *GetLayer(int) const override;
     189             :     OGRLayer *ICreateLayer(const char *pszName,
     190             :                            const OGRGeomFieldDefn *poGeomFieldDefn,
     191             :                            CSLConstList papszOptions) override;
     192             :     int TestCapability(const char *) const override;
     193             : 
     194         266 :     VSILFILE *GetOutputFP() const
     195             :     {
     196         266 :         return fpOutput;
     197             :     }
     198             : 
     199        3165 :     IGMLReader *GetReader() const
     200             :     {
     201        3165 :         return poReader;
     202             :     }
     203             : 
     204             :     void GrowExtents(OGREnvelope3D *psGeomBounds, int nCoordDimension);
     205             : 
     206         741 :     int ExposeId() const
     207             :     {
     208         741 :         return bExposeGMLId || bExposeFid;
     209             :     }
     210             : 
     211             :     void PrintLine(VSILFILE *fp, const char *fmt, ...)
     212             :         CPL_PRINT_FUNC_FORMAT(3, 4);
     213             : 
     214        1778 :     bool IsGML3Output() const
     215             :     {
     216        1778 :         return bIsOutputGML3;
     217             :     }
     218             : 
     219         138 :     bool IsGML3DeegreeOutput() const
     220             :     {
     221         138 :         return bIsOutputGML3Deegree;
     222             :     }
     223             : 
     224         890 :     bool IsGML32Output() const
     225             :     {
     226         890 :         return bIsOutputGML32;
     227             :     }
     228             : 
     229             :     /** Returns whether a writing error has occurred */
     230         530 :     inline bool HasWriteError() const
     231             :     {
     232         530 :         return m_bWriteError;
     233             :     }
     234             : 
     235         575 :     OGRGMLSRSNameFormat GetSRSNameFormat() const
     236             :     {
     237         575 :         return eSRSNameFormat;
     238             :     }
     239             : 
     240         266 :     bool WriteSpaceIndentation() const
     241             :     {
     242         266 :         return bWriteSpaceIndentation;
     243             :     }
     244             : 
     245             :     const char *GetGlobalSRSName();
     246             : 
     247         714 :     bool GetInvertAxisOrderIfLatLong() const
     248             :     {
     249         714 :         return m_bInvertAxisOrderIfLatLong;
     250             :     }
     251             : 
     252         714 :     bool GetConsiderEPSGAsURN() const
     253             :     {
     254         714 :         return m_bConsiderEPSGAsURN;
     255             :     }
     256             : 
     257         714 :     GMLSwapCoordinatesEnum GetSwapCoordinates() const
     258             :     {
     259         714 :         return m_eSwapCoordinates;
     260             :     }
     261             : 
     262         714 :     bool GetSecondaryGeometryOption() const
     263             :     {
     264         714 :         return m_bGetSecondaryGeometryOption;
     265             :     }
     266             : 
     267        3774 :     ReadMode GetReadMode() const
     268             :     {
     269        3774 :         return eReadMode;
     270             :     }
     271             : 
     272         107 :     void SetStoredGMLFeature(GMLFeature *poStoredGMLFeatureIn)
     273             :     {
     274         107 :         poStoredGMLFeature = poStoredGMLFeatureIn;
     275         107 :     }
     276             : 
     277        1937 :     GMLFeature *PeekStoredGMLFeature() const
     278             :     {
     279        1937 :         return poStoredGMLFeature;
     280             :     }
     281             : 
     282         859 :     OGRGMLLayer *GetLastReadLayer() const
     283             :     {
     284         859 :         return poLastReadLayer;
     285             :     }
     286             : 
     287         403 :     void SetLastReadLayer(OGRGMLLayer *poLayer)
     288             :     {
     289         403 :         poLastReadLayer = poLayer;
     290         403 :     }
     291             : 
     292             :     const char *GetAppPrefix() const;
     293             :     bool RemoveAppPrefix() const;
     294             :     bool WriteFeatureBoundedBy() const;
     295             :     const char *GetSRSDimensionLoc() const;
     296             :     bool GMLFeatureCollection() const;
     297             : 
     298             :     void DeclareNewWriteSRS(const OGRSpatialReference *poSRS);
     299             : 
     300         215 :     bool HasWriteGlobalSRS() const
     301             :     {
     302         215 :         return m_bWriteGlobalSRS;
     303             :     }
     304             : 
     305             :     OGRLayer *ExecuteSQL(const char *pszSQLCommand,
     306             :                          OGRGeometry *poSpatialFilter,
     307             :                          const char *pszDialect) override;
     308             :     void ReleaseResultSet(OGRLayer *poResultsSet) override;
     309             : 
     310             :     static bool CheckHeader(const char *pszStr);
     311             : };
     312             : 
     313             : #endif /* OGR_GML_H_INCLUDED */

Generated by: LCOV version 1.14