From 5a8a2579a8f4a6acdb35c08c2e943849d2d99e86 Mon Sep 17 00:00:00 2001 From: ebocher Date: Tue, 3 Oct 2023 18:02:40 +0200 Subject: [PATCH] Add TERRAIN_ROUGHNESS_CLASS at grid scale --- .../bdtopo/AbstractBDTopoWorkflow.groovy | 3 +- .../geoindicators/RsuIndicators.groovy | 6 +- .../WorkflowGeoIndicators.groovy | 190 +++++++++--------- .../geoindicators/RsuIndicatorsTests.groovy | 2 +- .../geoclimate/osm/WorkflowOSM.groovy | 3 +- .../geoclimate/osm/WorflowOSMTest.groovy | 6 +- 6 files changed, 109 insertions(+), 101 deletions(-) diff --git a/bdtopo/src/main/groovy/org/orbisgis/geoclimate/bdtopo/AbstractBDTopoWorkflow.groovy b/bdtopo/src/main/groovy/org/orbisgis/geoclimate/bdtopo/AbstractBDTopoWorkflow.groovy index c4be56987d..2393453556 100644 --- a/bdtopo/src/main/groovy/org/orbisgis/geoclimate/bdtopo/AbstractBDTopoWorkflow.groovy +++ b/bdtopo/src/main/groovy/org/orbisgis/geoclimate/bdtopo/AbstractBDTopoWorkflow.groovy @@ -543,7 +543,8 @@ abstract class AbstractBDTopoWorkflow extends BDTopoUtils { def allowed_grid_indicators = ["BUILDING_FRACTION", "BUILDING_HEIGHT", "BUILDING_POP", "BUILDING_TYPE_FRACTION", "WATER_FRACTION", "VEGETATION_FRACTION", "ROAD_FRACTION", "IMPERVIOUS_FRACTION", "UTRF_AREA_FRACTION", "UTRF_FLOOR_AREA_FRACTION", "LCZ_FRACTION", "LCZ_PRIMARY", "FREE_EXTERNAL_FACADE_DENSITY", "BUILDING_HEIGHT_WEIGHTED", "BUILDING_SURFACE_DENSITY", - "BUILDING_HEIGHT_DIST", "FRONTAL_AREA_INDEX", "SEA_LAND_FRACTION", "ASPECT_RATIO", "SVF", "HEIGHT_OF_ROUGHNESS_ELEMENTS"] + "BUILDING_HEIGHT_DIST", "FRONTAL_AREA_INDEX", "SEA_LAND_FRACTION", "ASPECT_RATIO", + "SVF", "HEIGHT_OF_ROUGHNESS_ELEMENTS", "TERRAIN_ROUGHNESS_CLASS"] def allowedOutputIndicators = allowed_grid_indicators.intersect(list_indicators*.toUpperCase()) if (allowedOutputIndicators) { //Update the RSU indicators list according the grid indicators diff --git a/geoindicators/src/main/groovy/org/orbisgis/geoclimate/geoindicators/RsuIndicators.groovy b/geoindicators/src/main/groovy/org/orbisgis/geoclimate/geoindicators/RsuIndicators.groovy index ba151cb151..62919539b4 100644 --- a/geoindicators/src/main/groovy/org/orbisgis/geoclimate/geoindicators/RsuIndicators.groovy +++ b/geoindicators/src/main/groovy/org/orbisgis/geoclimate/geoindicators/RsuIndicators.groovy @@ -1094,6 +1094,7 @@ String linearRoadOperations(JdbcDataSource datasource, String rsuTable, String r * @param datasource A connexion to a database (H2GIS, PostGIS, ...) where are stored the input Table and in which * the resulting database will be stored * @param rsuTable the name of the input ITable where are stored the effectiveTerrainRoughnessHeight values + * @param id_rsu Unique identifier column name * @param effectiveTerrainRoughnessLength the field name corresponding to the RSU effective terrain roughness class due * to roughness elements (buildings, trees, etc.) (in the rsuTable) * @param prefixName String use as prefix to name the output table @@ -1102,8 +1103,7 @@ String linearRoadOperations(JdbcDataSource datasource, String rsuTable, String r * * @author Jérémy Bernard */ -String effectiveTerrainRoughnessClass(JdbcDataSource datasource, String rsu, String effectiveTerrainRoughnessLength, String prefixName) { - def ID_COLUMN_RSU = "id_rsu" +String effectiveTerrainRoughnessClass(JdbcDataSource datasource, String rsu, String id_rsu, String effectiveTerrainRoughnessLength, String prefixName) { def BASE_NAME = "effective_terrain_roughness_class" debug "Executing RSU effective terrain roughness class" @@ -1113,7 +1113,7 @@ String effectiveTerrainRoughnessClass(JdbcDataSource datasource, String rsu, Str // Based on the lookup Table of Davenport datasource """DROP TABLE IF EXISTS $outputTableName; - CREATE TABLE $outputTableName AS SELECT $ID_COLUMN_RSU, + CREATE TABLE $outputTableName AS SELECT $id_rsu, CASEWHEN($effectiveTerrainRoughnessLength<0.0 OR $effectiveTerrainRoughnessLength IS NULL, null, CASEWHEN($effectiveTerrainRoughnessLength<0.00035, 1, CASEWHEN($effectiveTerrainRoughnessLength<0.01525, 2, diff --git a/geoindicators/src/main/groovy/org/orbisgis/geoclimate/geoindicators/WorkflowGeoIndicators.groovy b/geoindicators/src/main/groovy/org/orbisgis/geoclimate/geoindicators/WorkflowGeoIndicators.groovy index 79e947845a..c483927913 100644 --- a/geoindicators/src/main/groovy/org/orbisgis/geoclimate/geoindicators/WorkflowGeoIndicators.groovy +++ b/geoindicators/src/main/groovy/org/orbisgis/geoclimate/geoindicators/WorkflowGeoIndicators.groovy @@ -367,7 +367,7 @@ String computeRSUIndicators(JdbcDataSource datasource, String buildingTable, angleRangeSizeBuDirection : 30, svfSimplified : true, indicatorUse : ["LCZ", "UTRF", "TEB"], - surfSuperpositions : ["high_vegetation": ["water", "building", "low_vegetation", "rail","road", "impervious"]], + surfSuperpositions : ["high_vegetation": ["water", "building", "low_vegetation", "rail", "road", "impervious"]], surfPriorities : ["water", "building", "high_vegetation", "low_vegetation", "rail", "road", "impervious"], buildingAreaTypeAndComposition: ["light_industry": ["light_industry"], "heavy_industry": ["heavy_industry"], @@ -422,7 +422,7 @@ String computeRSUIndicators(JdbcDataSource datasource, String buildingTable, def columnIdRsu = "id_rsu" def columnIdBuild = "id_build" def BASE_NAME = "rsu_indicators" - def tablesToDrop=[] + def tablesToDrop = [] // Maps for intermediate or final joins def finalTablesToJoin = [:] def intermediateJoin = [:] @@ -450,9 +450,9 @@ String computeRSUIndicators(JdbcDataSource datasource, String buildingTable, if (!surfaceFractions) { // Calculate all surface fractions indicators // Need to create the smallest geometries used as input of the surface fraction process - def superpositionsTable = Geoindicators.RsuIndicators.smallestCommunGeometry(datasource, + def superpositionsTable = Geoindicators.RsuIndicators.smallestCommunGeometry(datasource, rsu, "id_rsu", buildingTable, road, water, vegetation, - impervious,rail, temporaryPrefName) + impervious, rail, temporaryPrefName) if (!superpositionsTable) { info "Cannot compute the smallest commun geometries" return @@ -467,7 +467,7 @@ String computeRSUIndicators(JdbcDataSource datasource, String buildingTable, return } - tablesToDrop< urbTypoCorrespondenceTabInverted[ini] = fin } - datasource.createIndex(utrfBuild,"I_TYPO") + datasource.createIndex(utrfBuild, "I_TYPO") def queryDistinct = """SELECT DISTINCT I_TYPO AS I_TYPO FROM $utrfBuild""" def mapTypos = datasource.rows(queryDistinct.toString()) def listTypos = [] @@ -912,8 +912,8 @@ Map computeTypologyIndicators(JdbcDataSource datasource, String building_indicat } queryCaseWhenReplace = queryCaseWhenReplace + " 'unknown' " + endCaseWhen utrfBuilding = postfix "UTRF_BUILDING" - datasource.createIndex(utrfBuild,COLUMN_ID_BUILD) - datasource.createIndex(building_indicators,COLUMN_ID_BUILD) + datasource.createIndex(utrfBuild, COLUMN_ID_BUILD) + datasource.createIndex(building_indicators, COLUMN_ID_BUILD) datasource """ DROP TABLE IF EXISTS $utrfBuilding; CREATE TABLE $utrfBuilding AS SELECT a.$COLUMN_ID_BUILD, a.$COLUMN_ID_RSU, a.THE_GEOM, @@ -926,9 +926,9 @@ Map computeTypologyIndicators(JdbcDataSource datasource, String building_indicat def queryCasewhen = [:] queryCasewhen["AREA"] = "" queryCasewhen["FLOOR_AREA"] = "" - datasource.createIndex(rsu_indicators,COLUMN_ID_RSU) - datasource.createIndex(building_indicators,COLUMN_ID_RSU) - datasource.createIndex(utrfBuilding,COLUMN_ID_BUILD) + datasource.createIndex(rsu_indicators, COLUMN_ID_RSU) + datasource.createIndex(building_indicators, COLUMN_ID_RSU) + datasource.createIndex(utrfBuilding, COLUMN_ID_BUILD) queryCasewhen.keySet().each { ind -> def querySum = "" @@ -946,26 +946,26 @@ Map computeTypologyIndicators(JdbcDataSource datasource, String building_indicat WHERE b.$COLUMN_ID_RSU IS NOT NULL GROUP BY b.$COLUMN_ID_RSU """.toString() - tablesToDrop<