[Qgis-developer] Problem using vector data provider in python

Chris Crook ccrook at linz.govt.nz
Tue Dec 14 15:18:11 EST 2010


Hi All

I'm wondering if it is possible to use a QgsVectorDataProvider independently from a map layer in Python.  For example, I'd like to open a GML file and read features, etc from it without creating a map layer.

I can get as far as 

p=QgsProviderRegistry.instance().getProvider("ogr","myfile.gml")

But what I get back is QgsDataProvider.

<qgis.core.QgsDataProvider object at 0x099BE6F0>

So all the QgsVectorDataProvider methods don't seem to be available.  For example

>>> p.extent()
<qgis.core.QgsRectangle object at 0x09A4D810>
>>> p.featureCount()
Traceback (most recent call last):
  File "<input>", line 1, in <module>
AttributeError: 'QgsDataProvider' object has no attribute 'featureCount'

Is there any way to cast this to a QgsVectorDataProvider in Python (as happens in gsVectorLayer::setDataProvider)?  Or is there another better way to access the data provider?

Thanks
Chris
______________________________________________________________________________________________________

This message contains information, which is confidential and may be subject to legal privilege. 
If you are not the intended recipient, you must not peruse, use, disseminate, distribute or copy this message.
If you have received this message in error, please notify us immediately (Phone 0800 665 463 or info at linz.govt.nz) and destroy the original message.
LINZ accepts no responsibility for changes to this email, or for any attachments, after its transmission from LINZ.

Thank you.
______________________________________________________________________________________________________


More information about the Qgis-developer mailing list