[QGIS-Developer] FeatureIterator is constructed but not iterated when creating a custom QgsVectorDataProvider in Python

Alessandro Pasotti apasotti at gmail.com
Fri Nov 20 05:30:16 PST 2020


On Fri, Nov 20, 2020 at 2:22 PM Mats Taraldsvik
<mats.taraldsvik at gmail.com> wrote:
>
> Hi,
>
> I'm trying to create/prototype a custom QgsVectorDataProvider in Python to retrieve data from a HTTP REST API.
>
> When testing, I do the following to register my provider:
>
> from qgis.core import QgsProviderRegistry, QgsProviderMetadata
> from provider import MyProvider
> registry = QgsProviderRegistry.instance()
> metadata = QgsProviderMetadata(MyProvider.providerKey(), MyProvider.description(), MyProvider.createProvider)
> registry.registerProvider(metadata)
> layer = QgsVectorLayer(<my-url>, 'Test myprovider', 'myprovider-plugin')
> QgsProject.instance().addMapLayer(layer)
> This seems to initialize the provider, although it stops after the constructor of MyFeatureIterator(QgsAbstractFeatureIterator) is run.
> For this test, data is retrieved from the REST API in the constructor, and I can see in the logs that the data is retrieved.
>
> I expected it to start iterating objects, but the next message in the log is prepareSimplification (I have added a log message to every class method to watch progress in the logs), then nothing.
>
> I even installed qgis-dev and watched the logs using Microsoft's DebugViewer, but I could not see any relevant information.
>
> Could someone please help me or tell me where to look to solve this issue and start iterating with nextFeature/fetchFeature? Regards,


AFAIK there is only one example I wrote for testing purposes ages ago:
https://github.com/qgis/QGIS/blob/master/tests/src/python/provider_python.py

I'm not sure it will be useful but it's a start.

Kind regards.

-- 
Alessandro Pasotti
QCooperative:  www.qcooperative.net
ItOpen:   www.itopen.it


More information about the QGIS-Developer mailing list