Skip to content
Permalink
Browse files

[OGR provider] Avoid attribute table to be empty on OGR layer with mi…

…xed geom types (fixes #19077)
  • Loading branch information
rouault committed May 31, 2018
1 parent 9fcee52 commit ee06d52421edfb1b98ccc29ff1d183eeb2adcf1c
@@ -92,7 +92,10 @@ QgsOgrFeatureIterator::QgsOgrFeatureIterator( QgsOgrFeatureSource *source, bool
return;
}

mFetchGeometry = ( !mFilterRect.isNull() ) || !( mRequest.flags() & QgsFeatureRequest::NoGeometry );
mFetchGeometry = ( !mFilterRect.isNull() ) ||
!( mRequest.flags() & QgsFeatureRequest::NoGeometry ) ||
( mSource->mOgrGeometryTypeFilter != wkbUnknown );

QgsAttributeList attrs = ( mRequest.flags() & QgsFeatureRequest::SubsetOfAttributes ) ? mRequest.subsetOfAttributes() : mSource->mFields.allAttributesList();

// ensure that all attributes required for expression filter are being fetched
@@ -661,6 +661,7 @@ static OGRwkbGeometryType ogrWkbGeometryTypeFromName( const QString &typeName )
else if ( typeName == QLatin1String( "MultiLineString25D" ) ) return wkbMultiLineString25D;
else if ( typeName == QLatin1String( "MultiPolygon25D" ) ) return wkbMultiPolygon25D;
else if ( typeName == QLatin1String( "GeometryCollection25D" ) ) return wkbGeometryCollection25D;
QgsDebugMsg( QStringLiteral( "unknown geometry type: %1" ).arg( typeName ) );
return wkbUnknown;
}

@@ -897,6 +897,32 @@ def _lessdigits(s):
self.assertEqual(_lessdigits(subSet_vl.extent().toString()), filtered_extent)
self.assertNotEqual(_lessdigits(subSet_vl.extent().toString()), unfiltered_extent)

def testRequestWithoutGeometryOnLayerMixedGeometry(self):
""" Test bugfix for https://issues.qgis.org/issues/19077 """

# Issue is more a generic one of the OGR provider, but easy to trigger with GPKG

tmpfile = os.path.join(self.basetestpath, 'testRequestWithoutGeometryOnLayerMixedGeometry.gpkg')
ds = ogr.GetDriverByName('GPKG').CreateDataSource(tmpfile)
lyr = ds.CreateLayer('test', geom_type=ogr.wkbUnknown, options=['SPATIAL_INDEX=NO'])
f = ogr.Feature(lyr.GetLayerDefn())
f.SetGeometry(ogr.CreateGeometryFromWkt('POINT(0 1)'))
lyr.CreateFeature(f)
f = ogr.Feature(lyr.GetLayerDefn())
f.SetGeometry(ogr.CreateGeometryFromWkt('LINESTRING(0 0,1 0)'))
lyr.CreateFeature(f)
f = ogr.Feature(lyr.GetLayerDefn())
f.SetGeometry(ogr.CreateGeometryFromWkt('LINESTRING(0 0,1 0)'))
lyr.CreateFeature(f)
f = None
ds = None

vl = QgsVectorLayer(u'{}'.format(tmpfile) + "|geometrytype=Point|layername=" + "test", 'test', u'ogr')
self.assertTrue(vl.isValid())
request = QgsFeatureRequest().setFlags(QgsFeatureRequest.NoGeometry)
features = [f for f in vl.getFeatures(request)]
self.assertEqual(len(features), 1)


if __name__ == '__main__':
unittest.main()

0 comments on commit ee06d52

Please sign in to comment.
You can’t perform that action at this time.