[Qgis-developer] [Python] QgsFeatureIterator for geometryless PostgreSQL-Layer

Martin Dobias wonder.sk at gmail.com
Thu Apr 11 13:30:57 PDT 2013


Hi Juergen

On Tue, Apr 9, 2013 at 6:10 PM, Jürgen E. <jef at norbit.de> wrote:
>> if I do
>> feat = QgsFeature()
>> iter = myLayer.getFeatures(QgsFeatureRequest().setFilterFid(myFid))
>> iter.nextFeature(feat)
>> returns False and I get a message in the PostgreSQL message tab stating
>> "Trying to fetch geometry on layer without geometry."
>>
>> Can anybody confirm?
>> Do I miss anything or is this a bug?
>
> You request geometry (by not saying you don't want any) - and get refused
> because there's none.
>
> myLayer.getFeatures(QgsFeatureRequest().setFilterFid(myFid).setFlags( QgsFeatureRequest.NoGeometry ) )
>
> should work.  Not really a bug, but inconvienent.

I have a feeling that we should call that a bug: the NoGeometry flag
tells that it is not necessary to fetch geometry... so even if the
flag is not set, the feature should be fetched.

Btw. there is one slightly related thing:
"enableGeometrylessFeatures(bool)" function of QgsVectorDataProvider.
It works only with OGR provider and I believe there is not
justification for keeping it around in v2.0. If I remember correctly
we have added it long time ago when all geometryless features were
automatically rejected because other parts of QGIS were not expecting
QgsFeature with NULL geometry - however the situation has changed in
meanwhile. I will remove it.

Martin


More information about the Qgis-developer mailing list