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

Andrea Giudiceandrea andreaerdna at libero.it
Fri Jun 3 03:12:14 PDT 2022


> 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


More information about the Qgis-user mailing list