Skip to content

Commit

Permalink
Add all sprawl indicators : areas, distances, cool distance
Browse files Browse the repository at this point in the history
  • Loading branch information
ebocher committed Mar 29, 2024
1 parent 2f8fd20 commit da48e9a
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,8 @@ abstract class AbstractBDTopoWorkflow extends BDTopoUtils {
"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", "TERRAIN_ROUGHNESS_CLASS"]
"SVF", "HEIGHT_OF_ROUGHNESS_ELEMENTS", "TERRAIN_ROUGHNESS_CLASS","SPRAWL_AREAS",
"SPRAWL_DISTANCES", "SPRAWL_COOL_DISTANCE"]
def allowedOutputIndicators = allowed_grid_indicators.intersect(list_indicators*.toUpperCase())
if (allowedOutputIndicators) {
//Update the RSU indicators list according the grid indicators
Expand Down Expand Up @@ -586,11 +587,6 @@ abstract class AbstractBDTopoWorkflow extends BDTopoUtils {
}
grid_indicators_tmp.put("lcz_lod", lcz_lod)
}
def sprawl_areas = grid_indicators.sprawl_areas
if (sprawl_areas && sprawl_areas in Boolean) {
grid_indicators_tmp.put("sprawl_areas", sprawl_areas)
}

