qgis / QGIS

QGIS is a free, open source, cross platform (lin/win/mac) geographical information system (GIS)
https://qgis.org
GNU General Public License v2.0
10.49k stars 2.99k forks source link

Display Vector Tile layers based on Vector Tile source CRS (EPSG:28992) #54366

Open kad-rothul opened 1 year ago

kad-rothul commented 1 year ago

Feature description

Vector tiles could be displayed in the CRS in which they tiles are served from source. Specifically for EPSG:28992, if a vector tile source (e.g. OGC:API - Tiles) serves tiles in EPSG:28992, it would be desired to display them in QGIS, so set the layer CRS correct. As of now, for each vector tile source, the CRS is set to EPSG:3857 by default.

Additional context

QGIS currently does not support adding a vector tile layer in a CRS different to EPSG:3857. The vector tile data source loader always sets the CRS to EPSG:3857, even when the provided vector tile source doesn't serve vector tiles in this projection, as can be seen in the code: setCrs( QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:3857" ) ) );

For a vector tile source which only serves tiles in EPSG:28992, it is not possible to display the tiles correctly as they won't match with other layers in EPSG:28992. This makes it impractical to display the vector tile layer in QGIS.

It would be ideal that QGIS recognizes the CRS in which the vector tiles are served, which can usually be derived from either the URL or the source. If this is not directly clear, it could also be an option to allow the user to select a specific CRS for a vector tile layer

DelazJ commented 1 year ago

QGIS currently does not support adding a vector tile layer in a CRS different to EPSG:3857

@kad-rothul Can you provide details on your QGIS version? Is your request not addressed in https://github.com/qgis/QGIS/pull/47617 (or is it something else)?

kad-rothul commented 1 year ago

I am using QGIS version 3.30.3-'s-Hertogenbosch and GDAL/OGR version 3.6.2 I will examine if the problem is the same, but I assume it is something else.

kad-rothul commented 1 year ago

image Although the url that is provided serves the vector tiles in EPSG:28992 (NetherlandsRDNewQuad), it still tells that the CRS is EPSG:3857. This is most likely (but not 100% sure) caused by the following in the code: https://github.com/qgis/QGIS/blob/366686e1b6254e12688b7665d63f3363fcf7e17e/src/core/vectortile/qgsvectortilelayer.cpp#L78C7-L78C7

nyalldawson commented 1 year ago

@kad-rothul that's just a default -- it's overridden here: https://github.com/qgis/QGIS/blob/366686e1b6254e12688b7665d63f3363fcf7e17e/src/core/vectortile/qgsvectortilelayer.cpp#L113

kad-rothul commented 1 year ago

Ah I see, this would imply it should be possible to correctly display vector tiles in a CRS different from EPSG:3857. When adding a VT layer, it does not seem to recognize the correct CRS from the tileMatrixSet of the ogc:api tiles url. In my example (https://github.com/qgis/QGIS/issues/54366#issuecomment-1695342740), the url does contain a reference to the CRS, is this enough? Or do I need to add it manually in the uri when creating the QgsVectorTileLayer? And if so, how should I do this?

kad-rothul commented 1 year ago

When creating the QgsVectorTileLayer, I add the crs manually in my python script as follows: tileLayer = QgsVectorTileLayer(uri, title) tileLayer.setCrs(srs=QgsCoordinateReferenceSystem("EPSG:28992")) This seems to work: The correct crs is displayed in the Information tab of the Vector Layer under Coordinate Reference System. However, I am not able to see the layer on the map, so it is still not working properly.

EDIT: I am able to see the data (by zooming to layer and adjusting the scale), but not in the right location. Simply put, I add a (background) layer in EPSG:28992 and on top I put the vector tile layer. They should overlap, but are displayed in a different location

kad-rothul commented 1 year ago

More information: Although the crs is now correctly set for the vector tile layer, the location where the tiles are placed is not correct. The center of the VT layer should be around [155003.77, 465200.20] for EPSG:28992. But in QGIS, I find the center is at [0,0]. Somehow, the location of the VT layer should be transformed to the new crs as well I presume. I am not really sure how to do this, can somebody help with this issue? I presume it has something to do with a transformation or extent which is not done properly or setting a crs for the layer, while the tiles are not changed...

github-actions[bot] commented 1 year ago

The QGIS project highly values your report and would love to see it addressed. However, this issue has been left in feedback mode for the last 14 days and is being automatically marked as "stale". If you would like to continue with this issue, please provide any missing information or answer any open questions. If you could resolve the issue yourself meanwhile, please leave a note for future readers with the same problem and close the issue. In case you should have any uncertainty, please leave a comment and we will be happy to help you proceed with this issue. If there is no further activity on this issue, it will be closed in a week.