diff --git a/rasterizor/metadata.txt b/rasterizor/metadata.txt index 1f39c21..01c9f55 100644 --- a/rasterizor/metadata.txt +++ b/rasterizor/metadata.txt @@ -20,6 +20,7 @@ changelog= 0.3.1 - Added a new symbology for comparison - Allowed only rasters layers for comparison + - Added a CRS selector 0.3 - Added the difference between rasters - Updated style code diff --git a/rasterizor/rasterizor.py b/rasterizor/rasterizor.py index 4318aa1..986083b 100644 --- a/rasterizor/rasterizor.py +++ b/rasterizor/rasterizor.py @@ -23,6 +23,7 @@ """ import os import numpy as np +from qgis._gui import QgsProjectionSelectionWidget from qgis.core import * from qgis.utils import iface from qgis.PyQt.QtCore import Qt, QSettings, QTranslator, QCoreApplication @@ -37,6 +38,7 @@ QDialogButtonBox, QMessageBox ) + from qgis._core import (QgsGradientColorRamp, QgsGradientStop) # from rast_functions import outTable # Initialize Qt resources from file resources.py @@ -89,8 +91,10 @@ def __init__(self, iface): # Set the CRS to the widget self.crs = QgsCoordinateReferenceSystem(QgsProject.instance().crs().authid()) - self.dlg.crsselector.setCrs(self.crs) - self.dlg.crsselector_2.setCrs(self.crs) + self.projectionSelector = QgsProjectionSelectionWidget() + # self.dlg.crsselector.setCrs(self.crs) + # self.dlg.crsselector_2.setCrs(self.crs) + # self.projectionSelector.selectCrs() # Run button self.dlg.runButton.clicked.connect(self.run) @@ -219,9 +223,55 @@ def closeDialog(self): def open(self): """Shows the dialog""" self.crs = QgsCoordinateReferenceSystem(QgsProject.instance().crs().authid()) - self.dlg.crsselector.setCrs(self.crs) - self.dlg.crsselector_2.setCrs(self.crs) - self.dlg.show() + while True: + # Check if it is metric + if not self.crs.isGeographic(): + self.dlg.crsselector.setCrs(self.crs) + self.dlg.crsselector_2.setCrs(self.crs) + self.dlg.show() + break # Exit the loop + else: + # Open the CRS selector + self.projectionSelector.selectCrs() + + # Check if the user selected a projected CRS + if not self.projectionSelector.crs().isGeographic(): + QgsProject.instance().setCrs(self.projectionSelector.crs()) + self.crs = self.projectionSelector.crs() + self.dlg.crsselector.setCrs(self.crs) + self.dlg.crsselector_2.setCrs(self.crs) + self.dlg.show() + break # Exit the loop + else: + # Show a warning message + QMessageBox.warning( + self.dlg, + "CRS error", + "Select a Projected Coordinate Reference System!" + ) + + # # Check if it is metric + # if not self.crs.isGeographic(): + # self.dlg.crsselector.setCrs(self.crs) + # self.dlg.crsselector_2.setCrs(self.crs) + # self.dlg.show() + # else: + # # Open the CRS selector + # self.projectionSelector.selectCrs() + # # Check again if the user selected a geographic crs + # if self.projectionSelector.crs().isGeographic(): + # QMessageBox.warning( + # self.dlg, + # "CRS error", + # "Select a Projected Coordinate Reference System!" + # ) + # else: + # QgsProject.instance().setCrs(self.projectionSelector.crs()) + # self.crs = self.projectionSelector.crs() + # self.dlg.crsselector.setCrs(self.crs) + # self.dlg.crsselector_2.setCrs(self.crs) + # self.dlg.show() + # Adapted function from dlg_sampling_xyz_.py def lidar_to_raster(self, lidar_file, raster_file, nodata_value=-9999):