From 3c1ec24f11f437f28fb8077320765e17360e0f1f Mon Sep 17 00:00:00 2001 From: Josep <> Date: Thu, 22 Jun 2023 19:13:09 +0200 Subject: [PATCH] define structure with utils submodule --- algs/buildings2sewertAlgorithm.py | 5 +++-- algs/catchmentAreasAlgorithm.py | 2 +- algs/utils/check_extent.py | 15 +++++++++++++ .../z_sampling.py} | 22 +------------------ 4 files changed, 20 insertions(+), 24 deletions(-) create mode 100644 algs/utils/check_extent.py rename algs/{common_functions.py => utils/z_sampling.py} (69%) diff --git a/algs/buildings2sewertAlgorithm.py b/algs/buildings2sewertAlgorithm.py index 07fe642..61a883d 100644 --- a/algs/buildings2sewertAlgorithm.py +++ b/algs/buildings2sewertAlgorithm.py @@ -36,7 +36,8 @@ import qgis.utils import processing import os -from .common_functions import checkExtent, z_sampling +from .utils.check_extent import check_extent +from .utils.z_sampling import z_sampling pluginPath = os.path.dirname(__file__) @@ -153,7 +154,7 @@ def processAlgorithm(self, parameters, context, feedback): nodes_o = self.parameterAsVectorLayer(parameters, 'MANHOLES', context) mde = self.parameterAsRasterLayer(parameters, 'DEM', context) - if not checkExtent(parcels_o, mde) or not checkExtent(nodes_o, mde): + if not check_extent(parcels_o, mde) or not check_extent(nodes_o, mde): feedback.reportError("Some of the layers are out of DEM") return {} diff --git a/algs/catchmentAreasAlgorithm.py b/algs/catchmentAreasAlgorithm.py index 0cd35ff..6024672 100644 --- a/algs/catchmentAreasAlgorithm.py +++ b/algs/catchmentAreasAlgorithm.py @@ -36,7 +36,7 @@ import qgis.utils import processing import os -from .common_functions import checkExtent, z_sampling +from .utils.z_sampling import z_sampling pluginPath = os.path.split(os.path.split(os.path.dirname(__file__))[0])[0] diff --git a/algs/utils/check_extent.py b/algs/utils/check_extent.py new file mode 100644 index 0000000..64e9e1f --- /dev/null +++ b/algs/utils/check_extent.py @@ -0,0 +1,15 @@ +def check_extent(layer, background): + xMaxL = layer.extent().xMaximum() + xMinL = layer.extent().xMinimum() + yMaxL = layer.extent().yMaximum() + yMinL = layer.extent().yMinimum() + + xMaxB = background.extent().xMaximum() + xMinB = background.extent().xMinimum() + yMaxB = background.extent().yMaximum() + yMinB = background.extent().yMinimum() + + if xMaxL > xMaxB or xMinL < xMinB or yMaxL > yMaxB or yMinL < yMinB: + return False + else: + return True \ No newline at end of file diff --git a/algs/common_functions.py b/algs/utils/z_sampling.py similarity index 69% rename from algs/common_functions.py rename to algs/utils/z_sampling.py index e448a95..4fae8f6 100644 --- a/algs/common_functions.py +++ b/algs/utils/z_sampling.py @@ -1,25 +1,5 @@ from qgis.PyQt.QtCore import * -from PyQt5.QtGui import QIcon from qgis.core import * -import qgis.utils -import processing - -def checkExtent(layer, background): - xMaxL = layer.extent().xMaximum() - xMinL = layer.extent().xMinimum() - yMaxL = layer.extent().yMaximum() - yMinL = layer.extent().yMinimum() - - xMaxB = background.extent().xMaximum() - xMinB = background.extent().xMinimum() - yMaxB = background.extent().yMaximum() - yMinB = background.extent().yMinimum() - - if xMaxL > xMaxB or xMinL < xMinB or yMaxL > yMaxB or yMinL < yMinB: - return False - else: - return True - def z_sampling(points, mde, feedback): #set the progressbar @@ -58,4 +38,4 @@ def z_sampling(points, mde, feedback): #update progressbar feedback.setProgress(int(current * total)) - return mem_layer + return mem_layer \ No newline at end of file