From 4a9078b00804fc0de0063d36cbbde997a24c087a Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Sat, 18 Sep 2021 15:37:17 +0200 Subject: [PATCH] Merge pull request #4506 from rouault/gfs_warning_geomtype GML: fix warning when reading .gfs file with a polyhedral surface --- gdal/ogr/ogr_core.h | 24 ++++++++--------- gdal/ogr/ogrsf_frmts/gml/gmlfeatureclass.cpp | 27 ++++++++++++++------ 2 files changed, 31 insertions(+), 20 deletions(-) diff --git a/gdal/ogr/ogr_core.h b/gdal/ogr/ogr_core.h index a92e606a3e0a..7fb863f63a3f 100644 --- a/gdal/ogr/ogr_core.h +++ b/gdal/ogr/ogr_core.h @@ -369,10 +369,10 @@ typedef enum wkbCurve = 13, /**< Curve (abstract type). ISO SQL/MM Part 3. GDAL >= 2.1 */ wkbSurface = 14, /**< Surface (abstract type). ISO SQL/MM Part 3. GDAL >= 2.1 */ wkbPolyhedralSurface = 15,/**< a contiguous collection of polygons, which share common boundary segments, - * ISO SQL/MM Part 3. Reserved in GDAL >= 2.1 but not yet implemented */ + * ISO SQL/MM Part 3. GDAL >= 2.3 */ wkbTIN = 16, /**< a PolyhedralSurface consisting only of Triangle patches - * ISO SQL/MM Part 3. Reserved in GDAL >= 2.1 but not yet implemented */ - wkbTriangle = 17, /**< a Triangle. ISO SQL/MM Part 3. Reserved in GDAL >= 2.1 but not yet implemented */ + * ISO SQL/MM Part 3. GDAL >= 2.3 */ + wkbTriangle = 17, /**< a Triangle. ISO SQL/MM Part 3. GDAL >= 2.3 */ wkbNone = 100, /**< non-standard, for pure attribute records */ wkbLinearRing = 101, /**< non-standard, just for createGeometry() */ @@ -384,9 +384,9 @@ typedef enum wkbMultiSurfaceZ = 1012, /**< wkbMultiSurface with Z component. ISO SQL/MM Part 3. GDAL >= 2.0 */ wkbCurveZ = 1013, /**< wkbCurve with Z component. ISO SQL/MM Part 3. GDAL >= 2.1 */ wkbSurfaceZ = 1014, /**< wkbSurface with Z component. ISO SQL/MM Part 3. GDAL >= 2.1 */ - wkbPolyhedralSurfaceZ = 1015, /**< ISO SQL/MM Part 3. Reserved in GDAL >= 2.1 but not yet implemented */ - wkbTINZ = 1016, /**< ISO SQL/MM Part 3. Reserved in GDAL >= 2.1 but not yet implemented */ - wkbTriangleZ = 1017, /**< ISO SQL/MM Part 3. Reserved in GDAL >= 2.1 but not yet implemented */ + wkbPolyhedralSurfaceZ = 1015, /**< ISO SQL/MM Part 3. GDAL >= 2.3 */ + wkbTINZ = 1016, /**< ISO SQL/MM Part 3. GDAL >= 2.3 */ + wkbTriangleZ = 1017, /**< ISO SQL/MM Part 3. GDAL >= 2.3 */ wkbPointM = 2001, /**< ISO SQL/MM Part 3. GDAL >= 2.1 */ wkbLineStringM = 2002, /**< ISO SQL/MM Part 3. GDAL >= 2.1 */ @@ -402,9 +402,9 @@ typedef enum wkbMultiSurfaceM = 2012, /**< ISO SQL/MM Part 3. GDAL >= 2.1 */ wkbCurveM = 2013, /**< ISO SQL/MM Part 3. GDAL >= 2.1 */ wkbSurfaceM = 2014, /**< ISO SQL/MM Part 3. GDAL >= 2.1 */ - wkbPolyhedralSurfaceM = 2015, /**< ISO SQL/MM Part 3. Reserved in GDAL >= 2.1 but not yet implemented */ - wkbTINM = 2016, /**< ISO SQL/MM Part 3. Reserved in GDAL >= 2.1 but not yet implemented */ - wkbTriangleM = 2017, /**< ISO SQL/MM Part 3. Reserved in GDAL >= 2.1 but not yet implemented */ + wkbPolyhedralSurfaceM = 2015, /**< ISO SQL/MM Part 3. GDAL >= 2.3 */ + wkbTINM = 2016, /**< ISO SQL/MM Part 3. GDAL >= 2.3 */ + wkbTriangleM = 2017, /**< ISO SQL/MM Part 3. GDAL >= 2.3 */ wkbPointZM = 3001, /**< ISO SQL/MM Part 3. GDAL >= 2.1 */ wkbLineStringZM = 3002, /**< ISO SQL/MM Part 3. GDAL >= 2.1 */ @@ -420,9 +420,9 @@ typedef enum wkbMultiSurfaceZM = 3012, /**< ISO SQL/MM Part 3. GDAL >= 2.1 */ wkbCurveZM = 3013, /**< ISO SQL/MM Part 3. GDAL >= 2.1 */ wkbSurfaceZM = 3014, /**< ISO SQL/MM Part 3. GDAL >= 2.1 */ - wkbPolyhedralSurfaceZM = 3015, /**< ISO SQL/MM Part 3. Reserved in GDAL >= 2.1 but not yet implemented */ - wkbTINZM = 3016, /**< ISO SQL/MM Part 3. Reserved in GDAL >= 2.1 but not yet implemented */ - wkbTriangleZM = 3017, /**< ISO SQL/MM Part 3. Reserved in GDAL >= 2.1 but not yet implemented */ + wkbPolyhedralSurfaceZM = 3015, /**< ISO SQL/MM Part 3. GDAL >= 2.3 */ + wkbTINZM = 3016, /**< ISO SQL/MM Part 3. GDAL >= 2.3 */ + wkbTriangleZM = 3017, /**< ISO SQL/MM Part 3. GDAL >= 2.3 */ #if defined(DOXYGEN_SKIP) // Sphinx doesn't like 0x8000000x constants diff --git a/gdal/ogr/ogrsf_frmts/gml/gmlfeatureclass.cpp b/gdal/ogr/ogrsf_frmts/gml/gmlfeatureclass.cpp index 73f7de8f0f6a..41013b481f46 100644 --- a/gdal/ogr/ogrsf_frmts/gml/gmlfeatureclass.cpp +++ b/gdal/ogr/ogrsf_frmts/gml/gmlfeatureclass.cpp @@ -42,6 +42,7 @@ #include "cpl_minixml.h" #include "cpl_string.h" #include "ogr_core.h" +#include "ogr_p.h" #include "ogr_geometry.h" CPL_CVSID("$Id$") @@ -468,6 +469,18 @@ bool GMLFeatureClass::InitializeFromXML( CPLXMLNode *psRoot ) const char *pszGPath = ""; int nGeomType = wkbUnknown; + const auto FlattenGeomTypeFromInt = [] (int eType) + { + eType = eType & (~wkb25DBitInternalUse); + if( eType >= 1000 && eType < 2000 ) // ISO Z. + return eType - 1000; + if( eType >= 2000 && eType < 3000 ) // ISO M. + return eType - 2000; + if( eType >= 3000 && eType < 4000 ) // ISO ZM. + return eType - 3000; + return eType; + }; + CPLXMLNode *psThis = nullptr; for( psThis = psRoot->psChild; psThis != nullptr; psThis = psThis->psNext ) { @@ -484,11 +497,10 @@ bool GMLFeatureClass::InitializeFromXML( CPLXMLNode *psRoot ) if( pszType != nullptr && !EQUAL(pszType, "0") ) { nGeomType = atoi(pszType); - const OGRwkbGeometryType nFlattenGeomType = - wkbFlatten(nGeomType); + const int nFlattenGeomType = FlattenGeomTypeFromInt(nGeomType); if( nGeomType != 0 && - !(nFlattenGeomType >= wkbPoint && - nFlattenGeomType <= wkbMultiSurface) ) + !(nFlattenGeomType >= static_cast(wkbPoint) && + nFlattenGeomType <= static_cast(wkbTIN)) ) { nGeomType = wkbUnknown; CPLError(CE_Warning, CPLE_AppDefined, @@ -571,8 +583,7 @@ bool GMLFeatureClass::InitializeFromXML( CPLXMLNode *psRoot ) if( pszGeometryType != nullptr && !EQUAL(pszGeometryType, "0") ) { nGeomType = atoi(pszGeometryType); - const OGRwkbGeometryType nFlattenGeomType = - wkbFlatten(nGeomType); + const int nFlattenGeomType = FlattenGeomTypeFromInt(nGeomType); if( nGeomType == 100 || EQUAL(pszGeometryType, "NONE") ) { bHasValidGeometryElementPath = false; @@ -580,8 +591,8 @@ bool GMLFeatureClass::InitializeFromXML( CPLXMLNode *psRoot ) break; } else if( nGeomType != 0 && - !(nFlattenGeomType >= wkbPoint && - nFlattenGeomType <= wkbMultiSurface) ) + !(nFlattenGeomType >= static_cast(wkbPoint) && + nFlattenGeomType <= static_cast(wkbTIN)) ) { nGeomType = wkbUnknown; CPLError(CE_Warning, CPLE_AppDefined,