Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding ArcGIS feature Service Layer with Python doesn't work in QGIS 3.28 #53736

Closed
1 of 2 tasks
SimonSAMPERE opened this issue Jul 6, 2023 · 3 comments · Fixed by #54806
Closed
1 of 2 tasks

Adding ArcGIS feature Service Layer with Python doesn't work in QGIS 3.28 #53736

SimonSAMPERE opened this issue Jul 6, 2023 · 3 comments · Fixed by #54806
Assignees
Labels
ArcGIS feature server data provider Bug Either a bug report, or a bug fix. Let's hope for the latter! Regression Something which used to work, but doesn't anymore

Comments

@SimonSAMPERE
Copy link

What is the bug or the crash?

Hello,
I would like to start by thanking you for all the work you have been doing for so many years.

I am the developer of a Python plugin that allows the user to add ESRI Feature Service layers.

This feature works perfectly in QGIS 3.22. However, in QGIS 3.28 (I tested in QGIS 3.28.4 and 3.28.8) the QgsVectorLayers I generate from EFS layers are no longer valid. However, it is still possible to add these layers manually in QGIS 3.28 from the "ArcGIS Server REST" data source manager.

Steps to reproduce the issue

Here's the URL of an open service with which you can test: https://carto.isogeo.net/server/rest/services/scan_services_1/EMS_EFS_WMS_WFS/FeatureServer/

Here's an example of Python code that works in QGIS 3.22 but not in QGIS 3.28:

# -*- coding: utf-8 -*-
from qgis.core import QgsDataSourceUri, QgsProject, QgsVectorLayer
from owslib.wfs import WebFeatureService

wfs_url_base = "crs='EPSG:2154' filter='' url='https://carto.isogeo.net/server/rest/services/scan_services_1/EMS_EFS_WMS_WFS/FeatureServer/2' table='' sql=''"
lyr = QgsVectorLayer(wfs_url_base, baseName="efs_arcgisserver", providerLib="arcgisfeatureserver")
QgsProject.instance().addMapLayer(lyr)

Running this code in QGIS 3.22 add a valid layer to the canvas. However, running it in QGIS 3.28 add an invalid layer :
image

Versions

<style type="text/css"> p, li { white-space: pre-wrap; } </style>
Version de QGIS 3.28.8-Firenze Révision du code 5ac4527
Version de Qt 5.15.3
Version de Python 3.9.5
Version de GDAL/OGR 3.7.0
Version de Proj 9.2.1
Version de la base de données du registre EPSG v10.088 (2023-05-13)
Version de GEOS 3.11.2-CAPI-1.17.2
Version de SQLite 3.41.1
Version de PDAL 2.5.3
Version du client PostgreSQL unknown
Version de SpatiaLite 5.0.1
Version de QWT 6.1.6
Version de QScintilla2 2.13.1
Version de l'OS Windows 10 Version 2009
       
Extensions Python actives
isogeo-plugin-qgis 3.4.1-beta
plugin_reloader 0.9.3
quick_map_services 0.19.33
db_manager 0.1.20
grassprovider 2.12.99
MetaSearch 0.3.6
processing 2.12.99
sagaprovider 2.12.99
Version de QGIS 3.28.8-Firenze Révision du code [5ac4527](https://github.com/qgis/QGIS/commit/5ac45272b5) Version de Qt 5.15.3 Version de Python 3.9.5 Version de GDAL/OGR 3.7.0 Version de Proj 9.2.1 Version de la base de données du registre EPSG v10.088 (2023-05-13) Version de GEOS 3.11.2-CAPI-1.17.2 Version de SQLite 3.41.1 Version de PDAL 2.5.3 Version du client PostgreSQL unknown Version de SpatiaLite 5.0.1 Version de QWT 6.1.6 Version de QScintilla2 2.13.1 Version de l'OS Windows 10 Version 2009

Extensions Python actives
isogeo-plugin-qgis
3.4.1-beta
plugin_reloader
0.9.3
quick_map_services
0.19.33
db_manager
0.1.20
grassprovider
2.12.99
MetaSearch
0.3.6
processing
2.12.99
sagaprovider
2.12.99

Supported QGIS version

  • I'm running a supported QGIS version according to the roadmap.

New profile

Additional context

This bug may be linked to #51409

@SimonSAMPERE SimonSAMPERE added the Bug Either a bug report, or a bug fix. Let's hope for the latter! label Jul 6, 2023
@agiudiceandrea agiudiceandrea added ArcGIS feature server data provider Regression Something which used to work, but doesn't anymore labels Jul 7, 2023
@SimonSAMPERE
Copy link
Author

It seems that removing filter='', table='' and sql='' from the wfs_url_base variable is enough to correct the problem.

The following code therefore works in QGIS 3.28 and QGIS 3.22:

# -*- coding: utf-8 -*-
from qgis.core import QgsDataSourceUri, QgsProject, QgsVectorLayer
from owslib.wfs import WebFeatureService

wfs_url_base = "crs='EPSG:2154' url='{service_url}/{layer_id}'"
lyr = QgsVectorLayer(wfs_url_base, baseName="efs_arcgisserver", providerLib="arcgisfeatureserver")
QgsProject.instance().addMapLayer(lyr)

However, I'm not aware of any documentation indicating this. If such documentation exists, I'd be grateful if someone could point it out to me. If not, perhaps it's not a bug but a need for documentation.

@nyalldawson
Copy link
Collaborator

@SimonSAMPERE

there's a bit happening here!

First, the issue is caused by the sql='' part of your URI. This was also problematic, but didn't cause any visible issues because in 3.22 the sql was ignored by the arcgis rest provider. In 3.28 the sql is respected and past onto the rest api -- so it was incorrectly passing on a '' string as the filter, which was rejected by the ArcGIS REST service.

The correct uri should either exclude the sql='' part entirely, or just specify sql= without any following string.

Special handling has been added in #54806 to treat sql='' as an empty sql string, which also fixes this issue.

@SimonSAMPERE
Copy link
Author

Thanks for the explanation @nyalldawson

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ArcGIS feature server data provider Bug Either a bug report, or a bug fix. Let's hope for the latter! Regression Something which used to work, but doesn't anymore
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants