You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A change of the QgsMapCanvas CRS causes a transformation of the canvas extent into coordinate values of the new CRS.
When this recalculation is finishedm the extentsChanged signal is emitted.
At the time of this signal, the CRS is still the old one. Slots that are connected to this signal which require the CRS information as well, may therefore use inconsistent data, as the canvas CRS does not fit to the values of the extent coordinates.
Steps to reproduce the issue
The following test changes a map canvas CRS from EPSG:32633 to EPGS:4326.
The recalculated extent is validated against the boundaries of the map canvas CRS. The extent coordinates should be inside the CRS boundaries, but this fails because the canvas CRS is still set on EPSG:32633, while the coordinate values are already in EPSG:4326.
Output:
Set CRS to <QgsCoordinateReferenceSystem: EPSG:4326>
WGS 84 / UTM zone 33N : 13.2958240245312247,52.4763378599360735 : 13.3992241580016476,52.5538069254515321
Traceback (most recent call last):
File "F:\Repositories\enmap-box\tests\src\issues\test_qgis_issue_mapcrs.py", line 33, in onExtentsChanged
self.assertTrue(bounds.contains(extent))
Code:
fromqgis.coreimportQgsCoordinateReferenceSystem, QgsRectangle, QgsCoordinateTransformfromqgis.guiimportQgsMapCanvasfromqgis.testingimportTestCase, start_appapp=start_app()
classMapCRSTest(TestCase):
deftest_mapCRS(self):
crsLatLon=QgsCoordinateReferenceSystem('EPSG:4326')
canvas=QgsMapCanvas()
canvas.setDestinationCrs(QgsCoordinateReferenceSystem('EPSG:32633'))
extent=QgsRectangle(384418.42293523817,
5817479.542521443,
391319.6968762298,
5821746.336751187)
canvas.setExtent(extent)
defonExtentsChanged(*args):
crs=canvas.mapSettings().destinationCrs()
extent=canvas.extent()
print(f' {crs.description()} : {extent.toString()}')
# convert boundary coordinate of the MapCanvas CRS from LatLon to MapCanvas CRS valuestrans=QgsCoordinateTransform()
trans.setSourceCrs(crsLatLon)
trans.setDestinationCrs(crs)
bounds=trans.transform(crs.bounds())
# the MapCanvas extent should still be within valid bound coordinatesself.assertTrue(bounds.contains(extent))
canvas.extentsChanged.connect(onExtentsChanged)
print(f'Set CRS to {crsLatLon}')
canvas.setDestinationCrs(crsLatLon)
What is the bug or the crash?
A change of the QgsMapCanvas CRS causes a transformation of the canvas extent into coordinate values of the new CRS.
When this recalculation is finishedm the
extentsChanged
signal is emitted.At the time of this signal, the CRS is still the old one. Slots that are connected to this signal which require the CRS information as well, may therefore use inconsistent data, as the canvas CRS does not fit to the values of the extent coordinates.
Steps to reproduce the issue
The following test changes a map canvas CRS from EPSG:32633 to EPGS:4326.
The recalculated extent is validated against the boundaries of the map canvas CRS. The extent coordinates should be inside the CRS boundaries, but this fails because the canvas CRS is still set on EPSG:32633, while the coordinate values are already in EPSG:4326.
Output:
Code:
Versions
QGIS 3.29 master c065313595 (windows 11)
Supported QGIS version
New profile
Additional context
No response
The text was updated successfully, but these errors were encountered: