Skip to content

Commit

Permalink
Merge pull request #292 from gkahiu/fix_aoi_check
Browse files Browse the repository at this point in the history
Fix Pilot Extent Check
  • Loading branch information
Samweli authored Nov 17, 2023
2 parents 64cd4da + a5e4669 commit fadf146
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
6 changes: 4 additions & 2 deletions src/cplus_plugin/gui/qgis_cplus_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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(
Expand Down
18 changes: 13 additions & 5 deletions src/cplus_plugin/lib/extent_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit fadf146

Please sign in to comment.