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 a267f7185e..f38283ef92 100644 --- a/geoindicators/src/main/groovy/org/orbisgis/geoclimate/geoindicators/RsuIndicators.groovy +++ b/geoindicators/src/main/groovy/org/orbisgis/geoclimate/geoindicators/RsuIndicators.groovy @@ -1811,7 +1811,7 @@ String roofFractionDistributionExact(JdbcDataSource datasource, String rsu, Stri for (i in 1..(listLayersBottom.size() - 1)) { def layer_top = listLayersBottom[i] def layer_bottom = listLayersBottom[i - 1] - def indicNameH = "${BASE_NAME}_${layer_bottom}_$layer_top".toString() + def indicNameH = getDistribIndicName(BASE_NAME, 'H', layer_bottom, layer_top).toString() tab_H[i - 1] = "${buildFracH}_$layer_bottom".toString() datasource """ DROP TABLE IF EXISTS $bufferTable; @@ -1840,7 +1840,7 @@ String roofFractionDistributionExact(JdbcDataSource datasource, String rsu, Stri // 4. Calculate the fraction of roof for the last level of the canopy def layer_bottom = listLayersBottom[listLayersBottom.size() - 1] - def indicNameH = "${BASE_NAME}_${layer_bottom}_inf".toString() + def indicNameH = getDistribIndicName(BASE_NAME, 'H', layer_bottom, null).toString() tab_H[listLayersBottom.size() - 1] = "${buildFracH}_$layer_bottom".toString() datasource """ DROP TABLE IF EXISTS $bufferTable; 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 b6dd6cc24c..33b3cb5241 100644 --- a/geoindicators/src/main/groovy/org/orbisgis/geoclimate/geoindicators/WorkflowGeoIndicators.groovy +++ b/geoindicators/src/main/groovy/org/orbisgis/geoclimate/geoindicators/WorkflowGeoIndicators.groovy @@ -618,6 +618,18 @@ String computeRSUIndicators(JdbcDataSource datasource, String buildingTable, finalTablesToJoin.put(computeGeometryProperties, columnIdRsu) } + // Calculate building height distribution + String buildingCutted + if (indicatorUse*.toUpperCase().contains("TEB")) { + def roofFractionDistributionExact = Geoindicators.RsuIndicators.roofFractionDistributionExact(datasource, + rsu, buildingTable, columnIdRsu, + [0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50], true, prefixName) + if (roofFractionDistributionExact) { + finalTablesToJoin.put(roofFractionDistributionExact, columnIdRsu) + } else { + info "Cannot compute the roof fraction distribution." + } + } // Building free external facade density if (indicatorUse*.toUpperCase().contains("UTRF") || indicatorUse*.toUpperCase().contains("LCZ")) { @@ -637,7 +649,7 @@ String computeRSUIndicators(JdbcDataSource datasource, String buildingTable, def inputVarAndOperations = [:] def heightColumnName = parameters.heightColumnName - if (indicatorUse*.toUpperCase().contains("LCZ") || indicatorUse*.toUpperCase().contains("TEB")) { + if (indicatorUse*.toUpperCase().contains("LCZ")) { inputVarAndOperations = inputVarAndOperations << [(heightColumnName): ["GEOM_AVG"]] } if (indicatorUse*.toUpperCase().contains("UTRF")) { @@ -649,12 +661,14 @@ String computeRSUIndicators(JdbcDataSource datasource, String buildingTable, "building" : ["NB_DENS"], "pop" : ["SUM", "DENS"]] } + if (indicatorUse*.toUpperCase().contains("TEB")) { + inputVarAndOperations = inputVarAndOperations << [(heightColumnName): ["GEOM_AVG", "AVG", "STD"]] + } def rsuStatisticsUnweighted = Geoindicators.GenericIndicators.unweightedOperationFromLowerScale(datasource, buildingTable, rsu, columnIdRsu, columnIdBuild, inputVarAndOperations, temporaryPrefName) if (!rsuStatisticsUnweighted) { - info "Cannot compute the statistics : building, building volume densities, building number density" + - " and mean building neighbor number for the RSU" + info "Cannot compute the building unweighted statistics at RSU scale" return } // Join in an intermediate table (for perviousness fraction) @@ -1195,6 +1209,7 @@ Map getParameters() { "nbEstimatedBuildHeight" : 0, "svfSimplified" : true, "facadeDensListLayersBottom" : [0, 10, 20, 30, 40, 50], + "buildHeightListLayersBottom" : [0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50], "facadeDensNumberOfDirection" : 12, "svfPointDensity" : 0.008, "svfRayLength" : 100, @@ -2033,7 +2048,7 @@ String rasterizeIndicators(JdbcDataSource datasource, if (!buildingCutted) { buildingCutted = cutBuilding(datasource, grid, building) if (!buildingCutted) { - info "Cannot split the building with the grid to compute the building height distance" + info "Cannot split the building with the grid to compute the building height distribution" return } } diff --git a/geoindicators/src/test/groovy/org/orbisgis/geoclimate/geoindicators/RsuIndicatorsTests.groovy b/geoindicators/src/test/groovy/org/orbisgis/geoclimate/geoindicators/RsuIndicatorsTests.groovy index b410a730df..c003605fb2 100644 --- a/geoindicators/src/test/groovy/org/orbisgis/geoclimate/geoindicators/RsuIndicatorsTests.groovy +++ b/geoindicators/src/test/groovy/org/orbisgis/geoclimate/geoindicators/RsuIndicatorsTests.groovy @@ -684,19 +684,19 @@ class RsuIndicatorsTests { [0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50], "test") assertNotNull(p) - assertEquals 1.0 / 3, h2GIS.firstRow("SELECT * FROM ${p} WHERE id_rsu = 1").ROOF_FRACTION_DISTRIBUTION_0_5, 0.00001 - assertEquals 0, h2GIS.firstRow("SELECT * FROM ${p} WHERE id_rsu = 1").ROOF_FRACTION_DISTRIBUTION_15_20, 0.00001 - assertEquals 1.0 / 3, h2GIS.firstRow("SELECT * FROM ${p} WHERE id_rsu = 1").ROOF_FRACTION_DISTRIBUTION_20_25, 0.00001 - assertEquals 1.0 / 3, h2GIS.firstRow("SELECT * FROM ${p} WHERE id_rsu = 1").ROOF_FRACTION_DISTRIBUTION_50_INF, 0.00001 - assertEquals 1.0, h2GIS.firstRow("SELECT * FROM ${p} WHERE id_rsu = 2").ROOF_FRACTION_DISTRIBUTION_20_25, 0.00001 - assertEquals 0, h2GIS.firstRow("SELECT * FROM ${p} WHERE id_rsu = 2").ROOF_FRACTION_DISTRIBUTION_0_5, 0.00001 - assertEquals 0, h2GIS.firstRow("SELECT * FROM ${p} WHERE id_rsu = 2").ROOF_FRACTION_DISTRIBUTION_50_INF, 0.00001 - assertEquals 0, h2GIS.firstRow("SELECT * FROM ${p} WHERE id_rsu = 3").ROOF_FRACTION_DISTRIBUTION_20_25, 0.00001 - assertEquals 0, h2GIS.firstRow("SELECT * FROM ${p} WHERE id_rsu = 3").ROOF_FRACTION_DISTRIBUTION_0_5, 0.00001 - assertEquals 1.0, h2GIS.firstRow("SELECT * FROM ${p} WHERE id_rsu = 3").ROOF_FRACTION_DISTRIBUTION_50_INF, 0.00001 - assertEquals 0, h2GIS.firstRow("SELECT * FROM ${p} WHERE id_rsu = 4").ROOF_FRACTION_DISTRIBUTION_20_25, 0.00001 - assertEquals 0, h2GIS.firstRow("SELECT * FROM ${p} WHERE id_rsu = 4").ROOF_FRACTION_DISTRIBUTION_0_5, 0.00001 - assertEquals 0, h2GIS.firstRow("SELECT * FROM ${p} WHERE id_rsu = 4").ROOF_FRACTION_DISTRIBUTION_50_INF, 0.00001 + assertEquals 1.0 / 3, h2GIS.firstRow("SELECT * FROM ${p} WHERE id_rsu = 1").ROOF_FRACTION_DISTRIBUTION_H0_5, 0.00001 + assertEquals 0, h2GIS.firstRow("SELECT * FROM ${p} WHERE id_rsu = 1").ROOF_FRACTION_DISTRIBUTION_H15_20, 0.00001 + assertEquals 1.0 / 3, h2GIS.firstRow("SELECT * FROM ${p} WHERE id_rsu = 1").ROOF_FRACTION_DISTRIBUTION_H20_25, 0.00001 + assertEquals 1.0 / 3, h2GIS.firstRow("SELECT * FROM ${p} WHERE id_rsu = 1").ROOF_FRACTION_DISTRIBUTION_H50, 0.00001 + assertEquals 1.0, h2GIS.firstRow("SELECT * FROM ${p} WHERE id_rsu = 2").ROOF_FRACTION_DISTRIBUTION_H20_25, 0.00001 + assertEquals 0, h2GIS.firstRow("SELECT * FROM ${p} WHERE id_rsu = 2").ROOF_FRACTION_DISTRIBUTION_H0_5, 0.00001 + assertEquals 0, h2GIS.firstRow("SELECT * FROM ${p} WHERE id_rsu = 2").ROOF_FRACTION_DISTRIBUTION_H50, 0.00001 + assertEquals 0, h2GIS.firstRow("SELECT * FROM ${p} WHERE id_rsu = 3").ROOF_FRACTION_DISTRIBUTION_H20_25, 0.00001 + assertEquals 0, h2GIS.firstRow("SELECT * FROM ${p} WHERE id_rsu = 3").ROOF_FRACTION_DISTRIBUTION_H0_5, 0.00001 + assertEquals 1.0, h2GIS.firstRow("SELECT * FROM ${p} WHERE id_rsu = 3").ROOF_FRACTION_DISTRIBUTION_H50, 0.00001 + assertEquals 0, h2GIS.firstRow("SELECT * FROM ${p} WHERE id_rsu = 4").ROOF_FRACTION_DISTRIBUTION_H20_25, 0.00001 + assertEquals 0, h2GIS.firstRow("SELECT * FROM ${p} WHERE id_rsu = 4").ROOF_FRACTION_DISTRIBUTION_H0_5, 0.00001 + assertEquals 0, h2GIS.firstRow("SELECT * FROM ${p} WHERE id_rsu = 4").ROOF_FRACTION_DISTRIBUTION_H50, 0.00001 } @Test diff --git a/geoindicators/src/test/groovy/org/orbisgis/geoclimate/geoindicators/WorkflowGeoIndicatorsTest.groovy b/geoindicators/src/test/groovy/org/orbisgis/geoclimate/geoindicators/WorkflowGeoIndicatorsTest.groovy index 976a57f348..d517ab4f38 100644 --- a/geoindicators/src/test/groovy/org/orbisgis/geoclimate/geoindicators/WorkflowGeoIndicatorsTest.groovy +++ b/geoindicators/src/test/groovy/org/orbisgis/geoclimate/geoindicators/WorkflowGeoIndicatorsTest.groovy @@ -106,7 +106,7 @@ class WorkflowGeoIndicatorsTest { // Indicator list (at RSU scale) for each facade direction and height (projected facade distrib) // and also for height only (vert and non vert roof density) List listFacadeDistrib = [] - List listHeightDistrib = [] + List listRoofDensDistrib = [] int rangeDeg = 360 / parameters.facadeDensNumberOfDirection for (int i in 0..parameters.facadeDensListLayersBottom.size()-1) { Integer h_bot = parameters.facadeDensListLayersBottom[i] @@ -117,8 +117,8 @@ class WorkflowGeoIndicatorsTest { h_up = parameters.facadeDensListLayersBottom[i + 1] } // Create names for vert and non vert roof density - listHeightDistrib.add(Geoindicators.RsuIndicators.getDistribIndicName("vert_roof_area", 'h', h_bot, h_up).toString().toUpperCase()) - listHeightDistrib.add(Geoindicators.RsuIndicators.getDistribIndicName("non_vert_roof_area", 'h', h_bot, h_up).toString().toUpperCase()) + listRoofDensDistrib.add(Geoindicators.RsuIndicators.getDistribIndicName("vert_roof_area", 'h', h_bot, h_up).toString().toUpperCase()) + listRoofDensDistrib.add(Geoindicators.RsuIndicators.getDistribIndicName("non_vert_roof_area", 'h', h_bot, h_up).toString().toUpperCase()) // Create names for facade density String name_h = Geoindicators.RsuIndicators.getDistribIndicName("projected_facade_area_distribution", 'h', h_bot, h_up).toString().toUpperCase() @@ -128,10 +128,22 @@ class WorkflowGeoIndicatorsTest { listFacadeDistrib.add(Geoindicators.RsuIndicators.getDistribIndicName(name_h, 'd', d_bot, d_up).toString().toUpperCase()) } } + // Indicator list (at RSU scale) for each building height level + List listHeightDistrib = [] + for (int i in 0..parameters.buildHeightListLayersBottom.size()-1) { + Integer h_bot = parameters.buildHeightListLayersBottom[i] + Integer h_up + if (h_bot == parameters.buildHeightListLayersBottom[-1]) { + h_up = null + } else { + h_up = parameters.buildHeightListLayersBottom[i + 1] + } + listHeightDistrib.add(Geoindicators.RsuIndicators.getDistribIndicName("roof_fraction_distribution", 'h', h_bot, h_up).toString().toUpperCase()) + } listNames = [ "TEB" : ["VERT_ROOF_DENSITY", "NON_VERT_ROOF_DENSITY"] + - listRoadDir + listFacadeDistrib + listHeightDistrib + listBuildTypTeb + - ["EFFECTIVE_TERRAIN_ROUGHNESS_LENGTH"], + listRoadDir + listFacadeDistrib + listRoofDensDistrib + listBuildTypTeb + listHeightDistrib + + ["AVG_HEIGHT_ROOF", "STD_HEIGHT_ROOF", "EFFECTIVE_TERRAIN_ROUGHNESS_LENGTH"], "UTRF": ["AREA", "ASPECT_RATIO", "BUILDING_TOTAL_FRACTION", "FREE_EXTERNAL_FACADE_DENSITY", "VEGETATION_FRACTION_UTRF", "LOW_VEGETATION_FRACTION_UTRF", "HIGH_VEGETATION_IMPERVIOUS_FRACTION_UTRF", "HIGH_VEGETATION_PERVIOUS_FRACTION_UTRF", "ROAD_FRACTION_UTRF", "IMPERVIOUS_FRACTION_UTRF", @@ -145,7 +157,6 @@ class WorkflowGeoIndicatorsTest { "IMPERVIOUS_FRACTION_LCZ", "GEOM_AVG_HEIGHT_ROOF", "EFFECTIVE_TERRAIN_ROUGHNESS_LENGTH", "EFFECTIVE_TERRAIN_ROUGHNESS_CLASS", "HIGH_VEGETATION_FRACTION_LCZ", "LOW_VEGETATION_FRACTION_LCZ", "WATER_FRACTION_LCZ"] + listBuildTypLcz] - // Basic columns at RSU scale listColBasic = ["ID_RSU", "THE_GEOM"]