From f0a3c950e03a541794c24de7ce8c01d2fb3a1aff Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Wed, 2 Oct 2024 02:16:28 +0200 Subject: [PATCH 1/3] ogr_PDS: remove non-existent dependency to GML --- ogr/ogrsf_frmts/CMakeLists.txt | 2 +- ogr/ogrsf_frmts/pds/CMakeLists.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ogr/ogrsf_frmts/CMakeLists.txt b/ogr/ogrsf_frmts/CMakeLists.txt index 85998924dbc3..48489c67c3ab 100644 --- a/ogr/ogrsf_frmts/CMakeLists.txt +++ b/ogr/ogrsf_frmts/CMakeLists.txt @@ -99,7 +99,7 @@ ogr_dependent_driver(xodr OpenDRIVE "GDAL_USE_OPENDRIVE;GDAL_USE_GEOS") ogr_dependent_driver(idrisi IDRISI "GDAL_ENABLE_DRIVER_IDRISI") -ogr_dependent_driver(pds "Planetary Data Systems TABLE" "GDAL_ENABLE_DRIVER_PDS;OGR_ENABLE_DRIVER_GML") +ogr_dependent_driver(pds "Planetary Data Systems TABLE" "GDAL_ENABLE_DRIVER_PDS") # Caution: if modifying SQLite declaration here, also modify it in gdal.cmake ogr_dependent_driver(sqlite "SQLite3 / Spatialite RDBMS" "GDAL_USE_SQLITE3") diff --git a/ogr/ogrsf_frmts/pds/CMakeLists.txt b/ogr/ogrsf_frmts/pds/CMakeLists.txt index 43304464760b..e28ed30bc586 100644 --- a/ogr/ogrsf_frmts/pds/CMakeLists.txt +++ b/ogr/ogrsf_frmts/pds/CMakeLists.txt @@ -3,7 +3,7 @@ add_gdal_driver( SOURCES ogrpdsdatasource.cpp ogr_pds.h ogrpdsdriver.cpp ogrpdslayer.cpp BUILTIN) gdal_standard_includes(ogr_PDS) -target_include_directories(ogr_PDS PRIVATE $ $) +target_include_directories(ogr_PDS PRIVATE $) if (GDAL_USE_JSONC_INTERNAL) gdal_add_vendored_lib(ogr_PDS libjson) else () From 5984846bb2cca19ec424f562c3e085d1a4ea2216 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Tue, 1 Oct 2024 23:28:13 +0200 Subject: [PATCH 2/3] Build: enable -DOGR_ENABLE_DRIVER_GML_PLUGIN=ON, provided that -DOGR_ENABLE_DRIVER_NAS=OFF; make CSW and WFS drivers plugin capable too --- autotest/gdrivers/ogcapi.py | 1 + frmts/ogcapi/CMakeLists.txt | 8 +- frmts/ogcapi/gdalogcapidataset.cpp | 8 - frmts/wcs/CMakeLists.txt | 2 +- ogr/ogr_p.h | 10 +- ogr/ogrsf_frmts/CMakeLists.txt | 21 +- ogr/ogrsf_frmts/csw/CMakeLists.txt | 5 +- ogr/ogrsf_frmts/csw/ogrcswdataset.cpp | 3 +- ogr/ogrsf_frmts/gml/CMakeLists.txt | 12 +- ogr/ogrsf_frmts/gml/gmlreader.h | 438 +---------------- ogr/ogrsf_frmts/gmlutils/CMakeLists.txt | 16 + .../{gml => gmlutils}/gmlfeature.cpp | 2 +- ogr/ogrsf_frmts/gmlutils/gmlfeature.h | 464 ++++++++++++++++++ .../{gml => gmlutils}/gmlfeatureclass.cpp | 2 +- .../{gml => gmlutils}/gmlpropertydefn.cpp | 2 +- .../{gml => gmlutils}/gmlutils.cpp | 0 ogr/ogrsf_frmts/{gml => gmlutils}/gmlutils.h | 17 +- .../{wfs => gmlutils}/ogrwfsfilter.cpp | 23 +- ogr/ogrsf_frmts/gmlutils/ogrwfsfilter.h | 29 ++ .../{gml => gmlutils}/parsexsd.cpp | 0 ogr/ogrsf_frmts/{gml => gmlutils}/parsexsd.h | 2 +- ogr/ogrsf_frmts/nas/CMakeLists.txt | 2 +- ogr/ogrsf_frmts/wfs/CMakeLists.txt | 9 +- ogr/ogrsf_frmts/wfs/ogr_wfs.h | 10 +- ogr/ogrsf_frmts/wfs/ogrwfsdatasource.cpp | 1 + ogr/ogrsf_frmts/wfs/ogrwfsdriver.cpp | 4 + ogr/ogrsf_frmts/wfs/ogrwfsjoinlayer.cpp | 1 + ogr/ogrsf_frmts/wfs/ogrwfslayer.cpp | 1 + 28 files changed, 583 insertions(+), 510 deletions(-) create mode 100644 ogr/ogrsf_frmts/gmlutils/CMakeLists.txt rename ogr/ogrsf_frmts/{gml => gmlutils}/gmlfeature.cpp (99%) create mode 100644 ogr/ogrsf_frmts/gmlutils/gmlfeature.h rename ogr/ogrsf_frmts/{gml => gmlutils}/gmlfeatureclass.cpp (99%) rename ogr/ogrsf_frmts/{gml => gmlutils}/gmlpropertydefn.cpp (99%) rename ogr/ogrsf_frmts/{gml => gmlutils}/gmlutils.cpp (100%) rename ogr/ogrsf_frmts/{gml => gmlutils}/gmlutils.h (82%) rename ogr/ogrsf_frmts/{wfs => gmlutils}/ogrwfsfilter.cpp (98%) create mode 100644 ogr/ogrsf_frmts/gmlutils/ogrwfsfilter.h rename ogr/ogrsf_frmts/{gml => gmlutils}/parsexsd.cpp (100%) rename ogr/ogrsf_frmts/{gml => gmlutils}/parsexsd.h (98%) diff --git a/autotest/gdrivers/ogcapi.py b/autotest/gdrivers/ogcapi.py index fdebf3a42427..dea41a3d5453 100644 --- a/autotest/gdrivers/ogcapi.py +++ b/autotest/gdrivers/ogcapi.py @@ -211,6 +211,7 @@ def init(): @pytest.mark.parametrize("remove_type_application_json", [False, True]) +@pytest.mark.require_driver("OAPIF") def test_ogr_ogcapi_features(remove_type_application_json): global global_remove_type_application_json diff --git a/frmts/ogcapi/CMakeLists.txt b/frmts/ogcapi/CMakeLists.txt index c6300dd3167c..864520f22614 100644 --- a/frmts/ogcapi/CMakeLists.txt +++ b/frmts/ogcapi/CMakeLists.txt @@ -1,9 +1,3 @@ add_gdal_driver(TARGET gdal_OGCAPI SOURCES gdalogcapidataset.cpp PLUGIN_CAPABLE NO_DEPS) gdal_standard_includes(gdal_OGCAPI) -if(NOT DEFINED OGR_ENABLE_DRIVER_GML) - message(FATAL_ERROR "OGR_ENABLE_DRIVER_GML is not defined") -endif() -if(OGR_ENABLE_DRIVER_GML) - target_include_directories(gdal_OGCAPI PRIVATE ${GDAL_VECTOR_FORMAT_SOURCE_DIR}/gml) - target_compile_definitions(gdal_OGCAPI PRIVATE -DOGR_ENABLE_DRIVER_GML) -endif() +target_include_directories(gdal_OGCAPI PRIVATE ${GDAL_VECTOR_FORMAT_SOURCE_DIR}/gmlutils) diff --git a/frmts/ogcapi/gdalogcapidataset.cpp b/frmts/ogcapi/gdalogcapidataset.cpp index 69750ab7526c..c6d926acc906 100644 --- a/frmts/ogcapi/gdalogcapidataset.cpp +++ b/frmts/ogcapi/gdalogcapidataset.cpp @@ -35,9 +35,7 @@ #include "ogrsf_frmts.h" #include "ogr_spatialref.h" -#ifdef OGR_ENABLE_DRIVER_GML #include "parsexsd.h" -#endif #include #include @@ -1649,7 +1647,6 @@ GDALColorInterp OGCAPIMapWrapperBand::GetColorInterpretation() /* ParseXMLSchema() */ /************************************************************************/ -#ifdef OGR_ENABLE_DRIVER_GML static bool ParseXMLSchema(const std::string &osURL, std::vector> &apoFields, @@ -1694,7 +1691,6 @@ ParseXMLSchema(const std::string &osURL, return false; } -#endif /************************************************************************/ /* InitWithTilesAPI() */ @@ -1966,14 +1962,12 @@ bool OGCAPIDataset::InitWithTilesAPI(GDALOpenInfo *poOpenInfo, } } -#ifdef OGR_ENABLE_DRIVER_GML std::vector> apoFields; bool bGotSchema = false; if (!osXMLSchemaURL.empty()) { bGotSchema = ParseXMLSchema(osXMLSchemaURL, apoFields, eGeomType); } -#endif for (const auto &tileMatrix : tms->tileMatrixList()) { @@ -2021,10 +2015,8 @@ bool OGCAPIDataset::InitWithTilesAPI(GDALOpenInfo *poOpenInfo, tileMatrix, eGeomType)); poLayer->SetMinMaxXY(minCol, minRow, maxCol, maxRow); poLayer->SetExtent(dfXMin, dfYMin, dfXMax, dfYMax); -#ifdef OGR_ENABLE_DRIVER_GML if (bGotSchema) poLayer->SetFields(apoFields); -#endif m_apoLayers.emplace_back(std::move(poLayer)); } diff --git a/frmts/wcs/CMakeLists.txt b/frmts/wcs/CMakeLists.txt index 15dcc77801c1..b1d0d3275d4e 100644 --- a/frmts/wcs/CMakeLists.txt +++ b/frmts/wcs/CMakeLists.txt @@ -20,4 +20,4 @@ if(NOT TARGET gdal_WCS) endif() gdal_standard_includes(gdal_WCS) -target_include_directories(gdal_WCS PRIVATE ${GDAL_VECTOR_FORMAT_SOURCE_DIR}/gml) +target_include_directories(gdal_WCS PRIVATE ${GDAL_VECTOR_FORMAT_SOURCE_DIR}/gmlutils) diff --git a/ogr/ogr_p.h b/ogr/ogr_p.h index f4ee626786d1..bf9e80b69d23 100644 --- a/ogr/ogr_p.h +++ b/ogr/ogr_p.h @@ -200,12 +200,10 @@ OGRErr CPL_DLL OGRCheckPermutation(const int *panPermutation, int nSize); /* GML related */ -OGRGeometry *GML2OGRGeometry_XMLNode(const CPLXMLNode *psNode, - int nPseudoBoolGetSecondaryGeometryOption, - int nRecLevel = 0, int nSRSDimension = 0, - bool bIgnoreGSG = false, - bool bOrientation = true, - bool bFaceHoleNegative = false); +OGRGeometry CPL_DLL *GML2OGRGeometry_XMLNode( + const CPLXMLNode *psNode, int nPseudoBoolGetSecondaryGeometryOption, + int nRecLevel = 0, int nSRSDimension = 0, bool bIgnoreGSG = false, + bool bOrientation = true, bool bFaceHoleNegative = false); /************************************************************************/ /* PostGIS EWKB encoding */ diff --git a/ogr/ogrsf_frmts/CMakeLists.txt b/ogr/ogrsf_frmts/CMakeLists.txt index 48489c67c3ab..7bebf98ca12f 100644 --- a/ogr/ogrsf_frmts/CMakeLists.txt +++ b/ogr/ogrsf_frmts/CMakeLists.txt @@ -45,7 +45,22 @@ ogr_optional_driver(vrt "VRT - Virtual Format") # Caution: if modifying AVC declaration here, also modify it in gdal.cmake ogr_optional_driver(avc AVC) -ogr_optional_driver(gml GML) # when not found both EXPAT/XercesC, return error in driver, referenced by WCS +if (NOT(DEFINED OGR_ENABLE_DRIVER_GML AND NOT OGR_ENABLE_DRIVER_GML AND + ((NOT GDAL_USE_CURL) OR + (DEFINED OGR_ENABLE_DRIVER_WFS AND NOT OGR_ENABLE_DRIVER_WFS AND + DEFINED OGR_ENABLE_DRIVER_CSW AND NOT OGR_ENABLE_DRIVER_CSW)))) + # Only build gmlutils if we have GML, WFS or CSW + add_subdirectory(gmlutils) +endif() + +if (GDAL_ENABLE_PLUGINS_NO_DEPS AND NOT DEFINED OGR_ENABLE_DRIVER_GML_PLUGIN) + option(OGR_ENABLE_DRIVER_GML_PLUGIN "Set ON to build GML driver as a plugin" OFF) +endif () +ogr_optional_driver(gml GML) +if (OGR_ENABLE_DRIVER_GML_PLUGIN AND + ((NOT DEFINED OGR_ENABLE_DRIVER_NAS OR OGR_ENABLE_DRIVER_NAS))) + message(FATAL_ERROR "When building the GML driver as a plugin, the NAS driver must be explicitly disabled with OGR_ENABLE_DRIVER_NAS=OFF") +endif() # ###################################################################################################################### ogr_optional_driver(csv CSV) @@ -85,14 +100,14 @@ ogr_dependent_driver(sdts SDTS "GDAL_ENABLE_DRIVER_SDTS") ogr_dependent_driver(gpx "GPX - GPS Exchange Format" "GDAL_USE_EXPAT") ogr_dependent_driver(gmlas GMLAS "GDAL_USE_XERCESC;OGR_ENABLE_DRIVER_PGDUMP") ogr_dependent_driver(svg "Scalable Vector Graphics" "GDAL_USE_EXPAT") -ogr_dependent_driver(csw CSW "GDAL_USE_CURL;OGR_ENABLE_DRIVER_GML") +ogr_dependent_driver(csw CSW "GDAL_USE_CURL") ogr_dependent_driver(dwg DWG "GDAL_USE_TEIGHA") ogr_dependent_driver(filegdb FileGDB "GDAL_USE_FILEGDB") ogr_dependent_driver(libkml LibKML "GDAL_USE_LIBKML") ogr_dependent_driver(nas "NAS/ALKIS" "GDAL_USE_XERCESC;OGR_ENABLE_DRIVER_GML") ogr_dependent_driver(plscenes PLSCENES "GDAL_USE_CURL") ogr_dependent_driver(sosi "SOSI:Systematic Organization of Spatial Information" "GDAL_USE_FYBA") -ogr_dependent_driver(wfs "OGC WFS service" "GDAL_USE_CURL;OGR_ENABLE_DRIVER_GML") +ogr_dependent_driver(wfs "OGC WFS service" "GDAL_USE_CURL") ogr_dependent_driver(ngw "NextGIS Web" "GDAL_USE_CURL") ogr_dependent_driver(elastic "ElasticSearch" "GDAL_USE_CURL") ogr_dependent_driver(xodr OpenDRIVE "GDAL_USE_OPENDRIVE;GDAL_USE_GEOS") diff --git a/ogr/ogrsf_frmts/csw/CMakeLists.txt b/ogr/ogrsf_frmts/csw/CMakeLists.txt index a1d8fc1eae6d..b3eb54f8eafa 100644 --- a/ogr/ogrsf_frmts/csw/CMakeLists.txt +++ b/ogr/ogrsf_frmts/csw/CMakeLists.txt @@ -1,6 +1,7 @@ add_gdal_driver( TARGET ogr_CSW SOURCES ogrcswdataset.cpp - BUILTIN) # BUILTIN because of GML and WFS dependency + PLUGIN_CAPABLE + NO_DEPS) gdal_standard_includes(ogr_CSW) -target_include_directories(ogr_CSW PRIVATE $ $) +target_include_directories(ogr_CSW PRIVATE $) diff --git a/ogr/ogrsf_frmts/csw/ogrcswdataset.cpp b/ogr/ogrsf_frmts/csw/ogrcswdataset.cpp index 46774b197c3d..d06fe563d500 100644 --- a/ogr/ogrsf_frmts/csw/ogrcswdataset.cpp +++ b/ogr/ogrsf_frmts/csw/ogrcswdataset.cpp @@ -29,8 +29,9 @@ #include "ogrsf_frmts.h" #include "cpl_conv.h" #include "cpl_http.h" -#include "ogr_wfs.h" #include "ogr_p.h" +#include "ogr_swq.h" +#include "ogrwfsfilter.h" #include "gmlutils.h" extern "C" void RegisterOGRCSW(); diff --git a/ogr/ogrsf_frmts/gml/CMakeLists.txt b/ogr/ogrsf_frmts/gml/CMakeLists.txt index 99d074bc3a51..845a797dcaec 100644 --- a/ogr/ogrsf_frmts/gml/CMakeLists.txt +++ b/ogr/ogrsf_frmts/gml/CMakeLists.txt @@ -1,32 +1,28 @@ add_gdal_driver( TARGET ogr_GML SOURCES gfstemplate.cpp - gmlpropertydefn.cpp gmlreadstate.cpp - gmlutils.h ogrgmldriver.cpp resolvexlinks.cpp - gmlfeature.cpp gmlreader.cpp gmlregistry.cpp hugefileresolver.cpp ogrgmllayer.cpp xercesc_headers.h - gmlfeatureclass.cpp gmlreader.h gmlregistry.h ogr_gml.h - parsexsd.cpp gmlhandler.cpp gmlreaderp.h - gmlutils.cpp ogrgmldatasource.cpp - parsexsd.h - BUILTIN + PLUGIN_CAPABLE + NO_DEPS STRONG_CXX_WFLAGS ) gdal_standard_includes(ogr_GML) +target_include_directories(ogr_GML PRIVATE $) + set(GDAL_DATA_FILES ${CMAKE_CURRENT_SOURCE_DIR}/data/gfs.xsd ${CMAKE_CURRENT_SOURCE_DIR}/data/gml_registry.xml diff --git a/ogr/ogrsf_frmts/gml/gmlreader.h b/ogr/ogrsf_frmts/gml/gmlreader.h index 8e32836cce47..4ea9ad1d089b 100644 --- a/ogr/ogrsf_frmts/gml/gmlreader.h +++ b/ogr/ogrsf_frmts/gml/gmlreader.h @@ -36,6 +36,7 @@ #include "cpl_minixml.h" #include "ogr_core.h" #include "gmlutils.h" +#include "gmlfeature.h" #include #include @@ -43,440 +44,6 @@ // Special value to map to a NULL field #define OGR_GML_NULL "___OGR_GML_NULL___" -typedef enum -{ - GMLPT_Untyped = 0, - GMLPT_String = 1, - GMLPT_Integer = 2, - GMLPT_Real = 3, - GMLPT_Complex = 4, - GMLPT_StringList = 5, - GMLPT_IntegerList = 6, - GMLPT_RealList = 7, - GMLPT_FeatureProperty = 8, - GMLPT_FeaturePropertyList = 9, - GMLPT_Boolean = 10, - GMLPT_BooleanList = 11, - GMLPT_Short = 12, - GMLPT_Float = 13, - GMLPT_Integer64 = 14, - GMLPT_Integer64List = 15, - GMLPT_DateTime = 16, - GMLPT_Date = 17, - GMLPT_Time = 18, -} GMLPropertyType; - -/************************************************************************/ -/* GMLPropertyDefn */ -/************************************************************************/ - -typedef struct -{ - int nSubProperties; - char **papszSubProperties; - char *aszSubProperties[2]; /* Optimization in the case of nSubProperties == - 1 */ -} GMLProperty; - -class CPL_DLL GMLPropertyDefn -{ - char *m_pszName = nullptr; - GMLPropertyType m_eType = GMLPT_Untyped; - int m_nWidth = 0; - int m_nPrecision = 0; - char *m_pszSrcElement = nullptr; - size_t m_nSrcElementLen = 0; - char *m_pszCondition = nullptr; - bool m_bNullable = true; - bool m_bUnique = false; - std::string m_osDocumentation{}; - - CPL_DISALLOW_COPY_ASSIGN(GMLPropertyDefn) - - public: - explicit GMLPropertyDefn(const char *pszName, - const char *pszSrcElement = nullptr); - ~GMLPropertyDefn(); - - const char *GetName() const - { - return m_pszName; - } - - GMLPropertyType GetType() const - { - return m_eType; - } - - void SetType(GMLPropertyType eType) - { - m_eType = eType; - } - - void SetWidth(int nWidth) - { - m_nWidth = nWidth; - } - - int GetWidth() const - { - return m_nWidth; - } - - void SetPrecision(int nPrecision) - { - m_nPrecision = nPrecision; - } - - int GetPrecision() const - { - return m_nPrecision; - } - - void SetSrcElement(const char *pszSrcElement); - - const char *GetSrcElement() const - { - return m_pszSrcElement; - } - - size_t GetSrcElementLen() const - { - return m_nSrcElementLen; - } - - void SetCondition(const char *pszCondition); - - const char *GetCondition() const - { - return m_pszCondition; - } - - void SetNullable(bool bNullable) - { - m_bNullable = bNullable; - } - - bool IsNullable() const - { - return m_bNullable; - } - - void SetUnique(bool bUnique) - { - m_bUnique = bUnique; - } - - bool IsUnique() const - { - return m_bUnique; - } - - void SetDocumentation(const std::string &osDocumentation) - { - m_osDocumentation = osDocumentation; - } - - const std::string &GetDocumentation() const - { - return m_osDocumentation; - } - - void AnalysePropertyValue(const GMLProperty *psGMLProperty, - bool bSetWidth = true); - - static bool IsSimpleType(GMLPropertyType eType) - { - return eType == GMLPT_String || eType == GMLPT_Integer || - eType == GMLPT_Real; - } -}; - -/************************************************************************/ -/* GMLGeometryPropertyDefn */ -/************************************************************************/ - -class CPL_DLL GMLGeometryPropertyDefn -{ - char *m_pszName = nullptr; - char *m_pszSrcElement = nullptr; - OGRwkbGeometryType m_nGeometryType = wkbUnknown; - const int m_nAttributeIndex = -1; - const bool m_bNullable = true; - bool m_bSRSNameConsistent = true; - std::string m_osSRSName{}; - OGRGeomCoordinatePrecision m_oCoordPrecision{}; - - CPL_DISALLOW_COPY_ASSIGN(GMLGeometryPropertyDefn) - - public: - GMLGeometryPropertyDefn(const char *pszName, const char *pszSrcElement, - OGRwkbGeometryType nType, int nAttributeIndex, - bool bNullable, - const OGRGeomCoordinatePrecision &oCoordPrec = - OGRGeomCoordinatePrecision()); - ~GMLGeometryPropertyDefn(); - - const char *GetName() const - { - return m_pszName; - } - - OGRwkbGeometryType GetType() const - { - return m_nGeometryType; - } - - void SetType(OGRwkbGeometryType nType) - { - m_nGeometryType = nType; - } - - const char *GetSrcElement() const - { - return m_pszSrcElement; - } - - int GetAttributeIndex() const - { - return m_nAttributeIndex; - } - - bool IsNullable() const - { - return m_bNullable; - } - - const OGRGeomCoordinatePrecision &GetCoordinatePrecision() const - { - return m_oCoordPrecision; - } - - void SetSRSName(const std::string &srsName) - { - m_bSRSNameConsistent = true; - m_osSRSName = srsName; - } - - void MergeSRSName(const std::string &osSRSName); - - const std::string &GetSRSName() const - { - return m_osSRSName; - } -}; - -/************************************************************************/ -/* GMLFeatureClass */ -/************************************************************************/ - -class CPL_DLL GMLFeatureClass -{ - char *m_pszName; - char *m_pszElementName; - int n_nNameLen; - int n_nElementNameLen; - int m_nPropertyCount; - GMLPropertyDefn **m_papoProperty; - std::map m_oMapPropertyNameToIndex{}; - std::map m_oMapPropertySrcElementToIndex{}; - - int m_nGeometryPropertyCount; - GMLGeometryPropertyDefn **m_papoGeometryProperty; - - bool m_bSchemaLocked; - - GIntBig m_nFeatureCount; - - char *m_pszExtraInfo; - - bool m_bHaveExtents; - double m_dfXMin; - double m_dfXMax; - double m_dfYMin; - double m_dfYMax; - - char *m_pszSRSName; - bool m_bSRSNameConsistent; - - bool m_bIsConsistentSingleGeomElemPath = true; - std::string m_osSingleGeomElemPath{}; - - CPL_DISALLOW_COPY_ASSIGN(GMLFeatureClass) - - public: - explicit GMLFeatureClass(const char *pszName = ""); - ~GMLFeatureClass(); - - const char *GetElementName() const; - size_t GetElementNameLen() const; - void SetElementName(const char *pszElementName); - - const char *GetName() const - { - return m_pszName; - } - - void SetName(const char *pszNewName); - - int GetPropertyCount() const - { - return m_nPropertyCount; - } - - GMLPropertyDefn *GetProperty(int iIndex) const; - int GetPropertyIndex(const char *pszName) const; - - GMLPropertyDefn *GetProperty(const char *pszName) const - { - return GetProperty(GetPropertyIndex(pszName)); - } - - int GetPropertyIndexBySrcElement(const char *pszElement, int nLen) const; - void StealProperties(); - - int GetGeometryPropertyCount() const - { - return m_nGeometryPropertyCount; - } - - GMLGeometryPropertyDefn *GetGeometryProperty(int iIndex) const; - int GetGeometryPropertyIndexBySrcElement(const char *pszElement) const; - void StealGeometryProperties(); - - bool HasFeatureProperties(); - - int AddProperty(GMLPropertyDefn *, int iPos = -1); - int AddGeometryProperty(GMLGeometryPropertyDefn *); - void ClearGeometryProperties(); - - void SetConsistentSingleGeomElemPath(bool b) - { - m_bIsConsistentSingleGeomElemPath = b; - } - - bool IsConsistentSingleGeomElemPath() const - { - return m_bIsConsistentSingleGeomElemPath; - } - - void SetSingleGeomElemPath(const std::string &s) - { - m_osSingleGeomElemPath = s; - } - - const std::string &GetSingleGeomElemPath() const - { - return m_osSingleGeomElemPath; - } - - bool IsSchemaLocked() const - { - return m_bSchemaLocked; - } - - void SetSchemaLocked(bool bLock) - { - m_bSchemaLocked = bLock; - } - - const char *GetExtraInfo(); - void SetExtraInfo(const char *); - - GIntBig GetFeatureCount(); - void SetFeatureCount(GIntBig); - - bool HasExtents() const - { - return m_bHaveExtents; - } - - void SetExtents(double dfXMin, double dfXMax, double dFYMin, double dfYMax); - bool GetExtents(double *pdfXMin, double *pdfXMax, double *pdFYMin, - double *pdfYMax); - - void SetSRSName(const char *pszSRSName); - void MergeSRSName(const char *pszSRSName); - - const char *GetSRSName() - { - return m_pszSRSName; - } - - CPLXMLNode *SerializeToXML(); - bool InitializeFromXML(CPLXMLNode *); -}; - -/************************************************************************/ -/* GMLFeature */ -/************************************************************************/ - -class CPL_DLL GMLFeature -{ - GMLFeatureClass *m_poClass; - char *m_pszFID; - - int m_nPropertyCount; - GMLProperty *m_pasProperties; - - int m_nGeometryCount; - CPLXMLNode **m_papsGeometry; /* NULL-terminated. Alias to m_apsGeometry if - m_nGeometryCount <= 1 */ - CPLXMLNode *m_apsGeometry[2]; /* NULL-terminated */ - - CPLXMLNode *m_psBoundedByGeometry = nullptr; - - CPL_DISALLOW_COPY_ASSIGN(GMLFeature) - - public: - explicit GMLFeature(GMLFeatureClass *); - ~GMLFeature(); - - GMLFeatureClass *GetClass() const - { - return m_poClass; - } - - void SetGeometryDirectly(CPLXMLNode *psGeom); - void SetGeometryDirectly(int nIdx, CPLXMLNode *psGeom); - void AddGeometry(CPLXMLNode *psGeom); - - int GetGeometryCount() const - { - return m_nGeometryCount; - } - - const CPLXMLNode *const *GetGeometryList() const - { - return m_papsGeometry; - } - - const CPLXMLNode *GetGeometryRef(int nIdx) const; - - void SetBoundedByGeometry(CPLXMLNode *psGeom); - - const CPLXMLNode *GetBoundedByGeometry() const - { - return m_psBoundedByGeometry; - } - - void SetPropertyDirectly(int i, char *pszValue); - - const GMLProperty *GetProperty(int i) const - { - return (i >= 0 && i < m_nPropertyCount) ? &m_pasProperties[i] : nullptr; - } - - const char *GetFID() const - { - return m_pszFID; - } - - void SetFID(const char *pszFID); - - void Dump(FILE *fp); -}; - /************************************************************************/ /* IGMLReader */ /************************************************************************/ @@ -544,7 +111,4 @@ IGMLReader *CreateGMLReader(bool bUseExpatParserPreferably, GMLSwapCoordinatesEnum eSwapCoordinates, bool bGetSecondaryGeometryOption); -OGRFieldType CPL_DLL GML_GetOGRFieldType(GMLPropertyType eType, - OGRFieldSubType &eSubType); - #endif /* GMLREADER_H_INCLUDED */ diff --git a/ogr/ogrsf_frmts/gmlutils/CMakeLists.txt b/ogr/ogrsf_frmts/gmlutils/CMakeLists.txt new file mode 100644 index 000000000000..5f87e38e6fa0 --- /dev/null +++ b/ogr/ogrsf_frmts/gmlutils/CMakeLists.txt @@ -0,0 +1,16 @@ +add_library( + gmlutils OBJECT + gmlfeature.cpp + gmlfeatureclass.cpp + gmlpropertydefn.cpp + gmlutils.cpp + parsexsd.h + parsexsd.cpp + ogrwfsfilter.cpp +) +gdal_standard_includes(gmlutils) +add_dependencies(gmlutils generate_gdal_version_h) +set_property(TARGET gmlutils PROPERTY POSITION_INDEPENDENT_CODE ${GDAL_OBJECT_LIBRARIES_POSITION_INDEPENDENT_CODE}) +target_sources(${GDAL_LIB_TARGET_NAME} PRIVATE $) +target_compile_options(gmlutils PRIVATE ${GDAL_CXX_WARNING_FLAGS} ${WFLAG_OLD_STYLE_CAST} ${WFLAG_EFFCXX}) + diff --git a/ogr/ogrsf_frmts/gml/gmlfeature.cpp b/ogr/ogrsf_frmts/gmlutils/gmlfeature.cpp similarity index 99% rename from ogr/ogrsf_frmts/gml/gmlfeature.cpp rename to ogr/ogrsf_frmts/gmlutils/gmlfeature.cpp index cc12248a6bdb..8eabff33ae69 100644 --- a/ogr/ogrsf_frmts/gml/gmlfeature.cpp +++ b/ogr/ogrsf_frmts/gmlutils/gmlfeature.cpp @@ -28,7 +28,7 @@ ****************************************************************************/ #include "cpl_port.h" -#include "gmlreader.h" +#include "gmlfeature.h" #include diff --git a/ogr/ogrsf_frmts/gmlutils/gmlfeature.h b/ogr/ogrsf_frmts/gmlutils/gmlfeature.h new file mode 100644 index 000000000000..ffa990be5576 --- /dev/null +++ b/ogr/ogrsf_frmts/gmlutils/gmlfeature.h @@ -0,0 +1,464 @@ +/****************************************************************************** + * $Id$ + * + * Project: GML Reader + * Purpose: Public Declarations for OGR free GML Reader code. + * Author: Frank Warmerdam, warmerdam@pobox.com + * + ****************************************************************************** + * Copyright (c) 2002, Frank Warmerdam + * Copyright (c) 2008-2013, Even Rouault + * + * SPDX-License-Identifier: MIT + ****************************************************************************/ + +#ifndef GMLFEATURE_H_INCLUDED +#define GMLFEATURE_H_INCLUDED + +#include "cpl_port.h" +#include "cpl_vsi.h" +#include "cpl_minixml.h" +#include "ogr_core.h" +#include "ogr_geomcoordinateprecision.h" + +#include +#include + +typedef enum +{ + GMLPT_Untyped = 0, + GMLPT_String = 1, + GMLPT_Integer = 2, + GMLPT_Real = 3, + GMLPT_Complex = 4, + GMLPT_StringList = 5, + GMLPT_IntegerList = 6, + GMLPT_RealList = 7, + GMLPT_FeatureProperty = 8, + GMLPT_FeaturePropertyList = 9, + GMLPT_Boolean = 10, + GMLPT_BooleanList = 11, + GMLPT_Short = 12, + GMLPT_Float = 13, + GMLPT_Integer64 = 14, + GMLPT_Integer64List = 15, + GMLPT_DateTime = 16, + GMLPT_Date = 17, + GMLPT_Time = 18, +} GMLPropertyType; + +/************************************************************************/ +/* GMLPropertyDefn */ +/************************************************************************/ + +typedef struct +{ + int nSubProperties; + char **papszSubProperties; + char *aszSubProperties[2]; /* Optimization in the case of nSubProperties == + 1 */ +} GMLProperty; + +class CPL_DLL GMLPropertyDefn +{ + char *m_pszName = nullptr; + GMLPropertyType m_eType = GMLPT_Untyped; + int m_nWidth = 0; + int m_nPrecision = 0; + char *m_pszSrcElement = nullptr; + size_t m_nSrcElementLen = 0; + char *m_pszCondition = nullptr; + bool m_bNullable = true; + bool m_bUnique = false; + std::string m_osDocumentation{}; + + CPL_DISALLOW_COPY_ASSIGN(GMLPropertyDefn) + + public: + explicit GMLPropertyDefn(const char *pszName, + const char *pszSrcElement = nullptr); + ~GMLPropertyDefn(); + + const char *GetName() const + { + return m_pszName; + } + + GMLPropertyType GetType() const + { + return m_eType; + } + + void SetType(GMLPropertyType eType) + { + m_eType = eType; + } + + void SetWidth(int nWidth) + { + m_nWidth = nWidth; + } + + int GetWidth() const + { + return m_nWidth; + } + + void SetPrecision(int nPrecision) + { + m_nPrecision = nPrecision; + } + + int GetPrecision() const + { + return m_nPrecision; + } + + void SetSrcElement(const char *pszSrcElement); + + const char *GetSrcElement() const + { + return m_pszSrcElement; + } + + size_t GetSrcElementLen() const + { + return m_nSrcElementLen; + } + + void SetCondition(const char *pszCondition); + + const char *GetCondition() const + { + return m_pszCondition; + } + + void SetNullable(bool bNullable) + { + m_bNullable = bNullable; + } + + bool IsNullable() const + { + return m_bNullable; + } + + void SetUnique(bool bUnique) + { + m_bUnique = bUnique; + } + + bool IsUnique() const + { + return m_bUnique; + } + + void SetDocumentation(const std::string &osDocumentation) + { + m_osDocumentation = osDocumentation; + } + + const std::string &GetDocumentation() const + { + return m_osDocumentation; + } + + void AnalysePropertyValue(const GMLProperty *psGMLProperty, + bool bSetWidth = true); + + static bool IsSimpleType(GMLPropertyType eType) + { + return eType == GMLPT_String || eType == GMLPT_Integer || + eType == GMLPT_Real; + } +}; + +/************************************************************************/ +/* GMLGeometryPropertyDefn */ +/************************************************************************/ + +class CPL_DLL GMLGeometryPropertyDefn +{ + char *m_pszName = nullptr; + char *m_pszSrcElement = nullptr; + OGRwkbGeometryType m_nGeometryType = wkbUnknown; + const int m_nAttributeIndex = -1; + const bool m_bNullable = true; + bool m_bSRSNameConsistent = true; + std::string m_osSRSName{}; + OGRGeomCoordinatePrecision m_oCoordPrecision{}; + + CPL_DISALLOW_COPY_ASSIGN(GMLGeometryPropertyDefn) + + public: + GMLGeometryPropertyDefn(const char *pszName, const char *pszSrcElement, + OGRwkbGeometryType nType, int nAttributeIndex, + bool bNullable, + const OGRGeomCoordinatePrecision &oCoordPrec = + OGRGeomCoordinatePrecision()); + ~GMLGeometryPropertyDefn(); + + const char *GetName() const + { + return m_pszName; + } + + OGRwkbGeometryType GetType() const + { + return m_nGeometryType; + } + + void SetType(OGRwkbGeometryType nType) + { + m_nGeometryType = nType; + } + + const char *GetSrcElement() const + { + return m_pszSrcElement; + } + + int GetAttributeIndex() const + { + return m_nAttributeIndex; + } + + bool IsNullable() const + { + return m_bNullable; + } + + const OGRGeomCoordinatePrecision &GetCoordinatePrecision() const + { + return m_oCoordPrecision; + } + + void SetSRSName(const std::string &srsName) + { + m_bSRSNameConsistent = true; + m_osSRSName = srsName; + } + + void MergeSRSName(const std::string &osSRSName); + + const std::string &GetSRSName() const + { + return m_osSRSName; + } +}; + +/************************************************************************/ +/* GMLFeatureClass */ +/************************************************************************/ + +class CPL_DLL GMLFeatureClass +{ + char *m_pszName; + char *m_pszElementName; + int n_nNameLen; + int n_nElementNameLen; + int m_nPropertyCount; + GMLPropertyDefn **m_papoProperty; + std::map m_oMapPropertyNameToIndex{}; + std::map m_oMapPropertySrcElementToIndex{}; + + int m_nGeometryPropertyCount; + GMLGeometryPropertyDefn **m_papoGeometryProperty; + + bool m_bSchemaLocked; + + GIntBig m_nFeatureCount; + + char *m_pszExtraInfo; + + bool m_bHaveExtents; + double m_dfXMin; + double m_dfXMax; + double m_dfYMin; + double m_dfYMax; + + char *m_pszSRSName; + bool m_bSRSNameConsistent; + + bool m_bIsConsistentSingleGeomElemPath = true; + std::string m_osSingleGeomElemPath{}; + + CPL_DISALLOW_COPY_ASSIGN(GMLFeatureClass) + + public: + explicit GMLFeatureClass(const char *pszName = ""); + ~GMLFeatureClass(); + + const char *GetElementName() const; + size_t GetElementNameLen() const; + void SetElementName(const char *pszElementName); + + const char *GetName() const + { + return m_pszName; + } + + void SetName(const char *pszNewName); + + int GetPropertyCount() const + { + return m_nPropertyCount; + } + + GMLPropertyDefn *GetProperty(int iIndex) const; + int GetPropertyIndex(const char *pszName) const; + + GMLPropertyDefn *GetProperty(const char *pszName) const + { + return GetProperty(GetPropertyIndex(pszName)); + } + + int GetPropertyIndexBySrcElement(const char *pszElement, int nLen) const; + void StealProperties(); + + int GetGeometryPropertyCount() const + { + return m_nGeometryPropertyCount; + } + + GMLGeometryPropertyDefn *GetGeometryProperty(int iIndex) const; + int GetGeometryPropertyIndexBySrcElement(const char *pszElement) const; + void StealGeometryProperties(); + + bool HasFeatureProperties(); + + int AddProperty(GMLPropertyDefn *, int iPos = -1); + int AddGeometryProperty(GMLGeometryPropertyDefn *); + void ClearGeometryProperties(); + + void SetConsistentSingleGeomElemPath(bool b) + { + m_bIsConsistentSingleGeomElemPath = b; + } + + bool IsConsistentSingleGeomElemPath() const + { + return m_bIsConsistentSingleGeomElemPath; + } + + void SetSingleGeomElemPath(const std::string &s) + { + m_osSingleGeomElemPath = s; + } + + const std::string &GetSingleGeomElemPath() const + { + return m_osSingleGeomElemPath; + } + + bool IsSchemaLocked() const + { + return m_bSchemaLocked; + } + + void SetSchemaLocked(bool bLock) + { + m_bSchemaLocked = bLock; + } + + const char *GetExtraInfo(); + void SetExtraInfo(const char *); + + GIntBig GetFeatureCount(); + void SetFeatureCount(GIntBig); + + bool HasExtents() const + { + return m_bHaveExtents; + } + + void SetExtents(double dfXMin, double dfXMax, double dFYMin, double dfYMax); + bool GetExtents(double *pdfXMin, double *pdfXMax, double *pdFYMin, + double *pdfYMax); + + void SetSRSName(const char *pszSRSName); + void MergeSRSName(const char *pszSRSName); + + const char *GetSRSName() + { + return m_pszSRSName; + } + + CPLXMLNode *SerializeToXML(); + bool InitializeFromXML(CPLXMLNode *); +}; + +/************************************************************************/ +/* GMLFeature */ +/************************************************************************/ + +class CPL_DLL GMLFeature +{ + GMLFeatureClass *m_poClass; + char *m_pszFID; + + int m_nPropertyCount; + GMLProperty *m_pasProperties; + + int m_nGeometryCount; + CPLXMLNode **m_papsGeometry; /* NULL-terminated. Alias to m_apsGeometry if + m_nGeometryCount <= 1 */ + CPLXMLNode *m_apsGeometry[2]; /* NULL-terminated */ + + CPLXMLNode *m_psBoundedByGeometry = nullptr; + + CPL_DISALLOW_COPY_ASSIGN(GMLFeature) + + public: + explicit GMLFeature(GMLFeatureClass *); + ~GMLFeature(); + + GMLFeatureClass *GetClass() const + { + return m_poClass; + } + + void SetGeometryDirectly(CPLXMLNode *psGeom); + void SetGeometryDirectly(int nIdx, CPLXMLNode *psGeom); + void AddGeometry(CPLXMLNode *psGeom); + + int GetGeometryCount() const + { + return m_nGeometryCount; + } + + const CPLXMLNode *const *GetGeometryList() const + { + return m_papsGeometry; + } + + const CPLXMLNode *GetGeometryRef(int nIdx) const; + + void SetBoundedByGeometry(CPLXMLNode *psGeom); + + const CPLXMLNode *GetBoundedByGeometry() const + { + return m_psBoundedByGeometry; + } + + void SetPropertyDirectly(int i, char *pszValue); + + const GMLProperty *GetProperty(int i) const + { + return (i >= 0 && i < m_nPropertyCount) ? &m_pasProperties[i] : nullptr; + } + + const char *GetFID() const + { + return m_pszFID; + } + + void SetFID(const char *pszFID); + + void Dump(FILE *fp); +}; + +OGRFieldType CPL_DLL GML_GetOGRFieldType(GMLPropertyType eType, + OGRFieldSubType &eSubType); + +#endif diff --git a/ogr/ogrsf_frmts/gml/gmlfeatureclass.cpp b/ogr/ogrsf_frmts/gmlutils/gmlfeatureclass.cpp similarity index 99% rename from ogr/ogrsf_frmts/gml/gmlfeatureclass.cpp rename to ogr/ogrsf_frmts/gmlutils/gmlfeatureclass.cpp index 86871ce29e30..7e7a199da824 100644 --- a/ogr/ogrsf_frmts/gml/gmlfeatureclass.cpp +++ b/ogr/ogrsf_frmts/gmlutils/gmlfeatureclass.cpp @@ -28,7 +28,7 @@ ****************************************************************************/ #include "cpl_port.h" -#include "gmlreader.h" +#include "gmlfeature.h" #include #include diff --git a/ogr/ogrsf_frmts/gml/gmlpropertydefn.cpp b/ogr/ogrsf_frmts/gmlutils/gmlpropertydefn.cpp similarity index 99% rename from ogr/ogrsf_frmts/gml/gmlpropertydefn.cpp rename to ogr/ogrsf_frmts/gmlutils/gmlpropertydefn.cpp index 622359e99fbc..9eb93da06bdf 100644 --- a/ogr/ogrsf_frmts/gml/gmlpropertydefn.cpp +++ b/ogr/ogrsf_frmts/gmlutils/gmlpropertydefn.cpp @@ -28,7 +28,7 @@ ****************************************************************************/ #include "cpl_port.h" -#include "gmlreader.h" +#include "gmlfeature.h" #include diff --git a/ogr/ogrsf_frmts/gml/gmlutils.cpp b/ogr/ogrsf_frmts/gmlutils/gmlutils.cpp similarity index 100% rename from ogr/ogrsf_frmts/gml/gmlutils.cpp rename to ogr/ogrsf_frmts/gmlutils/gmlutils.cpp diff --git a/ogr/ogrsf_frmts/gml/gmlutils.h b/ogr/ogrsf_frmts/gmlutils/gmlutils.h similarity index 82% rename from ogr/ogrsf_frmts/gml/gmlutils.h rename to ogr/ogrsf_frmts/gmlutils/gmlutils.h index 04de1deef375..329af13c3232 100644 --- a/ogr/ogrsf_frmts/gml/gmlutils.h +++ b/ogr/ogrsf_frmts/gmlutils/gmlutils.h @@ -50,24 +50,25 @@ typedef enum SRSNAME_OGC_URL } OGRGMLSRSNameFormat; -const char * +const char CPL_DLL * GML_ExtractSrsNameFromGeometry(const CPLXMLNode *const *papsGeometry, std::string &osWork, bool bConsiderEPSGAsURN); -bool GML_IsSRSLatLongOrder(const char *pszSRSName); -bool GML_IsLegitSRSName(const char *pszSRSName); +bool CPL_DLL GML_IsSRSLatLongOrder(const char *pszSRSName); +bool CPL_DLL GML_IsLegitSRSName(const char *pszSRSName); -void *GML_BuildOGRGeometryFromList_CreateCache(); -void GML_BuildOGRGeometryFromList_DestroyCache(void *hCacheSRS); +void CPL_DLL *GML_BuildOGRGeometryFromList_CreateCache(); +void CPL_DLL GML_BuildOGRGeometryFromList_DestroyCache(void *hCacheSRS); -OGRGeometry *GML_BuildOGRGeometryFromList( +OGRGeometry CPL_DLL *GML_BuildOGRGeometryFromList( const CPLXMLNode *const *papsGeometry, bool bTryToMakeMultipolygons, bool bInvertAxisOrderIfLatLong, const char *pszDefaultSRSName, bool bConsiderEPSGAsURN, GMLSwapCoordinatesEnum eSwapCoordinates, int nPseudoBoolGetSecondaryGeometryOption, void *hCacheSRS, bool bFaceHoleNegative = false); -char *GML_GetSRSName(const OGRSpatialReference *poSRS, - OGRGMLSRSNameFormat eSRSNameFormat, bool *pbCoordSwap); +char CPL_DLL *GML_GetSRSName(const OGRSpatialReference *poSRS, + OGRGMLSRSNameFormat eSRSNameFormat, + bool *pbCoordSwap); #endif /* _CPL_GMLREADERP_H_INCLUDED */ diff --git a/ogr/ogrsf_frmts/wfs/ogrwfsfilter.cpp b/ogr/ogrsf_frmts/gmlutils/ogrwfsfilter.cpp similarity index 98% rename from ogr/ogrsf_frmts/wfs/ogrwfsfilter.cpp rename to ogr/ogrsf_frmts/gmlutils/ogrwfsfilter.cpp index 7a794afbd6aa..f8f7f3477f46 100644 --- a/ogr/ogrsf_frmts/wfs/ogrwfsfilter.cpp +++ b/ogr/ogrsf_frmts/gmlutils/ogrwfsfilter.cpp @@ -26,7 +26,7 @@ * DEALINGS IN THE SOFTWARE. ****************************************************************************/ -#include "ogr_wfs.h" +#include "ogrwfsfilter.h" #include "ogr_p.h" typedef struct @@ -154,13 +154,12 @@ static const char *WFS_ExprGetSRSName(const swq_expr_node *poExpr, else if (poExpr->nSubExprCount == iSubArgIndex + 1 && poExpr->papoSubExpr[iSubArgIndex]->field_type == SWQ_INTEGER) { - if (oSRS.importFromEPSGA( - (int)poExpr->papoSubExpr[iSubArgIndex]->int_value) == - OGRERR_NONE) + if (oSRS.importFromEPSGA(static_cast( + poExpr->papoSubExpr[iSubArgIndex]->int_value)) == OGRERR_NONE) { return CPLSPrintf( "urn:ogc:def:crs:EPSG::%d", - (int)poExpr->papoSubExpr[iSubArgIndex]->int_value); + static_cast(poExpr->papoSubExpr[iSubArgIndex]->int_value)); } } else if (poExpr->nSubExprCount == iSubArgIndex && @@ -522,7 +521,8 @@ static bool WFS_ExprDumpAsOGCFilter(CPLString &osFilter, papszOptions = CSLSetNameValue(papszOptions, "GMLID", CPLSPrintf("id%d", psOptions->nUniqueGeomGMLId++)); - char *pszGML = OGR_G_ExportToGMLEx((OGRGeometryH)poGeom, papszOptions); + char *pszGML = + OGR_G_ExportToGMLEx(OGRGeometry::ToHandle(poGeom), papszOptions); osFilter += pszGML; CSLDestroy(papszOptions); delete poGeom; @@ -690,8 +690,8 @@ static bool OGRWFSCheckSRIDArg(swq_expr_node *op, int iSubArgIndex) if (op->papoSubExpr[iSubArgIndex]->field_type == SWQ_INTEGER) { OGRSpatialReference oSRS; - if (oSRS.importFromEPSGA( - (int)op->papoSubExpr[iSubArgIndex]->int_value) != OGRERR_NONE) + if (oSRS.importFromEPSGA(static_cast( + op->papoSubExpr[iSubArgIndex]->int_value)) != OGRERR_NONE) { CPLError(CE_Failure, CPLE_AppDefined, "Wrong value for argument %d of %s", iSubArgIndex + 1, @@ -885,11 +885,10 @@ static const swq_operation OGRWFSSpatialOps[] = { const swq_operation *OGRWFSCustomFuncRegistrar::GetOperator(const char *pszName) { - for (int i = 0; - i < (int)(sizeof(OGRWFSSpatialOps) / sizeof(OGRWFSSpatialOps[0])); i++) + for (const auto &op : OGRWFSSpatialOps) { - if (EQUAL(OGRWFSSpatialOps[i].pszName, pszName)) - return &OGRWFSSpatialOps[i]; + if (EQUAL(op.pszName, pszName)) + return &op; } return nullptr; } diff --git a/ogr/ogrsf_frmts/gmlutils/ogrwfsfilter.h b/ogr/ogrsf_frmts/gmlutils/ogrwfsfilter.h new file mode 100644 index 000000000000..84120004bedb --- /dev/null +++ b/ogr/ogrsf_frmts/gmlutils/ogrwfsfilter.h @@ -0,0 +1,29 @@ +/****************************************************************************** + * Project: WFS Reader + * Purpose: WFS filtering + * Purpose: Implements OGR SQL into OGC Filter translation. + * Author: Even Rouault, + * + ****************************************************************************** + * Copyright (c) 2010-2012, Even Rouault + * + * SPDX-License-Identifier: MIT + ****************************************************************************/ + +#ifndef OGRWFSFILTER_H_INCLUDED +#define OGRWFSFILTER_H_INCLUDED + +#include "cpl_string.h" +#include "gdal_priv.h" +#include "ogr_feature.h" +#include "ogrsf_frmts.h" +#include "ogr_swq.h" + +CPLString CPL_DLL WFS_TurnSQLFilterToOGCFilter( + const swq_expr_node *poExpr, GDALDataset *poDS, OGRFeatureDefn *poFDefn, + int nVersion, int bPropertyIsNotEqualToSupported, int bUseFeatureId, + int bGmlObjectIdNeedsGMLPrefix, const char *pszNSPrefix, + int *pbOutNeedsNullCheck); +swq_custom_func_registrar CPL_DLL *WFSGetCustomFuncRegistrar(); + +#endif diff --git a/ogr/ogrsf_frmts/gml/parsexsd.cpp b/ogr/ogrsf_frmts/gmlutils/parsexsd.cpp similarity index 100% rename from ogr/ogrsf_frmts/gml/parsexsd.cpp rename to ogr/ogrsf_frmts/gmlutils/parsexsd.cpp diff --git a/ogr/ogrsf_frmts/gml/parsexsd.h b/ogr/ogrsf_frmts/gmlutils/parsexsd.h similarity index 98% rename from ogr/ogrsf_frmts/gml/parsexsd.h rename to ogr/ogrsf_frmts/gmlutils/parsexsd.h index 02f4582907ea..a4a97933639b 100644 --- a/ogr/ogrsf_frmts/gml/parsexsd.h +++ b/ogr/ogrsf_frmts/gmlutils/parsexsd.h @@ -34,7 +34,7 @@ #include "cpl_port.h" #include -#include "gmlreader.h" +#include "gmlfeature.h" bool CPL_DLL GMLParseXSD(const char *pszFile, bool bUseSchemaImports, std::vector &aosClasses, diff --git a/ogr/ogrsf_frmts/nas/CMakeLists.txt b/ogr/ogrsf_frmts/nas/CMakeLists.txt index c47dd844ee71..7386ce5a0f37 100644 --- a/ogr/ogrsf_frmts/nas/CMakeLists.txt +++ b/ogr/ogrsf_frmts/nas/CMakeLists.txt @@ -9,7 +9,7 @@ add_gdal_driver( ogrnaslayer.cpp BUILTIN) # BUILTIN because of GML dependency gdal_standard_includes(ogr_NAS) -target_include_directories(ogr_NAS PRIVATE $) +target_include_directories(ogr_NAS PRIVATE $ $) if (GDAL_USE_EXPAT) target_compile_definitions(ogr_NAS PRIVATE -DHAVE_EXPAT) gdal_target_link_libraries(ogr_NAS PRIVATE ${EXPAT_TARGET}) diff --git a/ogr/ogrsf_frmts/wfs/CMakeLists.txt b/ogr/ogrsf_frmts/wfs/CMakeLists.txt index b0d0e59426df..c096af8976de 100644 --- a/ogr/ogrsf_frmts/wfs/CMakeLists.txt +++ b/ogr/ogrsf_frmts/wfs/CMakeLists.txt @@ -3,10 +3,13 @@ add_gdal_driver( SOURCES ogr_wfs.h ogrwfsdatasource.cpp ogrwfsdriver.cpp - ogrwfsfilter.cpp ogrwfsjoinlayer.cpp ogrwfslayer.cpp ogroapifdriver.cpp - BUILTIN) + PLUGIN_CAPABLE + NO_DEPS) gdal_standard_includes(ogr_WFS) -target_include_directories(ogr_WFS PRIVATE $) +target_include_directories(ogr_WFS PRIVATE $) +if (OGR_ENABLE_DRIVER_WFS_PLUGIN) + target_compile_definitions(ogr_WFS PRIVATE PLUGIN) +endif() diff --git a/ogr/ogrsf_frmts/wfs/ogr_wfs.h b/ogr/ogrsf_frmts/wfs/ogr_wfs.h index 1098f753fcb2..2c4b6dd313a4 100644 --- a/ogr/ogrsf_frmts/wfs/ogr_wfs.h +++ b/ogr/ogrsf_frmts/wfs/ogr_wfs.h @@ -36,20 +36,12 @@ #include "cpl_minixml.h" #include "ogrsf_frmts.h" -#include "gmlreader.h" +#include "gmlfeature.h" #include "cpl_http.h" #include "ogr_swq.h" const CPLXMLNode *WFSFindNode(const CPLXMLNode *psXML, const char *pszRootName); -CPLString -WFS_TurnSQLFilterToOGCFilter(const swq_expr_node *poExpr, GDALDataset *poDS, - OGRFeatureDefn *poFDefn, int nVersion, - int bPropertyIsNotEqualToSupported, - int bUseFeatureId, int bGmlObjectIdNeedsGMLPrefix, - const char *pszNSPrefix, int *pbOutNeedsNullCheck); -swq_custom_func_registrar *WFSGetCustomFuncRegistrar(); - const char *FindSubStringInsensitive(const char *pszStr, const char *pszSubStr); CPLString WFS_EscapeURL(const char *pszURL); diff --git a/ogr/ogrsf_frmts/wfs/ogrwfsdatasource.cpp b/ogr/ogrsf_frmts/wfs/ogrwfsdatasource.cpp index 889c76a36879..0cc3b2dc0a1d 100644 --- a/ogr/ogrsf_frmts/wfs/ogrwfsdatasource.cpp +++ b/ogr/ogrsf_frmts/wfs/ogrwfsdatasource.cpp @@ -35,6 +35,7 @@ #include "parsexsd.h" #include "ogr_swq.h" #include "ogr_p.h" +#include "ogrwfsfilter.h" #include diff --git a/ogr/ogrsf_frmts/wfs/ogrwfsdriver.cpp b/ogr/ogrsf_frmts/wfs/ogrwfsdriver.cpp index 51471bd9f7d1..ac70998fb60b 100644 --- a/ogr/ogrsf_frmts/wfs/ogrwfsdriver.cpp +++ b/ogr/ogrsf_frmts/wfs/ogrwfsdriver.cpp @@ -149,4 +149,8 @@ void RegisterOGRWFS() poDriver->pfnOpen = OGRWFSDriverOpen; GetGDALDriverManager()->RegisterDriver(poDriver); + +#ifdef PLUGIN + RegisterOGROAPIF(); +#endif } diff --git a/ogr/ogrsf_frmts/wfs/ogrwfsjoinlayer.cpp b/ogr/ogrsf_frmts/wfs/ogrwfsjoinlayer.cpp index e9d09819a528..515a150087ad 100644 --- a/ogr/ogrsf_frmts/wfs/ogrwfsjoinlayer.cpp +++ b/ogr/ogrsf_frmts/wfs/ogrwfsjoinlayer.cpp @@ -27,6 +27,7 @@ ****************************************************************************/ #include "ogr_wfs.h" +#include "ogrwfsfilter.h" #include "cpl_md5.h" /************************************************************************/ diff --git a/ogr/ogrsf_frmts/wfs/ogrwfslayer.cpp b/ogr/ogrsf_frmts/wfs/ogrwfslayer.cpp index 5773e38c75e3..f38ea61f4637 100644 --- a/ogr/ogrsf_frmts/wfs/ogrwfslayer.cpp +++ b/ogr/ogrsf_frmts/wfs/ogrwfslayer.cpp @@ -32,6 +32,7 @@ #include "cpl_minixml.h" #include "cpl_http.h" #include "parsexsd.h" +#include "ogrwfsfilter.h" /************************************************************************/ /* OGRWFSLayer() */ From 579ffc71c55bda6c639d37fe0fcd413924cdfb60 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Wed, 2 Oct 2024 14:14:00 +0200 Subject: [PATCH 3/3] Build: make the OAPIF driver independent from the WFS one, and plugin capable --- ogr/ogrsf_frmts/CMakeLists.txt | 4 +++- ogr/ogrsf_frmts/generic/ogrregisterall.cpp | 2 ++ ogr/ogrsf_frmts/oapif/CMakeLists.txt | 8 ++++++++ ogr/ogrsf_frmts/{wfs => oapif}/ogroapifdriver.cpp | 0 ogr/ogrsf_frmts/wfs/CMakeLists.txt | 4 ---- ogr/ogrsf_frmts/wfs/ogrwfsdriver.cpp | 4 ---- 6 files changed, 13 insertions(+), 9 deletions(-) create mode 100644 ogr/ogrsf_frmts/oapif/CMakeLists.txt rename ogr/ogrsf_frmts/{wfs => oapif}/ogroapifdriver.cpp (100%) diff --git a/ogr/ogrsf_frmts/CMakeLists.txt b/ogr/ogrsf_frmts/CMakeLists.txt index 7bebf98ca12f..e4cd0c4f044b 100644 --- a/ogr/ogrsf_frmts/CMakeLists.txt +++ b/ogr/ogrsf_frmts/CMakeLists.txt @@ -48,8 +48,9 @@ ogr_optional_driver(avc AVC) if (NOT(DEFINED OGR_ENABLE_DRIVER_GML AND NOT OGR_ENABLE_DRIVER_GML AND ((NOT GDAL_USE_CURL) OR (DEFINED OGR_ENABLE_DRIVER_WFS AND NOT OGR_ENABLE_DRIVER_WFS AND + DEFINED OGR_ENABLE_DRIVER_OAPIF AND NOT OGR_ENABLE_DRIVER_OAPIF AND DEFINED OGR_ENABLE_DRIVER_CSW AND NOT OGR_ENABLE_DRIVER_CSW)))) - # Only build gmlutils if we have GML, WFS or CSW + # Only build gmlutils if we have GML, WFS, OAPIF or CSW add_subdirectory(gmlutils) endif() @@ -108,6 +109,7 @@ ogr_dependent_driver(nas "NAS/ALKIS" "GDAL_USE_XERCESC;OGR_ENABLE_DRIVER_GML") ogr_dependent_driver(plscenes PLSCENES "GDAL_USE_CURL") ogr_dependent_driver(sosi "SOSI:Systematic Organization of Spatial Information" "GDAL_USE_FYBA") ogr_dependent_driver(wfs "OGC WFS service" "GDAL_USE_CURL") +ogr_dependent_driver(oapif "OGC API Features service" "GDAL_USE_CURL") ogr_dependent_driver(ngw "NextGIS Web" "GDAL_USE_CURL") ogr_dependent_driver(elastic "ElasticSearch" "GDAL_USE_CURL") ogr_dependent_driver(xodr OpenDRIVE "GDAL_USE_OPENDRIVE;GDAL_USE_GEOS") diff --git a/ogr/ogrsf_frmts/generic/ogrregisterall.cpp b/ogr/ogrsf_frmts/generic/ogrregisterall.cpp index f759e377d59c..f47094f04648 100644 --- a/ogr/ogrsf_frmts/generic/ogrregisterall.cpp +++ b/ogr/ogrsf_frmts/generic/ogrregisterall.cpp @@ -180,6 +180,8 @@ void OGRRegisterAllInternal() #endif #ifdef WFS_ENABLED RegisterOGRWFS(); +#endif +#ifdef OAPIF_ENABLED RegisterOGROAPIF(); #endif #ifdef SOSI_ENABLED diff --git a/ogr/ogrsf_frmts/oapif/CMakeLists.txt b/ogr/ogrsf_frmts/oapif/CMakeLists.txt new file mode 100644 index 000000000000..0f38ff550939 --- /dev/null +++ b/ogr/ogrsf_frmts/oapif/CMakeLists.txt @@ -0,0 +1,8 @@ +add_gdal_driver( + TARGET ogr_OAPIF + SOURCES ogroapifdriver.cpp + PLUGIN_CAPABLE + NO_DEPS + STRONG_CXX_FLAGS) +gdal_standard_includes(ogr_OAPIF) +target_include_directories(ogr_OAPIF PRIVATE $) diff --git a/ogr/ogrsf_frmts/wfs/ogroapifdriver.cpp b/ogr/ogrsf_frmts/oapif/ogroapifdriver.cpp similarity index 100% rename from ogr/ogrsf_frmts/wfs/ogroapifdriver.cpp rename to ogr/ogrsf_frmts/oapif/ogroapifdriver.cpp diff --git a/ogr/ogrsf_frmts/wfs/CMakeLists.txt b/ogr/ogrsf_frmts/wfs/CMakeLists.txt index c096af8976de..bb972020df0b 100644 --- a/ogr/ogrsf_frmts/wfs/CMakeLists.txt +++ b/ogr/ogrsf_frmts/wfs/CMakeLists.txt @@ -5,11 +5,7 @@ add_gdal_driver( ogrwfsdriver.cpp ogrwfsjoinlayer.cpp ogrwfslayer.cpp - ogroapifdriver.cpp PLUGIN_CAPABLE NO_DEPS) gdal_standard_includes(ogr_WFS) target_include_directories(ogr_WFS PRIVATE $) -if (OGR_ENABLE_DRIVER_WFS_PLUGIN) - target_compile_definitions(ogr_WFS PRIVATE PLUGIN) -endif() diff --git a/ogr/ogrsf_frmts/wfs/ogrwfsdriver.cpp b/ogr/ogrsf_frmts/wfs/ogrwfsdriver.cpp index ac70998fb60b..51471bd9f7d1 100644 --- a/ogr/ogrsf_frmts/wfs/ogrwfsdriver.cpp +++ b/ogr/ogrsf_frmts/wfs/ogrwfsdriver.cpp @@ -149,8 +149,4 @@ void RegisterOGRWFS() poDriver->pfnOpen = OGRWFSDriverOpen; GetGDALDriverManager()->RegisterDriver(poDriver); - -#ifdef PLUGIN - RegisterOGROAPIF(); -#endif }