LCOV - code coverage report
Current view: top level - ogr/ogrsf_frmts/gml - gmlreader.h (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 99 105 94.3 %
Date: 2024-05-07 17:03:27 Functions: 43 46 93.5 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  * $Id$
       3             :  *
       4             :  * Project:  GML Reader
       5             :  * Purpose:  Public Declarations for OGR free GML Reader code.
       6             :  * Author:   Frank Warmerdam, warmerdam@pobox.com
       7             :  *
       8             :  ******************************************************************************
       9             :  * Copyright (c) 2002, Frank Warmerdam
      10             :  * Copyright (c) 2008-2013, Even Rouault <even dot rouault at spatialys.com>
      11             :  *
      12             :  * Permission is hereby granted, free of charge, to any person obtaining a
      13             :  * copy of this software and associated documentation files (the "Software"),
      14             :  * to deal in the Software without restriction, including without limitation
      15             :  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
      16             :  * and/or sell copies of the Software, and to permit persons to whom the
      17             :  * Software is furnished to do so, subject to the following conditions:
      18             :  *
      19             :  * The above copyright notice and this permission notice shall be included
      20             :  * in all copies or substantial portions of the Software.
      21             :  *
      22             :  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
      23             :  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      24             :  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
      25             :  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      26             :  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
      27             :  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
      28             :  * DEALINGS IN THE SOFTWARE.
      29             :  ****************************************************************************/
      30             : 
      31             : #ifndef GMLREADER_H_INCLUDED
      32             : #define GMLREADER_H_INCLUDED
      33             : 
      34             : #include "cpl_port.h"
      35             : #include "cpl_vsi.h"
      36             : #include "cpl_minixml.h"
      37             : #include "ogr_core.h"
      38             : #include "gmlutils.h"
      39             : 
      40             : #include <map>
      41             : #include <vector>
      42             : 
      43             : // Special value to map to a NULL field
      44             : #define OGR_GML_NULL "___OGR_GML_NULL___"
      45             : 
      46             : typedef enum
      47             : {
      48             :     GMLPT_Untyped = 0,
      49             :     GMLPT_String = 1,
      50             :     GMLPT_Integer = 2,
      51             :     GMLPT_Real = 3,
      52             :     GMLPT_Complex = 4,
      53             :     GMLPT_StringList = 5,
      54             :     GMLPT_IntegerList = 6,
      55             :     GMLPT_RealList = 7,
      56             :     GMLPT_FeatureProperty = 8,
      57             :     GMLPT_FeaturePropertyList = 9,
      58             :     GMLPT_Boolean = 10,
      59             :     GMLPT_BooleanList = 11,
      60             :     GMLPT_Short = 12,
      61             :     GMLPT_Float = 13,
      62             :     GMLPT_Integer64 = 14,
      63             :     GMLPT_Integer64List = 15,
      64             :     GMLPT_DateTime = 16,
      65             :     GMLPT_Date = 17,
      66             :     GMLPT_Time = 18,
      67             : } GMLPropertyType;
      68             : 
      69             : /************************************************************************/
      70             : /*                           GMLPropertyDefn                            */
      71             : /************************************************************************/
      72             : 
      73             : typedef struct
      74             : {
      75             :     int nSubProperties;
      76             :     char **papszSubProperties;
      77             :     char *aszSubProperties[2]; /* Optimization in the case of nSubProperties ==
      78             :                                   1 */
      79             : } GMLProperty;
      80             : 
      81             : class CPL_DLL GMLPropertyDefn
      82             : {
      83             :     char *m_pszName;
      84             :     GMLPropertyType m_eType;
      85             :     int m_nWidth;
      86             :     int m_nPrecision;
      87             :     char *m_pszSrcElement;
      88             :     size_t m_nSrcElementLen;
      89             :     char *m_pszCondition;
      90             :     bool m_bNullable;
      91             :     bool m_bUnique = false;
      92             :     std::string m_osDocumentation{};
      93             : 
      94             :   public:
      95             :     explicit GMLPropertyDefn(const char *pszName,
      96             :                              const char *pszSrcElement = nullptr);
      97             :     ~GMLPropertyDefn();
      98             : 
      99        8447 :     const char *GetName() const
     100             :     {
     101        8447 :         return m_pszName;
     102             :     }
     103             : 
     104       15225 :     GMLPropertyType GetType() const
     105             :     {
     106       15225 :         return m_eType;
     107             :     }
     108             : 
     109        2278 :     void SetType(GMLPropertyType eType)
     110             :     {
     111        2278 :         m_eType = eType;
     112        2278 :     }
     113             : 
     114        2349 :     void SetWidth(int nWidth)
     115             :     {
     116        2349 :         m_nWidth = nWidth;
     117        2349 :     }
     118             : 
     119        4093 :     int GetWidth() const
     120             :     {
     121        4093 :         return m_nWidth;
     122             :     }
     123             : 
     124        1530 :     void SetPrecision(int nPrecision)
     125             :     {
     126        1530 :         m_nPrecision = nPrecision;
     127        1530 :     }
     128             : 
     129        2545 :     int GetPrecision() const
     130             :     {
     131        2545 :         return m_nPrecision;
     132             :     }
     133             : 
     134             :     void SetSrcElement(const char *pszSrcElement);
     135             : 
     136       15135 :     const char *GetSrcElement() const
     137             :     {
     138       15135 :         return m_pszSrcElement;
     139             :     }
     140             : 
     141             :     size_t GetSrcElementLen() const
     142             :     {
     143             :         return m_nSrcElementLen;
     144             :     }
     145             : 
     146             :     void SetCondition(const char *pszCondition);
     147             : 
     148        2675 :     const char *GetCondition() const
     149             :     {
     150        2675 :         return m_pszCondition;
     151             :     }
     152             : 
     153        2160 :     void SetNullable(bool bNullable)
     154             :     {
     155        2160 :         m_bNullable = bNullable;
     156        2160 :     }
     157             : 
     158         108 :     bool IsNullable() const
     159             :     {
     160         108 :         return m_bNullable;
     161             :     }
     162             : 
     163         641 :     void SetUnique(bool bUnique)
     164             :     {
     165         641 :         m_bUnique = bUnique;
     166         641 :     }
     167             : 
     168        1866 :     bool IsUnique() const
     169             :     {
     170        1866 :         return m_bUnique;
     171             :     }
     172             : 
     173          12 :     void SetDocumentation(const std::string &osDocumentation)
     174             :     {
     175          12 :         m_osDocumentation = osDocumentation;
     176          12 :     }
     177             : 
     178        2235 :     const std::string &GetDocumentation() const
     179             :     {
     180        2235 :         return m_osDocumentation;
     181             :     }
     182             : 
     183             :     void AnalysePropertyValue(const GMLProperty *psGMLProperty,
     184             :                               bool bSetWidth = true);
     185             : 
     186          82 :     static bool IsSimpleType(GMLPropertyType eType)
     187             :     {
     188          82 :         return eType == GMLPT_String || eType == GMLPT_Integer ||
     189          82 :                eType == GMLPT_Real;
     190             :     }
     191             : };
     192             : 
     193             : /************************************************************************/
     194             : /*                    GMLGeometryPropertyDefn                           */
     195             : /************************************************************************/
     196             : 
     197             : class CPL_DLL GMLGeometryPropertyDefn
     198             : {
     199             :     char *m_pszName;
     200             :     char *m_pszSrcElement;
     201             :     OGRwkbGeometryType m_nGeometryType = wkbUnknown;
     202             :     int m_nAttributeIndex;
     203             :     bool m_bNullable;
     204             :     bool m_bSRSNameConsistent = true;
     205             :     std::string m_osSRSName{};
     206             :     OGRGeomCoordinatePrecision m_oCoordPrecision{};
     207             : 
     208             :   public:
     209             :     GMLGeometryPropertyDefn(const char *pszName, const char *pszSrcElement,
     210             :                             OGRwkbGeometryType nType, int nAttributeIndex,
     211             :                             bool bNullable,
     212             :                             const OGRGeomCoordinatePrecision &oCoordPrec =
     213             :                                 OGRGeomCoordinatePrecision());
     214             :     ~GMLGeometryPropertyDefn();
     215             : 
     216         828 :     const char *GetName() const
     217             :     {
     218         828 :         return m_pszName;
     219             :     }
     220             : 
     221        2029 :     OGRwkbGeometryType GetType() const
     222             :     {
     223        2029 :         return m_nGeometryType;
     224             :     }
     225             : 
     226         500 :     void SetType(OGRwkbGeometryType nType)
     227             :     {
     228         500 :         m_nGeometryType = nType;
     229         500 :     }
     230             : 
     231        3619 :     const char *GetSrcElement() const
     232             :     {
     233        3619 :         return m_pszSrcElement;
     234             :     }
     235             : 
     236         288 :     int GetAttributeIndex() const
     237             :     {
     238         288 :         return m_nAttributeIndex;
     239             :     }
     240             : 
     241         791 :     bool IsNullable() const
     242             :     {
     243         791 :         return m_bNullable;
     244             :     }
     245             : 
     246         573 :     const OGRGeomCoordinatePrecision &GetCoordinatePrecision() const
     247             :     {
     248         573 :         return m_oCoordPrecision;
     249             :     }
     250             : 
     251         509 :     void SetSRSName(const std::string &srsName)
     252             :     {
     253         509 :         m_bSRSNameConsistent = true;
     254         509 :         m_osSRSName = srsName;
     255         509 :     }
     256             : 
     257             :     void MergeSRSName(const std::string &osSRSName);
     258             : 
     259         573 :     const std::string &GetSRSName() const
     260             :     {
     261         573 :         return m_osSRSName;
     262             :     }
     263             : };
     264             : 
     265             : /************************************************************************/
     266             : /*                           GMLFeatureClass                            */
     267             : /************************************************************************/
     268             : class CPL_DLL GMLFeatureClass
     269             : {
     270             :     char *m_pszName;
     271             :     char *m_pszElementName;
     272             :     int n_nNameLen;
     273             :     int n_nElementNameLen;
     274             :     int m_nPropertyCount;
     275             :     GMLPropertyDefn **m_papoProperty;
     276             :     std::map<CPLString, int> m_oMapPropertyNameToIndex;
     277             :     std::map<CPLString, int> m_oMapPropertySrcElementToIndex;
     278             : 
     279             :     int m_nGeometryPropertyCount;
     280             :     GMLGeometryPropertyDefn **m_papoGeometryProperty;
     281             : 
     282             :     bool m_bSchemaLocked;
     283             : 
     284             :     GIntBig m_nFeatureCount;
     285             : 
     286             :     char *m_pszExtraInfo;
     287             : 
     288             :     bool m_bHaveExtents;
     289             :     double m_dfXMin;
     290             :     double m_dfXMax;
     291             :     double m_dfYMin;
     292             :     double m_dfYMax;
     293             : 
     294             :     char *m_pszSRSName;
     295             :     bool m_bSRSNameConsistent;
     296             : 
     297             :     bool m_bIsConsistentSingleGeomElemPath = true;
     298             :     std::string m_osSingleGeomElemPath{};
     299             : 
     300             :   public:
     301             :     explicit GMLFeatureClass(const char *pszName = "");
     302             :     ~GMLFeatureClass();
     303             : 
     304             :     const char *GetElementName() const;
     305             :     size_t GetElementNameLen() const;
     306             :     void SetElementName(const char *pszElementName);
     307             : 
     308        4230 :     const char *GetName() const
     309             :     {
     310        4230 :         return m_pszName;
     311             :     }
     312             : 
     313             :     void SetName(const char *pszNewName);
     314             : 
     315       13612 :     int GetPropertyCount() const
     316             :     {
     317       13612 :         return m_nPropertyCount;
     318             :     }
     319             : 
     320             :     GMLPropertyDefn *GetProperty(int iIndex) const;
     321             :     int GetPropertyIndex(const char *pszName) const;
     322             : 
     323        3020 :     GMLPropertyDefn *GetProperty(const char *pszName) const
     324             :     {
     325        3020 :         return GetProperty(GetPropertyIndex(pszName));
     326             :     }
     327             : 
     328             :     int GetPropertyIndexBySrcElement(const char *pszElement, int nLen) const;
     329             :     void StealProperties();
     330             : 
     331       10405 :     int GetGeometryPropertyCount() const
     332             :     {
     333       10405 :         return m_nGeometryPropertyCount;
     334             :     }
     335             : 
     336             :     GMLGeometryPropertyDefn *GetGeometryProperty(int iIndex) const;
     337             :     int GetGeometryPropertyIndexBySrcElement(const char *pszElement) const;
     338             :     void StealGeometryProperties();
     339             : 
     340             :     bool HasFeatureProperties();
     341             : 
     342             :     int AddProperty(GMLPropertyDefn *, int iPos = -1);
     343             :     int AddGeometryProperty(GMLGeometryPropertyDefn *);
     344             :     void ClearGeometryProperties();
     345             : 
     346           4 :     void SetConsistentSingleGeomElemPath(bool b)
     347             :     {
     348           4 :         m_bIsConsistentSingleGeomElemPath = b;
     349           4 :     }
     350             : 
     351        1283 :     bool IsConsistentSingleGeomElemPath() const
     352             :     {
     353        1283 :         return m_bIsConsistentSingleGeomElemPath;
     354             :     }
     355             : 
     356         249 :     void SetSingleGeomElemPath(const std::string &s)
     357             :     {
     358         249 :         m_osSingleGeomElemPath = s;
     359         249 :     }
     360             : 
     361        1340 :     const std::string &GetSingleGeomElemPath() const
     362             :     {
     363        1340 :         return m_osSingleGeomElemPath;
     364             :     }
     365             : 
     366       45260 :     bool IsSchemaLocked() const
     367             :     {
     368       45260 :         return m_bSchemaLocked;
     369             :     }
     370             : 
     371         695 :     void SetSchemaLocked(bool bLock)
     372             :     {
     373         695 :         m_bSchemaLocked = bLock;
     374         695 :     }
     375             : 
     376             :     const char *GetExtraInfo();
     377             :     void SetExtraInfo(const char *);
     378             : 
     379             :     GIntBig GetFeatureCount();
     380             :     void SetFeatureCount(GIntBig);
     381             : 
     382         426 :     bool HasExtents() const
     383             :     {
     384         426 :         return m_bHaveExtents;
     385             :     }
     386             : 
     387             :     void SetExtents(double dfXMin, double dfXMax, double dFYMin, double dfYMax);
     388             :     bool GetExtents(double *pdfXMin, double *pdfXMax, double *pdFYMin,
     389             :                     double *pdfYMax);
     390             : 
     391             :     void SetSRSName(const char *pszSRSName);
     392             :     void MergeSRSName(const char *pszSRSName);
     393             : 
     394         622 :     const char *GetSRSName()
     395             :     {
     396         622 :         return m_pszSRSName;
     397             :     }
     398             : 
     399             :     CPLXMLNode *SerializeToXML();
     400             :     bool InitializeFromXML(CPLXMLNode *);
     401             : };
     402             : 
     403             : /************************************************************************/
     404             : /*                              GMLFeature                              */
     405             : /************************************************************************/
     406             : 
     407             : class CPL_DLL GMLFeature
     408             : {
     409             :     GMLFeatureClass *m_poClass;
     410             :     char *m_pszFID;
     411             : 
     412             :     int m_nPropertyCount;
     413             :     GMLProperty *m_pasProperties;
     414             : 
     415             :     int m_nGeometryCount;
     416             :     CPLXMLNode **m_papsGeometry;  /* NULL-terminated. Alias to m_apsGeometry if
     417             :                                      m_nGeometryCount <= 1 */
     418             :     CPLXMLNode *m_apsGeometry[2]; /* NULL-terminated */
     419             : 
     420             :     CPLXMLNode *m_psBoundedByGeometry = nullptr;
     421             : 
     422             :   public:
     423             :     explicit GMLFeature(GMLFeatureClass *);
     424             :     ~GMLFeature();
     425             : 
     426       46528 :     GMLFeatureClass *GetClass() const
     427             :     {
     428       46528 :         return m_poClass;
     429             :     }
     430             : 
     431             :     void SetGeometryDirectly(CPLXMLNode *psGeom);
     432             :     void SetGeometryDirectly(int nIdx, CPLXMLNode *psGeom);
     433             :     void AddGeometry(CPLXMLNode *psGeom);
     434             : 
     435         503 :     int GetGeometryCount() const
     436             :     {
     437         503 :         return m_nGeometryCount;
     438             :     }
     439             : 
     440        1333 :     const CPLXMLNode *const *GetGeometryList() const
     441             :     {
     442        1333 :         return m_papsGeometry;
     443             :     }
     444             : 
     445             :     const CPLXMLNode *GetGeometryRef(int nIdx) const;
     446             : 
     447             :     void SetBoundedByGeometry(CPLXMLNode *psGeom);
     448             : 
     449        1181 :     const CPLXMLNode *GetBoundedByGeometry() const
     450             :     {
     451        1181 :         return m_psBoundedByGeometry;
     452             :     }
     453             : 
     454             :     void SetPropertyDirectly(int i, char *pszValue);
     455             : 
     456        6522 :     const GMLProperty *GetProperty(int i) const
     457             :     {
     458        6522 :         return (i >= 0 && i < m_nPropertyCount) ? &m_pasProperties[i] : nullptr;
     459             :     }
     460             : 
     461         689 :     const char *GetFID() const
     462             :     {
     463         689 :         return m_pszFID;
     464             :     }
     465             : 
     466             :     void SetFID(const char *pszFID);
     467             : 
     468             :     void Dump(FILE *fp);
     469             : };
     470             : 
     471             : /************************************************************************/
     472             : /*                              IGMLReader                              */
     473             : /************************************************************************/
     474             : class CPL_DLL IGMLReader
     475             : {
     476             :   public:
     477             :     virtual ~IGMLReader();
     478             : 
     479             :     virtual bool IsClassListLocked() const = 0;
     480             :     virtual void SetClassListLocked(bool bFlag) = 0;
     481             : 
     482             :     virtual void SetSourceFile(const char *pszFilename) = 0;
     483             : 
     484           0 :     virtual void SetFP(CPL_UNUSED VSILFILE *fp)
     485             :     {
     486           0 :     }
     487             : 
     488             :     virtual const char *GetSourceFileName() = 0;
     489             : 
     490             :     virtual int GetClassCount() const = 0;
     491             :     virtual GMLFeatureClass *GetClass(int i) const = 0;
     492             :     virtual GMLFeatureClass *GetClass(const char *pszName) const = 0;
     493             : 
     494             :     virtual int AddClass(GMLFeatureClass *poClass) = 0;
     495             :     virtual void ClearClasses() = 0;
     496             : 
     497             :     virtual GMLFeature *NextFeature() = 0;
     498             :     virtual void ResetReading() = 0;
     499             : 
     500             :     virtual bool LoadClasses(const char *pszFile = nullptr) = 0;
     501             :     virtual bool SaveClasses(const char *pszFile = nullptr) = 0;
     502             : 
     503             :     virtual bool ResolveXlinks(const char *pszFile, bool *pbOutIsTempFile,
     504             :                                char **papszSkip = nullptr,
     505             :                                const bool bStrict = false) = 0;
     506             : 
     507             :     virtual bool HugeFileResolver(const char *pszFile, bool bSqliteIsTempFile,
     508             :                                   int iSqliteCacheMB) = 0;
     509             : 
     510             :     virtual bool PrescanForSchema(bool bGetExtents = true,
     511             :                                   bool bOnlyDetectSRS = false) = 0;
     512             :     virtual bool PrescanForTemplate() = 0;
     513             : 
     514             :     virtual bool HasStoppedParsing() = 0;
     515             : 
     516           0 :     virtual void SetGlobalSRSName(CPL_UNUSED const char *pszGlobalSRSName)
     517             :     {
     518           0 :     }
     519             : 
     520             :     virtual const char *GetGlobalSRSName() = 0;
     521             :     virtual bool CanUseGlobalSRSName() = 0;
     522             : 
     523             :     virtual bool SetFilteredClassName(const char *pszClassName) = 0;
     524             :     virtual const char *GetFilteredClassName() = 0;
     525             : 
     526           0 :     virtual bool IsSequentialLayers() const
     527             :     {
     528           0 :         return false;
     529             :     }
     530             : };
     531             : 
     532             : IGMLReader *CreateGMLReader(bool bUseExpatParserPreferably,
     533             :                             bool bInvertAxisOrderIfLatLong,
     534             :                             bool bConsiderEPSGAsURN,
     535             :                             GMLSwapCoordinatesEnum eSwapCoordinates,
     536             :                             bool bGetSecondaryGeometryOption);
     537             : 
     538             : OGRFieldType CPL_DLL GML_GetOGRFieldType(GMLPropertyType eType,
     539             :                                          OGRFieldSubType &eSubType);
     540             : 
     541             : #endif /* GMLREADER_H_INCLUDED */

Generated by: LCOV version 1.14