Skip to content

Commit

Permalink
fix detecting 3D geometry for OGR format
Browse files Browse the repository at this point in the history
  • Loading branch information
vcloarec authored and nyalldawson committed Nov 18, 2021
1 parent c0bbed3 commit 77fc85e
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/core/providers/ogr/qgsogrproviderutils.cpp
Expand Up @@ -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() )
Expand Down Expand Up @@ -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" ) );
Expand All @@ -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" ) );

Expand Down

0 comments on commit 77fc85e

Please sign in to comment.