Skip to content

Commit

Permalink
Extend urban areas layer to support transport, government, military a…
Browse files Browse the repository at this point in the history
…nd social_building.

Add new rules to set the best building type when urban areas orvelap.
Add new type on building layer as building without wall, water_tower, slight_construction
  • Loading branch information
ebocher committed Nov 14, 2023
1 parent 23ab2e9 commit e45e679
Show file tree
Hide file tree
Showing 20 changed files with 297 additions and 138 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@ abstract class AbstractBDTopoWorkflow extends BDTopoUtils {
svfSimplified : true,
surface_vegetation: 10000f,
surface_hydro : 2500f,
surface_urban_areas: 10000f,
snappingTolerance : 0.01f,
mapOfWeights : ["sky_view_factor" : 4,
"aspect_ratio" : 3,
Expand Down Expand Up @@ -505,6 +506,11 @@ abstract class AbstractBDTopoWorkflow extends BDTopoUtils {
if (surface_hydroP && surface_hydroP in Number) {
rsu_indicators_default.surface_hydro = surface_hydroP
}
def surface_UrbanAreasP = rsu_indicators.surface_urban_areas
if (surface_UrbanAreasP && surface_UrbanAreasP in Number) {
rsu_indicators_default.surface_urban_areas = surface_UrbanAreasP
}

def svfSimplifiedP = rsu_indicators.svfSimplified
if (svfSimplifiedP && svfSimplifiedP in Boolean) {
rsu_indicators_default.svfSimplified = svfSimplifiedP
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def loadV2(
String troncon_voie_ferree = tablesExist.get("troncon_voie_ferree")
if (!troncon_voie_ferree) {
troncon_voie_ferree = "troncon_voie_ferree"
datasource.execute("DROP TABLE IF EXISTS $troncon_voie_ferree; CREATE TABLE $troncon_voie_ferree (THE_GEOM geometry(linestring, $srid), ID varchar, NATURE varchar, POS_SOL integer, FRANCHISST varchar,LARGEUR DOUBLE PRECISION);".toString())
datasource.execute("DROP TABLE IF EXISTS $troncon_voie_ferree; CREATE TABLE $troncon_voie_ferree (THE_GEOM geometry(linestring, $srid), ID varchar, NATURE varchar, POS_SOL integer, FRANCHISST varchar,LARGEUR DOUBLE PRECISION, NB_VOIES INTEGER);".toString())
}
String surface_eau = tablesExist.get("surface_eau")
if (!surface_eau) {
Expand Down Expand Up @@ -252,7 +252,8 @@ def loadV2(
datasource.execute("""
DROP TABLE IF EXISTS INPUT_RAIL;
CREATE TABLE INPUT_RAIL (THE_GEOM geometry, ID_SOURCE varchar(24), TYPE varchar, ZINDEX integer, CROSSING varchar, WIDTH DOUBLE PRECISION)
AS SELECT ST_FORCE2D(ST_MAKEVALID(a.THE_GEOM)) as the_geom, a.ID, a.NATURE, a.POS_SOL, a.FRANCHISST, CASE WHEN a.NB_VOIES = 0 THEN 1.435 ELSE 1.435 * a.NB_VOIES END FROM $troncon_voie_ferree a, $zoneTable b WHERE a.the_geom && b.the_geom AND ST_INTERSECTS(a.the_geom, b.the_geom) and a.POS_SOL>=0;
AS SELECT ST_FORCE2D(ST_MAKEVALID(a.THE_GEOM)) as the_geom, a.ID, a.NATURE, a.POS_SOL, a.FRANCHISST,
CASE WHEN a.NB_VOIES = 0 THEN 1.435 ELSE 1.435 * a.NB_VOIES END FROM $troncon_voie_ferree a, $zoneTable b WHERE a.the_geom && b.the_geom AND ST_INTERSECTS(a.the_geom, b.the_geom) and a.POS_SOL>=0;
""".toString())


Expand Down Expand Up @@ -445,7 +446,7 @@ Map loadV3(JdbcDataSource datasource,
troncon_de_voie_ferree = "troncon_de_voie_ferree"
datasource.execute("""DROP TABLE IF EXISTS $troncon_de_voie_ferree;
CREATE TABLE $troncon_de_voie_ferree (THE_GEOM geometry(linestring, $srid), ID varchar, NATURE varchar,
POS_SOL integer, FRANCHISST varchar, LARGEUR DOUBLE PRECISION);""".toString())
POS_SOL integer, FRANCHISST varchar, LARGEUR DOUBLE PRECISION, NB_VOIES INTEGER);""".toString())
}

String surface_hydrographique = tablesExist.get("surface_hydrographique")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import org.slf4j.Logger

abstract class AbstractScript extends Script {


public Logger logger


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,15 @@ import static org.h2gis.network.functions.ST_ConnectedComponents.getConnectedCom
* Expressed in geometry unit of the vegetationTable, default 10000
* @param surface_hydro A double value to select the hydrographic geometry areas.
* Expressed in geometry unit of the vegetationTable, default 2500
* @param surface_urban_areas A double value to select the urban areas.
* Expressed in geometry unit of the urban_areas table, default 10000
*
* @return A database table name and the name of the column ID
*/
String createTSU(JdbcDataSource datasource, String zone,
double area = 1f, String road, String rail, String vegetation,
String water, String sea_land_mask,String urban_areas,
double surface_vegetation, double surface_hydro, String prefixName) {
double surface_vegetation, double surface_hydro, double surface_urban_areas, String prefixName) {
def BASE_NAME = "rsu"

debug "Creating the reference spatial units"
Expand All @@ -71,7 +73,7 @@ String createTSU(JdbcDataSource datasource, String zone,

def tsuDataPrepared = prepareTSUData(datasource,
zone, road, rail,
vegetation, water, sea_land_mask, urban_areas, surface_vegetation, surface_hydro, prefixName)
vegetation, water, sea_land_mask, urban_areas, surface_vegetation, surface_hydro, surface_urban_areas, prefixName)
if (!tsuDataPrepared) {
info "Cannot prepare the data for RSU calculation."
return
Expand Down Expand Up @@ -114,7 +116,7 @@ String createTSU(JdbcDataSource datasource, String inputTableName, String inputz
error "The input data to compute the TSU cannot be null or empty"
return null
}
def epsg = datasource.getSpatialTable(inputTableName).srid
def epsg = datasource.getSrid(inputTableName)

if (area <= 0) {
error "The area value to filter the TSU must be greater to 0"
Expand All @@ -125,9 +127,9 @@ String createTSU(JdbcDataSource datasource, String inputTableName, String inputz
datasource """
DROP TABLE IF EXISTS $outputTableName;
CREATE TABLE $outputTableName AS
SELECT EXPLOD_ID AS $COLUMN_ID_NAME, ST_SETSRID(a.the_geom, $epsg) AS the_geom
SELECT EXPLOD_ID AS $COLUMN_ID_NAME, ST_SETSRID(ST_BUFFER(a.the_geom,0.01), $epsg) AS the_geom
FROM ST_EXPLODE('(
SELECT ST_BUFFER(ST_POLYGONIZE(ST_UNION(ST_NODE(ST_ACCUM(the_geom)))), -0.01) AS the_geom
SELECT ST_POLYGONIZE(ST_UNION(ST_NODE(ST_ACCUM(the_geom)))) AS the_geom
FROM $inputTableName)') AS a,
$inputzone AS b
WHERE a.the_geom && b.the_geom
Expand All @@ -139,7 +141,7 @@ String createTSU(JdbcDataSource datasource, String inputTableName, String inputz
CREATE TABLE $outputTableName AS
SELECT EXPLOD_ID AS $COLUMN_ID_NAME, ST_SETSRID(st_buffer(the_geom, -0.01), $epsg) AS the_geom
FROM ST_EXPLODE('(
SELECT ST_BUFFER(ST_POLYGONIZE(ST_UNION(ST_NODE(ST_ACCUM(the_geom)))),-0.01) AS the_geom
SELECT ST_POLYGONIZE(ST_UNION(ST_NODE(ST_ACCUM(the_geom)))) AS the_geom
FROM $inputTableName)') where st_area(the_geom) > $area""".toString()
}

Expand Down Expand Up @@ -171,7 +173,8 @@ String createTSU(JdbcDataSource datasource, String inputTableName, String inputz
*/
String prepareTSUData(JdbcDataSource datasource, String zone, String road, String rail,
String vegetation, String water, String sea_land_mask, String urban_areas,
double surface_vegetation, double surface_hydro, String prefixName = "unified_abstract_model") {
double surface_vegetation, double surface_hydro, double surface_urban_areas, String prefixName = "unified_abstract_model") {

if (surface_vegetation <= 100) {
error("The surface of vegetation must be greater or equal than 100 m²")
return
Expand All @@ -180,6 +183,12 @@ String prepareTSUData(JdbcDataSource datasource, String zone, String road, Strin
error("The surface of water must be greater or equal than 100 m²")
return
}

if (surface_urban_areas < 10000) {
error("The surface of urban areas must be greater or equal than 100 m²")
return
}

def BASE_NAME = "prepared_tsu_data"

debug "Preparing the abstract model to build the TSU"
Expand Down Expand Up @@ -326,8 +335,7 @@ 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)"]

queryCreateOutputTable += [urban_areas_tmp: "(SELECT ST_ToMultiLine(THE_GEOM) FROM $urban_areas WHERE st_area(the_geom)>=$surface_urban_areas and type not in ('social_building'))"]
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,8 @@ Map createUnitsOfAnalysis(JdbcDataSource datasource, String zone, String buildin
String road, String rail, String vegetation,
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 = "") {
double surface_hydro, double surface_urban_areas,
double snappingTolerance, List indicatorUse = ["LCZ", "UTRF", "TEB"], String prefixName = "") {
info "Create the units of analysis..."
def idRsu = "id_rsu"
def tablesToDrop = []
Expand All @@ -1038,7 +1039,7 @@ Map createUnitsOfAnalysis(JdbcDataSource datasource, String zone, String buildin
rsu = Geoindicators.SpatialUnits.createTSU(datasource, zone, road, rail,
vegetation, water,
sea_land_mask, urban_areas, surface_vegetation,
surface_hydro, prefixName)
surface_hydro,surface_urban_areas, prefixName)
if (!rsu) {
info "Cannot compute the RSU."
return
Expand Down Expand Up @@ -1111,7 +1112,7 @@ Map createUnitsOfAnalysis(JdbcDataSource datasource, String zone, String buildin
*/
Map getParameters() {
return [
"surface_vegetation" : 10000d, "surface_hydro": 2500d,
"surface_vegetation" : 10000d, "surface_hydro": 2500d, "surface_urban_areas":10000d,
"snappingTolerance" : 0.01d, "indicatorUse": ["LCZ", "UTRF", "TEB"],
"mapOfWeights" : ["sky_view_factor" : 1, "aspect_ratio": 1, "building_surface_fraction": 1,
"impervious_surface_fraction" : 1, "pervious_surface_fraction": 1,
Expand Down Expand Up @@ -1218,6 +1219,7 @@ Map computeAllGeoIndicators(JdbcDataSource datasource, String zone, String build

def surface_vegetation = inputParameters.surface_vegetation
def surface_hydro = inputParameters.surface_hydro
def surface_urban_areas = inputParameters.surface_urban_areas
def snappingTolerance = inputParameters.snappingTolerance
def buildingHeightModelName = inputParameters.buildingHeightModelName
def indicatorUse = inputParameters.indicatorUse
Expand All @@ -1239,7 +1241,7 @@ Map computeAllGeoIndicators(JdbcDataSource datasource, String zone, String build
water, impervious,
buildingEstimateTableName,
sea_land_mask, urban_areas, rsuTable,
surface_vegetation, surface_hydro,
surface_vegetation, surface_hydro,surface_urban_areas,
snappingTolerance,
buildingHeightModelName, prefixName)
if (!estimHeight) {
Expand Down Expand Up @@ -1280,7 +1282,7 @@ Map computeAllGeoIndicators(JdbcDataSource datasource, String zone, String build
vegetation,
water, sea_land_mask, "", rsuTable,
surface_vegetation,
surface_hydro, snappingTolerance, indicatorUse,
surface_hydro, surface_urban_areas, snappingTolerance, indicatorUse,
prefixName)
if (!spatialUnitsForCalc) {
error "Cannot create the spatial units"
Expand Down Expand Up @@ -1330,7 +1332,7 @@ Map computeAllGeoIndicators(JdbcDataSource datasource, String zone, String build
rail, vegetation,
water, sea_land_mask, "","",
surface_vegetation,
surface_hydro, snappingTolerance, indicatorUse,
surface_hydro,surface_urban_areas, snappingTolerance, indicatorUse,
prefixName)
if (!spatialUnits) {
error "Cannot create the spatial units"
Expand Down Expand Up @@ -1367,7 +1369,7 @@ Map estimateBuildingHeight(JdbcDataSource datasource, String zone, String buildi
String water, String impervious,
String building_estimate, String sea_land_mask, String urban_areas, String rsu,
double surface_vegetation, double surface_hydro,
double snappingTolerance, String buildingHeightModelName, String prefixName = "") {
double snappingTolerance, double surface_urban_areas, String buildingHeightModelName, String prefixName = "") {
if (!building_estimate) {
error "To estimate the building height a table that contains the list of building to estimate must be provided"
return
Expand All @@ -1382,7 +1384,7 @@ Map estimateBuildingHeight(JdbcDataSource datasource, String zone, String buildi
Map spatialUnits = createUnitsOfAnalysis(datasource, zone,
building, road, rail, vegetation,
water, sea_land_mask, urban_areas, rsu,
surface_vegetation, surface_hydro, snappingTolerance, ["UTRF"],
surface_vegetation, surface_hydro,surface_urban_areas, snappingTolerance, ["UTRF"],
prefixName)
if (!spatialUnits) {
error "Cannot create the spatial units"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ class RsuIndicatorsTests {
def outputTableGeoms = Geoindicators.SpatialUnits.prepareTSUData(h2GIS,
'zone_test', 'road_test', '',
'veget_test', 'hydro_test', "","",
10000, 2500, "prepare_rsu")
10000, 2500,10000, "prepare_rsu")

assertNotNull h2GIS.getTable(outputTableGeoms)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class SpatialUnitsTests {
def outputTableGeoms = Geoindicators.SpatialUnits.prepareTSUData(h2GIS,
'zone_test', 'road_test', 'rail_test',
'veget_test', 'hydro_test', "","",
10000, 2500, "block")
10000, 2500,10000, "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,10000, "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, 10000, "block")


assertNotNull(outputTableGeoms)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -489,15 +489,15 @@ class WorkflowGeoIndicatorsTest {
def checkRSUIndicators(def datasource, def rsuIndicatorsTableName) {
//Check road_fraction > 0
def countResult = datasource.firstRow("select count(*) as count from ${rsuIndicatorsTableName} WHERE ROAD_FRACTION>0".toString())
assertEquals(184, countResult.count)
assertEquals(195, countResult.count)

//Check building_fraction > 0
countResult = datasource.firstRow("select count(*) as count from ${rsuIndicatorsTableName} WHERE BUILDING_FRACTION>0".toString())
assertEquals(70, countResult.count)
assertEquals(73, countResult.count)

//Check high_vegetation_fraction > 0
countResult = datasource.firstRow("select count(*) as count from ${rsuIndicatorsTableName} WHERE high_vegetation_fraction>0".toString())
assertEquals(18, countResult.count)
assertEquals(43, countResult.count)

//Check high_vegetation_water_fraction > 0
countResult = datasource.firstRow("select count(*) as count from ${rsuIndicatorsTableName} WHERE high_vegetation_water_fraction>0".toString())
Expand All @@ -513,7 +513,7 @@ class WorkflowGeoIndicatorsTest {

//Check high_vegetation_road_fraction > 0
countResult = datasource.firstRow("select count(*) as count from ${rsuIndicatorsTableName} WHERE high_vegetation_road_fraction>0".toString())
assertEquals(20, countResult.count)
assertEquals(43, countResult.count)

//Check high_vegetation_impervious_fraction > 0
countResult = datasource.firstRow("select count(*) as count from ${rsuIndicatorsTableName} WHERE high_vegetation_impervious_fraction>0".toString())
Expand All @@ -525,7 +525,7 @@ class WorkflowGeoIndicatorsTest {

//Check low_vegetation_fraction > 0
countResult = datasource.firstRow("select count(*) as count from ${rsuIndicatorsTableName} WHERE low_vegetation_fraction>0".toString())
assertEquals(50, countResult.count)
assertEquals(76, countResult.count)

//Check low_vegetation_fraction > 0
countResult = datasource.firstRow("select count(*) as count from ${rsuIndicatorsTableName} WHERE impervious_fraction>0".toString())
Expand Down
Loading

0 comments on commit e45e679

Please sign in to comment.