From fa8a4ecf2bf4d64c79f78f961daee086642b98c7 Mon Sep 17 00:00:00 2001 From: jeremy Date: Wed, 6 Mar 2024 17:39:06 +0100 Subject: [PATCH] Fix issue #63 UMEP-Processing --- functions/URock/DataUtil.py | 9 ++-- functions/URock/InitWindField.py | 71 +++++++++----------------------- metadata.txt | 3 +- 3 files changed, 27 insertions(+), 56 deletions(-) diff --git a/functions/URock/DataUtil.py b/functions/URock/DataUtil.py index 596c28c..41b7f52 100644 --- a/functions/URock/DataUtil.py +++ b/functions/URock/DataUtil.py @@ -184,9 +184,12 @@ def createIndex(tableName, fieldName, isSpatial): spatialKeyWord = "" if isSpatial: spatialKeyWord = " SPATIAL " - query = "CREATE {0} INDEX IF NOT EXISTS id_{1}_{2} ON {2}({1});".format(spatialKeyWord, - fieldName, - tableName) + if type(fieldName) == type([]): + query = f"""CREATE {spatialKeyWord} INDEX IF NOT EXISTS id_{"_".join(fieldName)}_{tableName} + ON {tableName}({",".join(fieldName)});""" + else: + query = f"""CREATE {spatialKeyWord} INDEX IF NOT EXISTS id_{fieldName}_{tableName} + ON {tableName}({fieldName});""" return query def radToDeg(data, origin = 90, direction = "CLOCKWISE"): diff --git a/functions/URock/InitWindField.py b/functions/URock/InitWindField.py index 2412fb7..15becd0 100644 --- a/functions/URock/InitWindField.py +++ b/functions/URock/InitWindField.py @@ -2163,34 +2163,25 @@ def manageSuperimposition(cursor, prefix = PREFIX_NAME) # Add backward zone points to the final table (replace points if exist) - cursor.execute(""" - {0}{1}{2}{3} - DROP TABLE IF EXISTS {4}; - CREATE TABLE {4} + cursor.execute(f""" + {DataUtil.createIndex(tableName=upstreamBackPrioritiesTempoTable, + fieldName=[ID_POINT, ID_POINT_Z], + isSpatial=False)} + {DataUtil.createIndex(tableName=tempoPrioritiesWeightedAll, + fieldName=[ID_POINT, ID_POINT_Z], + isSpatial=False)} + DROP TABLE IF EXISTS {tempoPrioritiesWeightedAllPlusBack}; + CREATE TABLE {tempoPrioritiesWeightedAllPlusBack} AS SELECT a.* - FROM {5} AS a LEFT JOIN {6} AS b - ON a.{7} = b.{7} AND a.{8} = b.{8} - WHERE b.{7} IS NOT NULL AND b.{8} IS NOT NULL + FROM {upstreamBackPrioritiesTempoTable} AS a LEFT JOIN {tempoPrioritiesWeightedAll} AS b + ON a.{ID_POINT} = b.{ID_POINT} AND a.{ID_POINT_Z} = b.{ID_POINT_Z} + WHERE b.{ID_POINT} IS NOT NULL AND b.{ID_POINT_Z} IS NOT NULL UNION ALL SELECT a.* - FROM {6} AS a LEFT JOIN {5} AS b - ON a.{7} = b.{7} AND a.{8} = b.{8} - WHERE b.{7} IS NULL AND b.{8} IS NULL - """.format( DataUtil.createIndex(tableName=upstreamBackPrioritiesTempoTable, - fieldName=ID_POINT, - isSpatial=False), - DataUtil.createIndex(tableName=upstreamBackPrioritiesTempoTable, - fieldName=ID_POINT_Z, - isSpatial=False), - DataUtil.createIndex(tableName=tempoPrioritiesWeightedAll, - fieldName=ID_POINT, - isSpatial=False), - DataUtil.createIndex(tableName=tempoPrioritiesWeightedAll, - fieldName=ID_POINT_Z, - isSpatial=False), - tempoPrioritiesWeightedAllPlusBack, upstreamBackPrioritiesTempoTable, - tempoPrioritiesWeightedAll , ID_POINT, - ID_POINT_Z)) + FROM {tempoPrioritiesWeightedAll} AS a LEFT JOIN {upstreamBackPrioritiesTempoTable} AS b + ON a.{ID_POINT} = b.{ID_POINT} AND a.{ID_POINT_Z} = b.{ID_POINT_Z} + WHERE b.{ID_POINT} IS NULL AND b.{ID_POINT_Z} IS NULL + """) if feedback: feedback.setProgressText('Deals with vegetation zones superimposition') @@ -2201,10 +2192,7 @@ def manageSuperimposition(cursor, # MANAGE THE DOWNSTREAM WEIGHTING ZONES # Weight the wind speeds factors by the downstream weights (vegetation) cursor.execute(""" - {12}; - {13}; - {14}; - {15}; + {12} DROP TABLE IF EXISTS {10}; CREATE TABLE {10} AS SELECT a.{2}, a.{3}, COALESCE(b.{4}, NULL) AS {4}, @@ -2221,25 +2209,13 @@ def manageSuperimposition(cursor, U , V, W , REF_HEIGHT_FIELD, tempoUpstreamAndDownstream , REF_HEIGHT_DOWNSTREAM_WEIGHTING, - DataUtil.createIndex(tableName=dicAllWeightFactorsTables[downstreamWeightingTable], - fieldName=ID_POINT, - isSpatial=False), - DataUtil.createIndex(tableName=dicAllWeightFactorsTables[downstreamWeightingTable], - fieldName=ID_POINT_Z, - isSpatial=False), - DataUtil.createIndex(tableName=tempoPrioritiesWeightedAllPlusBack, - fieldName=ID_POINT, - isSpatial=False), DataUtil.createIndex(tableName=tempoPrioritiesWeightedAllPlusBack, - fieldName=ID_POINT_Z, + fieldName=[ID_POINT, ID_POINT_Z], isSpatial=False))) # Join the downstream weigthted points to the non downstream weighted ones cursor.execute(""" - {12}; - {13}; {10}; - {11}; DROP TABLE IF EXISTS {9}; CREATE TABLE {9} AS SELECT a.{2}, a.{3}, a.{4}, a.{5}, a.{6}, a.{7}, a.{8} @@ -2255,16 +2231,7 @@ def manageSuperimposition(cursor, V , W, REF_HEIGHT_FIELD , initializedWindFactorTable, DataUtil.createIndex(tableName=tempoUpstreamAndDownstream, - fieldName=ID_POINT, - isSpatial=False), - DataUtil.createIndex(tableName=tempoUpstreamAndDownstream, - fieldName=ID_POINT_Z, - isSpatial=False), - DataUtil.createIndex(tableName=tempoPrioritiesWeightedAllPlusBack, - fieldName=ID_POINT, - isSpatial=False), - DataUtil.createIndex(tableName=tempoPrioritiesWeightedAllPlusBack, - fieldName=ID_POINT_Z, + fieldName=[ID_POINT, ID_POINT_Z], isSpatial=False))) if not DEBUG: diff --git a/metadata.txt b/metadata.txt index a1dd468..a0108d7 100644 --- a/metadata.txt +++ b/metadata.txt @@ -6,7 +6,7 @@ name=UMEP for processing qgisMinimumVersion=3.0 description=Urban Multi-scale Environmental Predictor (UMEP) for the QGIS processing framework -version=2.0.21 +version=2.0.22 author=Fredrik Lindberg, Nils Wallenberg email=fredrikl@gvc.gu.se @@ -25,6 +25,7 @@ repository=https://github.com/UMEP-dev/UMEP-processing hasProcessingProvider=yes # Uncomment the following line and add your changelog: changelog= + 2.0.22: URock: Fix endless query (issue #63 in UMEP-Processing) 2.0.21: URock: Fix .gpkg extension issue (issue #66 in UMEP-Processing) 2.0.20: URock: Fix canyon scheme (resolve part of issue #589). 2.0.19: URock: New H2GIS version (2.2.1) and solve issue with open vegetation geometry validity (response to #63 - in UMEP-Processing)