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
_______________________________________________
Qgis-user mailing list
[email protected]
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user

Reply via email to