Skip to content

Commit

Permalink
Merge pull request #853 from ebocher/urban_areas_rsu
Browse files Browse the repository at this point in the history
Perform RSU segmentation using urban areas layer
  • Loading branch information
ebocher authored Oct 6, 2023
2 parents 008e4c8 + 48c2db4 commit 1ecd510
Show file tree
Hide file tree
Showing 13 changed files with 68 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,7 @@ abstract class AbstractBDTopoWorkflow extends BDTopoUtils {
Map geoIndicators = Geoindicators.WorkflowGeoIndicators.computeAllGeoIndicators(h2gis_datasource, zone,
building, road,
rail, vegetation,
water, impervious, "", "", "",
water, impervious, "", "", urban_areas,"",
rsu_indicators_params, processing_parameters.prefixName)
if (!geoIndicators) {
error "Cannot build the geoindicators for the zone $id_zone"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import static org.h2gis.network.functions.ST_ConnectedComponents.getConnectedCom
* @param vegetation The vegetation table to be processed
* @param water The water table to be processed
* @param sea_land_mask The table to distinguish sea from land
* @param urban_areas The table to distinguish the urban areas
* @param surface_vegetation A double value to select the vegetation geometry areas.
* Expressed in geometry unit of the vegetationTable, default 10000
* @param surface_hydro A double value to select the hydrographic geometry areas.
Expand All @@ -59,7 +60,7 @@ import static org.h2gis.network.functions.ST_ConnectedComponents.getConnectedCom
*/
String createTSU(JdbcDataSource datasource, String zone,
double area = 1f, String road, String rail, String vegetation,
String water, String sea_land_mask,
String water, String sea_land_mask,String urban_areas,
double surface_vegetation, double surface_hydro, String prefixName) {
def BASE_NAME = "rsu"

Expand All @@ -70,7 +71,7 @@ String createTSU(JdbcDataSource datasource, String zone,

def tsuDataPrepared = prepareTSUData(datasource,
zone, road, rail,
vegetation, water, sea_land_mask, surface_vegetation, surface_hydro, prefixName)
vegetation, water, sea_land_mask, urban_areas, surface_vegetation, surface_hydro, prefixName)
if (!tsuDataPrepared) {
info "Cannot prepare the data for RSU calculation."
return
Expand Down Expand Up @@ -156,6 +157,8 @@ String createTSU(JdbcDataSource datasource, String inputTableName, String inputz
* @param rail The rail table to be processed
* @param vegetation The vegetation table to be processed
* @param water The hydrographic table to be processed
* @param water The sea mask to be processed
* @param water The urban areas table to be processed
* @param surface_vegetation A double value to select the vegetation geometry areas.
* Expressed in geometry unit of the vegetationTable. 10000 m² seems correct.
* @param sea_land_mask The table to distinguish sea from land
Expand All @@ -167,7 +170,7 @@ String createTSU(JdbcDataSource datasource, String inputTableName, String inputz
* @return A database table name.
*/
String prepareTSUData(JdbcDataSource datasource, String zone, String road, String rail,
String vegetation, String water, String sea_land_mask,
String vegetation, String water, String sea_land_mask, String urban_areas,
double surface_vegetation, double surface_hydro, String prefixName = "unified_abstract_model") {
if (surface_vegetation <= 100) {
error("The surface of vegetation must be greater or equal than 100 m²")
Expand Down Expand Up @@ -320,6 +323,14 @@ String prepareTSUData(JdbcDataSource datasource, String zone, String road, Strin
}
}

if (water && datasource.hasTable(urban_areas)) {
if (datasource.getColumnNames(urban_areas).size() > 0) {
debug "Preparing urban areas..."
queryCreateOutputTable += [urban_areas_tmp: "(SELECT ST_ToMultiLine(THE_GEOM) FROM $urban_areas)"]

}
}

// The input table that contains the geometries to be transformed as TSU
debug "Grouping all tables..."
if (queryCreateOutputTable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1006,6 +1006,8 @@ Map computeTypologyIndicators(JdbcDataSource datasource, String building_indicat
* @param rail The rail table to be processed
* @param vegetation The vegetation table to be processed
* @param water The hydrographic table to be processed
* @param sea_land_mask The sea areas to be processed
* @param urban_areas The urban areas table to be processed
* @param rsu Only if the RSU table is provided by the user (otherwise the default RSU is calculated)
* @param surface_vegetation The minimum area of vegetation that will be considered to delineate the RSU (default 100,000 m²)
* @param surface_hydro The minimum area of water that will be considered to delineate the RSU (default 2,500 m²)
Expand All @@ -1021,7 +1023,7 @@ Map computeTypologyIndicators(JdbcDataSource datasource, String building_indicat
*/
Map createUnitsOfAnalysis(JdbcDataSource datasource, String zone, String building,
String road, String rail, String vegetation,
String water, String sea_land_mask,
String water, String sea_land_mask, String urban_areas,
String rsu, double surface_vegetation,
double surface_hydro, double snappingTolerance, List indicatorUse = ["LCZ", "UTRF", "TEB"], String prefixName = "") {
info "Create the units of analysis..."
Expand All @@ -1031,7 +1033,7 @@ Map createUnitsOfAnalysis(JdbcDataSource datasource, String zone, String buildin
// Create the RSU
rsu = Geoindicators.SpatialUnits.createTSU(datasource, zone, road, rail,
vegetation, water,
sea_land_mask, surface_vegetation,
sea_land_mask, urban_areas, surface_vegetation,
surface_hydro, prefixName)
if (!rsu) {
info "Cannot compute the RSU."
Expand Down Expand Up @@ -1203,7 +1205,7 @@ Map getParameters(Map parameters) {
*/
Map computeAllGeoIndicators(JdbcDataSource datasource, String zone, String building, String road, String rail, String vegetation,
String water, String impervious, String buildingEstimateTableName,
String sea_land_mask, String rsuTable,
String sea_land_mask,String urban_areas, String rsuTable,
Map parameters = [:], String prefixName) {
Map inputParameters = getParameters()
if (parameters) {
Expand Down Expand Up @@ -1232,7 +1234,7 @@ Map computeAllGeoIndicators(JdbcDataSource datasource, String zone, String build
road, rail, vegetation,
water, impervious,
buildingEstimateTableName,
sea_land_mask, rsuTable,
sea_land_mask, urban_areas, rsuTable,
surface_vegetation, surface_hydro,
snappingTolerance,
buildingHeightModelName, prefixName)
Expand Down Expand Up @@ -1272,7 +1274,7 @@ Map computeAllGeoIndicators(JdbcDataSource datasource, String zone, String build
Map spatialUnitsForCalc = createUnitsOfAnalysis(datasource, zone,
building, road, rail,
vegetation,
water, sea_land_mask, rsuTable,
water, sea_land_mask, "", rsuTable,
surface_vegetation,
surface_hydro, snappingTolerance, indicatorUse,
prefixName)
Expand Down Expand Up @@ -1322,7 +1324,7 @@ Map computeAllGeoIndicators(JdbcDataSource datasource, String zone, String build
Map spatialUnits = createUnitsOfAnalysis(datasource, zone,
building, road,
rail, vegetation,
water, sea_land_mask, "",
water, sea_land_mask, "","",
surface_vegetation,
surface_hydro, snappingTolerance, indicatorUse,
prefixName)
Expand Down Expand Up @@ -1359,7 +1361,7 @@ Map computeAllGeoIndicators(JdbcDataSource datasource, String zone, String build
Map estimateBuildingHeight(JdbcDataSource datasource, String zone, String building,
String road, String rail, String vegetation,
String water, String impervious,
String building_estimate, String sea_land_mask, String rsu,
String building_estimate, String sea_land_mask, String urban_areas, String rsu,
double surface_vegetation, double surface_hydro,
double snappingTolerance, String buildingHeightModelName, String prefixName = "") {
if (!building_estimate) {
Expand All @@ -1375,7 +1377,7 @@ Map estimateBuildingHeight(JdbcDataSource datasource, String zone, String buildi
//Create spatial units and relations : building, block, rsu
Map spatialUnits = createUnitsOfAnalysis(datasource, zone,
building, road, rail, vegetation,
water, sea_land_mask, rsu,
water, sea_land_mask, urban_areas, rsu,
surface_vegetation, surface_hydro, snappingTolerance, ["UTRF"],
prefixName)
if (!spatialUnits) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ class RsuIndicatorsTests {

def outputTableGeoms = Geoindicators.SpatialUnits.prepareTSUData(h2GIS,
'zone_test', 'road_test', '',
'veget_test', 'hydro_test', "",
'veget_test', 'hydro_test', "","",
10000, 2500, "prepare_rsu")

assertNotNull h2GIS.getTable(outputTableGeoms)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class SpatialUnitsTests {

def outputTableGeoms = Geoindicators.SpatialUnits.prepareTSUData(h2GIS,
'zone_test', 'road_test', 'rail_test',
'veget_test', 'hydro_test', "",
'veget_test', 'hydro_test', "","",
10000, 2500, "block")

assertNotNull(outputTableGeoms)
Expand All @@ -103,7 +103,7 @@ class SpatialUnitsTests {
def createRSU = Geoindicators.SpatialUnits.createTSU(h2GIS, "zone_test",
'road_test', 'rail_test',
'veget_test', 'hydro_test',
"", 10000, 2500, "block")
"","", 10000, 2500, "block")
assert createRSU

assert h2GIS.getSpatialTable(createRSU).save(new File(folder, "rsu.shp").getAbsolutePath(), true)
Expand Down Expand Up @@ -188,7 +188,7 @@ class SpatialUnitsTests {

def outputTableGeoms = Geoindicators.SpatialUnits.prepareTSUData(h2GIS,
'zone_test', 'road_test', 'rail_test', 'veget_test',
'hydro_test', "", 10000, 2500, "block")
'hydro_test', "", "",10000, 2500, "block")


assertNotNull(outputTableGeoms)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class WorkflowGeoIndicatorsTest {
Map geoIndicatorsCompute_i = Geoindicators.WorkflowGeoIndicators.computeAllGeoIndicators(datasource, inputTableNames.zoneTable,
inputTableNames.buildingTable, inputTableNames.roadTable,
inputTableNames.railTable, inputTableNames.vegetationTable,
inputTableNames.hydrographicTable, "", "", "", "",
inputTableNames.hydrographicTable, "", "", "", "","",
["indicatorUse": indicatorUse, svfSimplified: false], prefixName)
assertNotNull(geoIndicatorsCompute_i)
checkRSUIndicators(datasource, geoIndicatorsCompute_i.rsu_indicators)
Expand Down Expand Up @@ -173,7 +173,7 @@ class WorkflowGeoIndicatorsTest {
inputTableNames.buildingTable, inputTableNames.roadTable,
inputTableNames.railTable, inputTableNames.vegetationTable,
inputTableNames.hydrographicTable, "",
"", "", "",
"", "", "","",
["indicatorUse": indicatorUse, svfSimplified: false, "utrfModelName": "UTRF_BDTOPO_V2_RF_2_2.model"], prefixName)
assertNotNull(geoIndicatorsCompute_i)

Expand Down Expand Up @@ -245,7 +245,7 @@ class WorkflowGeoIndicatorsTest {
Map geoIndicatorsCompute_i = Geoindicators.WorkflowGeoIndicators.computeAllGeoIndicators(datasource, inputTableNames.zoneTable,
inputTableNames.buildingTable, inputTableNames.roadTable,
inputTableNames.railTable, inputTableNames.vegetationTable,
inputTableNames.hydrographicTable, "",
inputTableNames.hydrographicTable, "","",
"", "", "", ["indicatorUse": indicatorUse, svfSimplified: false], prefixName)
assertNotNull(geoIndicatorsCompute_i)

Expand Down Expand Up @@ -287,7 +287,7 @@ class WorkflowGeoIndicatorsTest {
inputTableNames.buildingTable, inputTableNames.roadTable,
inputTableNames.railTable, inputTableNames.vegetationTable,
inputTableNames.hydrographicTable, "",
"", "", "", ["indicatorUse": indicatorUse, svfSimplified: false], prefixName)
"", "", "","", ["indicatorUse": indicatorUse, svfSimplified: false], prefixName)
assertNotNull(geoIndicatorsCompute_i)

checkRSUIndicators(datasource, geoIndicatorsCompute_i.rsu_indicators)
Expand Down Expand Up @@ -327,7 +327,7 @@ class WorkflowGeoIndicatorsTest {
inputTableNames.buildingTable, inputTableNames.roadTable,
inputTableNames.railTable, inputTableNames.vegetationTable,
inputTableNames.hydrographicTable, "",
"", "", "", ["indicatorUse": indicatorUse, svfSimplified: false], prefixName)
"", "", "", "",["indicatorUse": indicatorUse, svfSimplified: false], prefixName)
assertNotNull(geoIndicatorsCompute_i)

checkRSUIndicators(datasource, geoIndicatorsCompute_i.rsu_indicators)
Expand Down Expand Up @@ -368,7 +368,8 @@ class WorkflowGeoIndicatorsTest {
.computeAllGeoIndicators(datasource, inputTableNames.zoneTable,
inputTableNames.buildingTable, inputTableNames.roadTable,
inputTableNames.railTable, inputTableNames.vegetationTable,
inputTableNames.hydrographicTable, "", "", "", "",
inputTableNames.hydrographicTable, "", "", "",
"","",
["indicatorUse": indicatorUse, "svfSimplified": false],
prefixName)
assertNotNull(geoIndicatorsCompute_i)
Expand Down Expand Up @@ -410,7 +411,7 @@ class WorkflowGeoIndicatorsTest {
inputTableNames.buildingTable, inputTableNames.roadTable,
inputTableNames.railTable, inputTableNames.vegetationTable,
inputTableNames.hydrographicTable, "",
"", "", "", ["indicatorUse": indicatorUse, svfSimplified: false], prefixName)
"", "", "", "",["indicatorUse": indicatorUse, svfSimplified: false], prefixName)
assertNotNull(geoIndicatorsCompute_i)

def expectListRsuTempo = listColBasic + listColCommon
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1001,12 +1001,22 @@ String formatUrbanAreas(JdbcDataSource datasource, String urban_areas, String zo
queryMapper += ", a.the_geom as the_geom FROM $urban_areas as a"

}

def constructions = ["industrial", "commercial", "residential"]
int rowcount = 1
datasource.withBatch(100) { stmt ->
datasource.eachRow(queryMapper) { row ->
def typeAndUseValues = getTypeAndUse(row, columnNames, mappingType)
def use = typeAndUseValues[1]
def type = typeAndUseValues[0]
//Check if the urban areas is under construction
if(type == "construction"){
def construction = row."construction"
if(construction && construction in constructions){
type = construction
use = construction
}
}
Geometry geom = row.the_geom
int epsg = geom.getSRID()
for (int i = 0; i < geom.getNumGeometries(); i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ Map osm_processing(JdbcDataSource h2gis_datasource, def processing_parameters, d
hydrographicTableName, imperviousTableName,
buildingEstimateTableName,
seaLandMaskTableName,
"",
urbanAreasTable,"",
rsu_indicators_params,
processing_parameters.prefixName)
if (!geoIndicators) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,22 @@
"commercial",
"residential",
"retail",
"industrial"
]
"industrial",
"construction"
],
"construction":[]
},
"columns": [
"landuse",
"industrial"
"industrial",
"construction"
],
"type": {
"construction": {
"landuse": [
"construction"
]
},
"commercial": {
"landuse": [
"commercial",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class InputDataFormattingTest {
assertEquals 136, h2GIS.getTable(extractData.vegetation).rowCount
assertEquals 10, h2GIS.getTable(extractData.water).rowCount
assertEquals 47, h2GIS.getTable(extractData.impervious).rowCount
assertEquals 6, h2GIS.getTable(extractData.urban_areas).rowCount
assertEquals 7, h2GIS.getTable(extractData.urban_areas).rowCount
assertEquals 0, h2GIS.getTable(extractData.coastline).rowCount

//Buildings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class InputDataLoadingTest {

assertEquals 47, h2GIS.getTable(extract.impervious).rowCount

assertEquals 6, h2GIS.getTable(extract.urban_areas).rowCount
assertEquals 7, h2GIS.getTable(extract.urban_areas).rowCount
}

//This test is used for debug purpose
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ class WorflowOSMTest extends WorkflowAbstractTest {
datasource.load(urlZone, zone, true)
//Run tests
geoIndicatorsCalc(dirFile.absolutePath, datasource, zone, buildingTableName, roadTableName,
railTableName, vegetationTableName, hydrographicTableName, null, "",
saveResults, svfSimplified, indicatorUse, prefixName)
railTableName, vegetationTableName, hydrographicTableName, "", "","",
saveResults, svfSimplified, indicatorUse, prefixName, false)
}

@Test
Expand Down Expand Up @@ -196,7 +196,7 @@ class WorflowOSMTest extends WorkflowAbstractTest {

//Run tests
geoIndicatorsCalc(dirFile.absolutePath, datasource, zone, buildingTableName, roadTableName,
railTableName, vegetationTableName, hydrographicTableName, imperviousTableName, sealandTableName,
railTableName, vegetationTableName, hydrographicTableName, imperviousTableName, sealandTableName,"",
saveResults, svfSimplified, indicatorUse, prefixName, true)
}

Expand Down Expand Up @@ -663,7 +663,7 @@ class WorflowOSMTest extends WorkflowAbstractTest {
"delete": false
],
"input" : [
"locations": ["Redon"],//["Pont-de-Veyle"],//[nominatim["bbox"]],//["Lorient"],
"locations": [[47.081403,-1.481352,47.110619,-1.423845]],//["Pont-de-Veyle"],//[nominatim["bbox"]],//["Lorient"],
"area": 2800,
/*"timeout":182,
"maxsize": 536870918,
Expand Down
Loading

0 comments on commit 1ecd510

Please sign in to comment.