Skip to content
Permalink
Browse files
fix detecting 3D geometry for OGR format
  • Loading branch information
vcloarec authored and nyalldawson committed Nov 18, 2021
1 parent c0bbed3 commit 77fc85e203d2c98315fdacde67578125ae52cb12
Showing with 9 additions and 3 deletions.
  1. +9 −3 src/core/providers/ogr/qgsogrproviderutils.cpp
@@ -2448,16 +2448,21 @@ QList< QgsProviderSublayerDetails > QgsOgrProviderUtils::querySubLayerList( int
// Add virtual sublayers for supported geometry types if layer type is unknown
// Count features for geometry types
QMap<OGRwkbGeometryType, int> fCount;
QSet<OGRwkbGeometryType> fHasZ;
// TODO: avoid reading attributes, setRelevantFields cannot be called here because it is not constant

layer->ResetReading();
gdal::ogr_feature_unique_ptr fet;
while ( fet.reset( layer->GetNextFeature() ), fet )
{
const OGRwkbGeometryType gType = QgsOgrProviderUtils::ogrWkbSingleFlatten( resolveGeometryTypeForFeature( fet.get(), driverName ) );
OGRwkbGeometryType gType = resolveGeometryTypeForFeature( fet.get(), driverName );
if ( gType != wkbNone )
{
bool hasZ = wkbHasZ( gType );
gType = QgsOgrProviderUtils::ogrWkbSingleFlatten( gType );
fCount[gType] = fCount.value( gType ) + 1;
if ( hasZ )
fHasZ.insert( gType );
}

if ( feedback && feedback->isCanceled() )
@@ -2528,7 +2533,7 @@ QList< QgsProviderSublayerDetails > QgsOgrProviderUtils::querySubLayerList( int
}
}
details.setFeatureCount( fCount.value( countIt.key() ) );
details.setWkbType( QgsOgrUtils::ogrGeometryTypeToQgsWkbType( ( bIs25D ) ? wkbSetZ( countIt.key() ) : countIt.key() ) );
details.setWkbType( QgsOgrUtils::ogrGeometryTypeToQgsWkbType( ( bIs25D || fHasZ.contains( countIt.key() ) ) ? wkbSetZ( countIt.key() ) : countIt.key() ) );
details.setGeometryColumnName( geometryColumnName );
details.setDescription( longDescription );
details.setProviderKey( QStringLiteral( "ogr" ) );
@@ -2539,7 +2544,8 @@ QList< QgsProviderSublayerDetails > QgsOgrProviderUtils::querySubLayerList( int
// in the uri for the sublayers (otherwise we'll be forced to re-do this iteration whenever
// the uri from the sublayer is used to construct an actual vector layer)
if ( details.wkbType() != QgsWkbTypes::Unknown )
parts.insert( QStringLiteral( "geometryType" ), ogrWkbGeometryTypeName( countIt.key() ) );
parts.insert( QStringLiteral( "geometryType" ),
ogrWkbGeometryTypeName( ( bIs25D || fHasZ.contains( countIt.key() ) ) ? wkbSetZ( countIt.key() ) : countIt.key() ) );
else
parts.remove( QStringLiteral( "geometryType" ) );

0 comments on commit 77fc85e

Please sign in to comment.