-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
When a OGR layer is of geometry type "unknown", we use the geometry of the first feature to guess the geometry type. But if this feature has no geometry, then we assume that we have no geometry for the whole layer. This is a bit extreme. Let us allow to probe a few features before giving up. Fixes #15065
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -706,23 +706,26 @@ OGRwkbGeometryType QgsOgrProvider::getOgrGeomType( OGRLayerH ogrLayer ) | |
|
||
// Some ogr drivers (e.g. GML) are not able to determine the geometry type of a layer like this. | ||
// In such cases, we use virtual sublayers for each geometry if the layer contains | ||
// multiple geometries (see subLayers) otherwise we guess geometry type from first feature | ||
// multiple geometries (see subLayers) otherwise we guess geometry type from the first | ||
// feature that has a geometry (limit us to a few features, not the whole layer) | ||
if ( geomType == wkbUnknown ) | ||
{ | ||
geomType = wkbNone; | ||
OGR_L_ResetReading( ogrLayer ); | ||
OGRFeatureH firstFeature = OGR_L_GetNextFeature( ogrLayer ); | ||
if ( firstFeature ) | ||
for ( int i = 0; i < 10; i++ ) | ||
{ | ||
OGRGeometryH firstGeometry = OGR_F_GetGeometryRef( firstFeature ); | ||
if ( firstGeometry ) | ||
{ | ||
geomType = OGR_G_GetGeometryType( firstGeometry ); | ||
} | ||
else | ||
OGRFeatureH nextFeature = OGR_L_GetNextFeature( ogrLayer ); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
rouault
Author
Contributor
|
||
if ( !nextFeature ) | ||
break; | ||
|
||
OGRGeometryH geometry = OGR_F_GetGeometryRef( nextFeature ); | ||
if ( geometry ) | ||
{ | ||
geomType = wkbNone; | ||
geomType = OGR_G_GetGeometryType( geometry ); | ||
} | ||
OGR_F_Destroy( firstFeature ); | ||
OGR_F_Destroy( nextFeature ); | ||
if ( geomType != wkbNone ) | ||
break; | ||
} | ||
OGR_L_ResetReading( ogrLayer ); | ||
} | ||
|
@rouault I'm seeing a crash here about 50% of the time in the TestQgsDataItem::testDirItemChildren() test. I can't work out what's causing this - it's happening on the first feature (i=0), so to me the code path looks the same as before.