[Qgis-user] PyQGIS - OGCFeatureService / QgsVectorLayer "OAPIF"

Andrew Hughes ahhughes at gmail.com
Mon Jun 6 02:09:54 PDT 2022


Hi Andrea,

Yes, thank you! I only tried it about 2 hours ago and the second example
worked perfectly.

I'm sure the first works, I could not create a valid Uri based on the
documentation alone.

Thank you for your help and checking in and apologies for the slow reply.

Cheers
Andrew


On Mon, 6 Jun 2022, 5:54 pm Andrea Giudiceandrea, <andreaerdna at libero.it>
wrote:

> Hi Andrew,
> have you received my replay to your question? Have you managed to solve
> your problem?
>
> Best regards.
>
> Andrea
>
>
> -------- Messaggio Inoltrato --------
> Oggetto: Re: [Qgis-user] PyQGIS - OGCFeatureService / QgsVectorLayer
> "OAPIF"
> Data: Fri, 3 Jun 2022 12:12:14 +0200
> Mittente: Andrea Giudiceandrea <andreaerdna at libero.it>
> A: qgis-user at lists.osgeo.org
>
> > Andrew Hughes ahhughes at gmail.com
> > Thu Jun 2 21:37:03 PDT 2022
>
> > The following returns False, and has no features. Can someone please tell
> > me what I am doing wrong -  this seems so simple and really there is
> > nothing I can think of that is wrong with this, but doesn't work?
> >
> > QgsVectorLayer('
> >
> https://services.arcgis.com/quV9d0y7GW2PJkRl/arcgis/rest/services/rpt_spv_str_restr_prod_ogcfl/OGCFeatureServer
> ',
> > "layer_name", "OAPIF").isValid()
>
> Hi Andrew,
> a clue is in the "OGC API - Features data provider (oapif)" section of
> the QgsVectorLayer class detailed description at
> https://api.qgis.org/api/classQgsVectorLayer.html
>
> Both the 'url' and the 'typename' parameters of the uri are mandatory
> for the OAPIF driver.
>
> So you need to construct an uri with at least both such parameters:
> e.g.
>
> QgsVectorLayer("url='
> https://services.arcgis.com/quV9d0y7GW2PJkRl/arcgis/rest/services/rpt_spv_str_restr_prod_ogcfl/OGCFeatureServer'
>
> typename='0'","layer_name", "OAPIF").isValid()
>
> or
>
> service_uri = QgsDataSourceUri()
> service_uri.setParam("url","
> https://services.arcgis.com/quV9d0y7GW2PJkRl/arcgis/rest/services/rpt_spv_str_restr_prod_ogcfl/OGCFeatureServer
> ")
> service_uri.setParam("typename","0")
> QgsVectorLayer(service_uri.uri(),"layer_name", "OAPIF").isValid()
>
> Best regards.
>
> Andrea Giudiceandrea
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20220606/dc5f07fb/attachment.htm>


More information about the Qgis-user mailing list