defaultParameters.put("grid_indicators", grid_indicators_tmp)
} else {
error "Please set a valid list of indicator names in ${allowed_grid_indicators}"
Expand Down Expand Up @@ -863,12 +859,19 @@ abstract class AbstractBDTopoWorkflow extends BDTopoUtils {
results.rsu_lcz, results.rsu_utrf_area, "", "",
processing_parameters.prefixName)
if (rasterizedIndicators) {
h2gis_datasource.dropTable(gridTableName)
results.put("grid_indicators", rasterizedIndicators)
if(grid_indicators_params.sprawl_areas){
String sprawl_areas = Geoindicators.SpatialUnits.computeSprawlAreas(h2gis_datasource, rasterizedIndicators, Math.max(x_size,y_size))
if(sprawl_areas){
results.put("sprawl_areas", sprawl_areas)
}
if(!grid_indicators_params.lcz_lod){
//We must compute the multiscale grid
String grid_tmp = Geoindicators.GridIndicators.multiscaleLCZGrid(h2gis_datasource, rasterizedIndicators, "id_grid", 1)
h2gis_datasource.execute("DROP TABLE IF EXISTS $rasterizedIndicators;".toString())
rasterizedIndicators=grid_tmp
}
Map sprawl_indic = Geoindicators.WorkflowGeoIndicators.sprawlIndicators(h2gis_datasource,rasterizedIndicators, "id_grid", grid_indicators_params.indicators,
Math.max(x_size,y_size).floatValue())
if(sprawl_indic){
results.put("sprawl_areas", sprawl_indic.sprawl_areas)
results.put("grid_indicators", sprawl_indic.grid_indicators)
}
info("End computing grid_indicators")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2452,4 +2452,79 @@ static boolean modelCheck(String modelName) {
}
}
return true
}

/***
* This method is used to compute a set of sprawl_areas indicators as
* - the sprawl_areas layer
* - the distances inside and outside the sprawl_areas
* - the distance to cool areas (LCZ 101, 102, 103, 104,106,107) inside the sprawl_areas
*
* @param datasource
* @param grid_indicators
* @param list_indicators the indicators to compute : ["SPRAWL_AREAS", "SPRAWL_DISTANCES", "SPRAWL_COOL_DISTANCE"]
* @param distance the erode and dilate the geometries
* @return the sprawl_areas layer plus new distance columns on the input grid_indicators
*/
Map sprawlIndicators(JdbcDataSource datasource, String grid_indicators, String id_grid, List list_indicators, float distance) {
if (!list_indicators) {
info "The list of indicator names cannot be null or empty"
return
}

//Concert the list of indicators to upper case

allowed_indicators = ["SPRAWL_AREAS", "SPRAWL_DISTANCES", "SPRAWL_COOL_DISTANCE"]
def list_indicators_upper = list_indicators.collect { it.toUpperCase() }

def tablesToDrop = []
def tablesToJoin = [:]
String sprawl_areas
if (list_indicators_upper.intersect(["SPRAWL_AREAS", "SPRAWL_DISTANCES", "SPRAWL_COOL_DISTANCE"]) && grid_indicators) {
sprawl_areas = Geoindicators.SpatialUnits.computeSprawlAreas(datasource, grid_indicators, distance)
}
if (sprawl_areas) {
//Compute the distances
if (list_indicators.contains(["SPRAWL_DISTANCES"])) {
String inside_sprawl_areas = Geoindicators.GridIndicators.gridDistances(datasource, sprawl_areas, grid_indicators, id_grid)
if (inside_sprawl_areas) {
datasource.execute("""ALTER TABLE $inside_sprawl_areas RENAME COLUMN DISTANCE TO SPRAWL_INDIST""")
tablesToDrop << inside_sprawl_areas
String inverse_sprawl_areas = Geoindicators.SpatialUnits.inversePolygonsLayer(datasource, sprawl_areas)
if (inverse_sprawl_areas) {
datasource.execute("""ALTER TABLE $inside_sprawl_areas RENAME COLUMN DISTANCE TO SPRAWL_OUTDIST""")
tablesToDrop << inverse_sprawl_areas
tablesToJoin.put(inside_sprawl_areas, id_grid)
String outside_sprawl_areas = Geoindicators.GridIndicators.gridDistances(datasource, inverse_sprawl_areas, grid_indicators, id_grid)
if (outside_sprawl_areas) {
tablesToDrop << outside_sprawl_areas
tablesToJoin.put(outside_sprawl_areas, id_grid)
}
}
}
}
if (list_indicators.contains(["SPRAWL_COOL_DISTANCE"])) {
String cool_areas = Geoindicators.SpatialUnits.extractCoolAreas(datasource, grid_indicators, distance)
if (cool_areas) {
tablesToDrop << cool_areas
String inverse_cool_areas = Geoindicators.SpatialUnits.inversePolygonsLayer(datasource, cool_areas)
if (inverse_cool_areas) {
tablesToDrop << inverse_cool_areas
String cool_distances = Geoindicators.GridIndicators.gridDistances(datasource, inverse_cool_areas, grid_indicators, id_grid)
if (cool_distances) {
tablesToDrop << cool_distances
datasource.execute("""ALTER TABLE $cool_distances RENAME COLUMN DISTANCE TO SPRAWL_COOL_INSDIST""")
tablesToJoin.put(cool_distances, id_grid)
}
}
}
}
}
if (tablesToJoin.size() > 0) {
tablesToDrop<<grid_indicators
grid_indicators = Geoindicators.DataUtils.joinTables(datasource, tablesToJoin, postfix("grid_indicators"))
}
datasource.dropTable(tablesToDrop)

return ["sprawl_areas":sprawl_areas, "grid_indicators": grid_indicators]
}
19 changes: 13 additions & 6 deletions osm/src/main/groovy/org/orbisgis/geoclimate/osm/WorkflowOSM.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -658,11 +658,17 @@ Map osm_processing(JdbcDataSource h2gis_datasource, def processing_parameters, d
if (rasterizedIndicators) {
h2gis_datasource.dropTable(grid)
results.put("grid_indicators", rasterizedIndicators)
if(grid_indicators_params.sprawl_areas){
String sprawl_areas = Geoindicators.SpatialUnits.computeSprawlAreas(h2gis_datasource, rasterizedIndicators, Math.max(x_size,y_size))
if(sprawl_areas){
results.put("sprawl_areas", sprawl_areas)
}
if(!grid_indicators_params.lcz_lod){
//We must compute the multiscale grid
String grid_tmp = Geoindicators.GridIndicators.multiscaleLCZGrid(h2gis_datasource, rasterizedIndicators, "id_grid", 1)
h2gis_datasource.execute("DROP TABLE IF EXISTS $rasterizedIndicators;".toString())
rasterizedIndicators=grid_tmp
}
def sprawl_indic = Geoindicators.WorkflowGeoIndicators.sprawlIndicators(h2gis_datasource,rasterizedIndicators, "id_grid", grid_indicators_params.indicators,
Math.max(x_size,y_size).floatValue())
if(sprawl_indic){
results.put("sprawl_areas", sprawl_indic.sprawl_areas)
results.put("grid_indicators", sprawl_indic.grid_indicators)
}
info("End computing grid_indicators")
}
Expand Down Expand Up @@ -911,7 +917,8 @@ def extractProcessingParameters(def processing_parameters) {
"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", "TERRAIN_ROUGHNESS_CLASS"]
"HEIGHT_OF_ROUGHNESS_ELEMENTS", "TERRAIN_ROUGHNESS_CLASS","SPRAWL_AREAS",
"SPRAWL_DISTANCES", "SPRAWL_COOL_DISTANCE"]
def allowedOutputIndicators = allowed_grid_indicators.intersect(list_indicators*.toUpperCase())
if (allowedOutputIndicators) {
//Update the RSU indicators list according the grid indicators
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -690,9 +690,10 @@ class WorflowOSMTest extends WorkflowAbstractTest {
"SEA_LAND_FRACTION",
"ASPECT_RATIO",
//"SVF",
"HEIGHT_OF_ROUGHNESS_ELEMENTS", "TERRAIN_ROUGHNESS_CLASS"],
"lcz_lod":2,
"sprawl_areas":true
"HEIGHT_OF_ROUGHNESS_ELEMENTS", "TERRAIN_ROUGHNESS_CLASS",
"SPRAWL_AREAS",
"SPRAWL_DISTANCES", "SPRAWL_COOL_DISTANCE"],
//"lcz_lod":2
]/*, "worldpop_indicators": true,
"road_traffic" : true,
Expand Down

0 comments on commit da48e9a

Please sign in to comment.