From a5e46697c6b1dace829a81ffffd7287dcaf6dd36 Mon Sep 17 00:00:00 2001 From: Kahiu Date: Thu, 16 Nov 2023 18:55:50 +0300 Subject: [PATCH] Fix check pilot extent. --- src/cplus_plugin/gui/qgis_cplus_main.py | 6 ++++-- src/cplus_plugin/lib/extent_check.py | 18 +++++++++++++----- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/cplus_plugin/gui/qgis_cplus_main.py b/src/cplus_plugin/gui/qgis_cplus_main.py index dc6784f0d..8d4fd4e6a 100644 --- a/src/cplus_plugin/gui/qgis_cplus_main.py +++ b/src/cplus_plugin/gui/qgis_cplus_main.py @@ -375,7 +375,9 @@ def initialize_priority_layers(self): def on_ncs_pathways_reloaded(self): """Slot raised when NCS pathways have been reloaded in the view.""" - within_pilot_area = extent_within_pilot(self.extent_box.outputExtent()) + within_pilot_area = extent_within_pilot( + self.extent_box.outputExtent(), self.extent_box.outputCrs() + ) self.implementation_model_widget.enable_default_items(within_pilot_area) def on_extent_changed(self, new_extent: QgsRectangle): @@ -384,7 +386,7 @@ def on_extent_changed(self, new_extent: QgsRectangle): Used to enable/disable default model items if they are within or outside the pilot AOI. """ - within_pilot_area = extent_within_pilot(new_extent) + within_pilot_area = extent_within_pilot(new_extent, self.extent_box.outputCrs()) if not within_pilot_area: msg = tr( diff --git a/src/cplus_plugin/lib/extent_check.py b/src/cplus_plugin/lib/extent_check.py index c81874bc3..58d28db25 100644 --- a/src/cplus_plugin/lib/extent_check.py +++ b/src/cplus_plugin/lib/extent_check.py @@ -13,27 +13,35 @@ from ..definitions.defaults import DEFAULT_CRS_ID, PILOT_AREA_EXTENT -def extent_within_pilot(new_extent: QgsRectangle) -> bool: +def extent_within_pilot( + new_extent: QgsRectangle, source_crs: QgsCoordinateReferenceSystem = None +) -> bool: """Checks if the extent is within the pilot area. :param new_extent: Extent to check if within the pilot area. :type new_extent: QgsRectangle + :param source_crs: Source coordinate reference system, if not specified then + it will default to the project reference system. It reproject to WGS84 + which is what is used for the pilot extent. + :type source_crs: QgsCoordinateReferenceSystem + :returns: True if the current map canvas extent is within the pilot area, else False. :rtype: bool """ + if source_crs is None: + source_crs = QgsProject.instance().crs() + extent_list = PILOT_AREA_EXTENT["coordinates"] pilot_extent = QgsRectangle( extent_list[0], extent_list[2], extent_list[1], extent_list[3] ) default_crs = QgsCoordinateReferenceSystem.fromEpsgId(DEFAULT_CRS_ID) - project_crs = QgsProject.instance().crs() - - if default_crs != project_crs: + if default_crs != source_crs: coordinate_xform = QgsCoordinateTransform( - default_crs, project_crs, QgsProject.instance() + source_crs, default_crs, QgsProject.instance() ) new_extent = coordinate_xform.transformBoundingBox(new_extent)