<div dir="auto"><div>Hi Andrea,</div><div dir="auto"><br></div><div dir="auto">Yes, thank you! I only tried it about 2 hours ago and the second example worked perfectly. </div><div dir="auto"><br></div><div dir="auto">I'm sure the first works, I could not create a valid Uri based on the documentation alone.</div><div dir="auto"><br></div><div dir="auto">Thank you for your help and checking in and apologies for the slow reply.</div><div dir="auto"><br></div><div dir="auto">Cheers</div><div dir="auto">Andrew</div><div dir="auto"><br><br><div class="gmail_quote" dir="auto"><div dir="ltr" class="gmail_attr">On Mon, 6 Jun 2022, 5:54 pm Andrea Giudiceandrea, <<a href="mailto:andreaerdna@libero.it">andreaerdna@libero.it</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Andrew,<br>
have you received my replay to your question? Have you managed to solve <br>
your problem?<br>
<br>
Best regards.<br>
<br>
Andrea<br>
<br>
<br>
-------- Messaggio Inoltrato --------<br>
Oggetto: Re: [Qgis-user] PyQGIS - OGCFeatureService / QgsVectorLayer "OAPIF"<br>
Data: Fri, 3 Jun 2022 12:12:14 +0200<br>
Mittente: Andrea Giudiceandrea <<a href="mailto:andreaerdna@libero.it" target="_blank" rel="noreferrer">andreaerdna@libero.it</a>><br>
A: <a href="mailto:qgis-user@lists.osgeo.org" target="_blank" rel="noreferrer">qgis-user@lists.osgeo.org</a><br>
<br>
> Andrew Hughes ahhughes at <a href="http://gmail.com" rel="noreferrer noreferrer" target="_blank">gmail.com</a><br>
> Thu Jun 2 21:37:03 PDT 2022<br>
<br>
> The following returns False, and has no features. Can someone please tell<br>
> me what I am doing wrong -  this seems so simple and really there is<br>
> nothing I can think of that is wrong with this, but doesn't work?<br>
> <br>
> QgsVectorLayer('<br>
> <a href="https://services.arcgis.com/quV9d0y7GW2PJkRl/arcgis/rest/services/rpt_spv_str_restr_prod_ogcfl/OGCFeatureServer" rel="noreferrer noreferrer" target="_blank">https://services.arcgis.com/quV9d0y7GW2PJkRl/arcgis/rest/services/rpt_spv_str_restr_prod_ogcfl/OGCFeatureServer</a>',<br>
> "layer_name", "OAPIF").isValid()<br>
<br>
Hi Andrew,<br>
a clue is in the "OGC API - Features data provider (oapif)" section of <br>
the QgsVectorLayer class detailed description at <br>
<a href="https://api.qgis.org/api/classQgsVectorLayer.html" rel="noreferrer noreferrer" target="_blank">https://api.qgis.org/api/classQgsVectorLayer.html</a><br>
<br>
Both the 'url' and the 'typename' parameters of the uri are mandatory <br>
for the OAPIF driver.<br>
<br>
So you need to construct an uri with at least both such parameters:<br>
e.g.<br>
<br>
QgsVectorLayer("url='<a href="https://services.arcgis.com/quV9d0y7GW2PJkRl/arcgis/rest/services/rpt_spv_str_restr_prod_ogcfl/OGCFeatureServer" rel="noreferrer noreferrer" target="_blank">https://services.arcgis.com/quV9d0y7GW2PJkRl/arcgis/rest/services/rpt_spv_str_restr_prod_ogcfl/OGCFeatureServer</a>' <br>
typename='0'","layer_name", "OAPIF").isValid()<br>
<br>
or<br>
<br>
service_uri = QgsDataSourceUri()<br>
service_uri.setParam("url","<a href="https://services.arcgis.com/quV9d0y7GW2PJkRl/arcgis/rest/services/rpt_spv_str_restr_prod_ogcfl/OGCFeatureServer" rel="noreferrer noreferrer" target="_blank">https://services.arcgis.com/quV9d0y7GW2PJkRl/arcgis/rest/services/rpt_spv_str_restr_prod_ogcfl/OGCFeatureServer</a>")<br>
service_uri.setParam("typename","0")<br>
QgsVectorLayer(service_uri.uri(),"layer_name", "OAPIF").isValid()<br>
<br>
Best regards.<br>
<br>
Andrea Giudiceandrea<br>
</blockquote></div></div></div>