Skip to content

Commit

Permalink
Fix issue #63 UMEP-Processing
Browse files Browse the repository at this point in the history
  • Loading branch information
j3r3m1 committed Mar 6, 2024
1 parent 00a75bc commit fa8a4ec
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 56 deletions.
9 changes: 6 additions & 3 deletions functions/URock/DataUtil.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand Down
71 changes: 19 additions & 52 deletions functions/URock/InitWindField.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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},
Expand All @@ -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}
Expand All @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion metadata.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand Down

0 comments on commit fa8a4ec

Please sign in to comment.