Skip to content

Commit

Permalink
Merge branch 'master' into master_sprawl
Browse files Browse the repository at this point in the history
  • Loading branch information
ebocher authored Mar 14, 2024
2 parents 104b0ee + a2958d4 commit 09ac654
Show file tree
Hide file tree
Showing 9 changed files with 134 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,7 @@ abstract class AbstractBDTopoWorkflow extends BDTopoUtils {
def urban_areas = dataFormated.urban_areas


info "BDTOPO V2 GIS layers formated"
info "BDTOPO GIS layers formated"

def rsu_indicators_params = processing_parameters.rsu_indicators
def worldpop_indicators = processing_parameters.worldpop_indicators
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class WorkflowDebugTest {
@Test
void testIntegrationFolderInput() {
def input_data = "/media/ebocher/Extreme SSD/bdtopo/bdtopo2/BDTOPO_2-2_TOUSTHEMES_SHP_LAMB93_D035_2018-09-25/BDTOPO/1_DONNEES_LIVRAISON_2018-11-00144/BDT_2-2_SHP_LAMB93_D035-ED182"
def locations = ["Gimont"]
def locations = [ "Redon"]
String directory = "/tmp/bdtopo2"
File dirFile = new File(directory)
dirFile.delete()
Expand All @@ -158,20 +158,27 @@ class WorkflowDebugTest {
"parameters" :
["distance" : 0,
rsu_indicators : [
"indicatorUse": ["LCZ"]//, "UTRF"]
"indicatorUse": ["LCZ", "UTRF", "URBAN_TYPOLOGY"]
],
/*"grid_indicators": [
"grid_indicators": [
"x_size" : 1000,
"y_size" : 1000,
"indicators": ["LCZ_FRACTION"]
]*/
"indicators" :["BUILDING_FRACTION", "BUILDING_HEIGHT", "BUILDING_POP",
"BUILDING_TYPE_FRACTION", "WATER_FRACTION", "VEGETATION_FRACTION",
"ROAD_FRACTION", "IMPERVIOUS_FRACTION", "FREE_EXTERNAL_FACADE_DENSITY",
"BUILDING_HEIGHT_WEIGHTED", "BUILDING_SURFACE_DENSITY",
"SEA_LAND_FRACTION", "ASPECT_RATIO", "SVF",
"HEIGHT_OF_ROUGHNESS_ELEMENTS", "TERRAIN_ROUGHNESS_CLASS",
"UTRF_AREA_FRACTION", "UTRF_FLOOR_AREA_FRACTION",
"LCZ_PRIMARY"]
]
]
]
//BDTopo.v2(bdTopoParameters)

input_data = "/home/ebocher/Téléchargements/BDTOPO_3-3_TOUSTHEMES_SHP_LAMB93_D032_2023-09-15/BDTOPO"
input_data = "/media/ebocher/Extreme SSD/bdtopo/bdtopo3/BDTOPO_3-0_TOUSTHEMES_SHP_LAMB93_D035_2022-09-15/BDTOPO"

directory = "/tmp/bdtopo3/result"
directory = "/tmp/bdtopo3"
dirFile = new File(directory)
dirFile.delete()
dirFile.mkdir()
Expand Down
6 changes: 3 additions & 3 deletions common-utils/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback-version}</version>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>${slf4j-version}</version>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.orbisgis.geoclimate.utils

import ch.qos.logback.classic.Level
import ch.qos.logback.classic.LoggerContext
import org.slf4j.Logger
import org.slf4j.LoggerFactory

Expand Down Expand Up @@ -77,20 +75,17 @@ class LoggerUtils {
*/
static void setLoggerLevel(String loggerLevel) {
if (loggerLevel) {
Level level
if (loggerLevel.equalsIgnoreCase("INFO")) {
level = Level.INFO
System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", loggerLevel.toLowerCase())
} else if (loggerLevel.equalsIgnoreCase("DEBUG")) {
level = Level.DEBUG
System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", loggerLevel.toLowerCase())
} else if (loggerLevel.equalsIgnoreCase("TRACE")) {
level = Level.TRACE
System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", loggerLevel.toLowerCase())
} else if (loggerLevel.equalsIgnoreCase("OFF")) {
level = Level.OFF
System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", loggerLevel.toLowerCase())
} else {
throw new RuntimeException("Invalid log level. Allowed values are : INFO, DEBUG, TRACE, OFF")
}
var context = (LoggerContext) LoggerFactory.getILoggerFactory()
context.getLoggerList().each { it -> it.setLevel(level) }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -967,8 +967,8 @@ String upperScaleAreaStatistics(JdbcDataSource datasource, String upperTableName
DROP TABLE IF EXISTS $spatialJoinTable;
CREATE TABLE $spatialJoinTable
AS SELECT b.$upperColumnId, a.$lowerColumnName,
ST_AREA(ST_INTERSECTION(st_force2d(st_makevalid(a.$lowerGeometryColumn)),
st_force2d(st_makevalid(b.$upperGeometryColumn)))) AS area
ST_AREA(ST_INTERSECTION(a.$lowerGeometryColumn,
b.$upperGeometryColumn)) AS area
FROM $lowerTableName a, $upperTableName b
WHERE a.$lowerGeometryColumn && b.$upperGeometryColumn AND
ST_INTERSECTS(a.$lowerGeometryColumn, b.$upperGeometryColumn);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1027,7 +1027,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 urban_areas,
String water, String sea_land_mask, String urban_areas,
String rsu, double surface_vegetation,
double surface_hydro, double surface_urban_areas,
double snappingTolerance, List indicatorUse = ["LCZ", "UTRF", "TEB"], String prefixName = "") {
Expand All @@ -1039,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,surface_urban_areas, prefixName)
surface_hydro, surface_urban_areas, prefixName)
if (!rsu) {
info "Cannot compute the RSU."
return
Expand Down Expand Up @@ -1112,7 +1112,7 @@ Map createUnitsOfAnalysis(JdbcDataSource datasource, String zone, String buildin
*/
Map getParameters() {
return [
"surface_vegetation" : 10000d, "surface_hydro": 2500d, "surface_urban_areas":10000d,
"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 @@ -1210,7 +1210,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 urban_areas, String rsuTable,
String sea_land_mask, String urban_areas, String rsuTable,
Map parameters = [:], String prefixName) {
Map inputParameters = getParameters()
if (parameters) {
Expand Down Expand Up @@ -1241,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_urban_areas,
surface_vegetation, surface_hydro, surface_urban_areas,
snappingTolerance,
buildingHeightModelName, prefixName)
if (!estimHeight) {
Expand Down Expand Up @@ -1330,9 +1330,9 @@ 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,surface_urban_areas, snappingTolerance, indicatorUse,
surface_hydro, surface_urban_areas, snappingTolerance, indicatorUse,
prefixName)
if (!spatialUnits) {
error "Cannot create the spatial units"
Expand Down Expand Up @@ -1368,7 +1368,7 @@ Map estimateBuildingHeight(JdbcDataSource datasource, String zone, String buildi
String road, String rail, String vegetation,
String water, String impervious,
String building_estimate, String sea_land_mask, String urban_areas, String rsu,
double surface_vegetation, double surface_hydro,double surface_urban_areas,
double surface_vegetation, double surface_hydro, double surface_urban_areas,
double snappingTolerance, 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"
Expand All @@ -1384,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,surface_urban_areas, snappingTolerance, ["UTRF"],
surface_vegetation, surface_hydro, surface_urban_areas, snappingTolerance, ["UTRF"],
prefixName)
if (!spatialUnits) {
error "Cannot create the spatial units"
Expand Down Expand Up @@ -1435,7 +1435,7 @@ Map estimateBuildingHeight(JdbcDataSource datasource, String zone, String buildi
prefixName)

def buildingTableName = "BUILDING_TABLE_WITH_RSU_AND_BLOCK_ID"
int nbBuildingEstimated =0
int nbBuildingEstimated = 0
def buildEstimatedHeight
if (datasource.getTable(gatheredScales).isEmpty()) {
info "No building height to estimate"
Expand All @@ -1449,7 +1449,7 @@ Map estimateBuildingHeight(JdbcDataSource datasource, String zone, String buildi
info "Start estimating the building height"
//Apply RF model
buildEstimatedHeight = Geoindicators.TypologyClassification.applyRandomForestModel(datasource,
gatheredScales, buildingHeightModelName,"id_build", prefixName)
gatheredScales, buildingHeightModelName, "id_build", prefixName)
if (!buildEstimatedHeight) {
error "Cannot apply the building height model $buildingHeightModelName"
return
Expand Down Expand Up @@ -1645,6 +1645,9 @@ String rasterizeIndicators(JdbcDataSource datasource,
def grid_column_identifier = "id_grid"
def indicatorTablesToJoin = [:]
indicatorTablesToJoin.put(grid, grid_column_identifier)

//An array to execute some commands on the final table
def sqlUpdateCommand =[]
/*
* Make aggregation process with previous grid and current rsu lcz
*/
Expand Down Expand Up @@ -1845,7 +1848,7 @@ String rasterizeIndicators(JdbcDataSource datasource,
"building_type_fraction")
if (upperScaleAreaStatistics) {
indicatorTablesToJoin.put(upperScaleAreaStatistics, grid_column_identifier)
tablesToDrop<<upperScaleAreaStatistics
tablesToDrop << upperScaleAreaStatistics
} else {
info "Cannot aggregate the building type at grid scale"
}
Expand All @@ -1868,7 +1871,7 @@ String rasterizeIndicators(JdbcDataSource datasource,
if (freeFacadeDensityExact) {
if (list_indicators_upper.intersect(["FREE_EXTERNAL_FACADE_DENSITY", "ASPECT_RATIO"])) {
indicatorTablesToJoin.put(freeFacadeDensityExact, grid_column_identifier)
tablesToDrop<<freeFacadeDensityExact
tablesToDrop << freeFacadeDensityExact
}
if (list_indicators_upper.contains("FREE_EXTERNAL_FACADE_DENSITY")) {
def buildingSurfDensity = Geoindicators.RsuIndicators.buildingSurfaceDensity(
Expand All @@ -1881,8 +1884,8 @@ String rasterizeIndicators(JdbcDataSource datasource,
indicatorTablesToJoin.put(buildingSurfDensity, grid_column_identifier)
}
}
tablesToDrop<<freeFacadeDensityExact
tablesToDrop<<buildingSurfDensity
tablesToDrop << freeFacadeDensityExact
tablesToDrop << buildingSurfDensity
}
} else {
info "Cannot calculate the exact free external facade density"
Expand Down Expand Up @@ -1932,20 +1935,21 @@ String rasterizeIndicators(JdbcDataSource datasource,
}

if (list_indicators_upper.contains("SEA_LAND_FRACTION") && sea_land_mask) {
// If only one type of surface (land or sea) is in the zone, no need for computational fraction calculation
def sea_land_type_rows = datasource.rows("""SELECT $seaLandTypeField, COUNT(*) AS NB_TYPES
if (datasource.getRowCount(sea_land_mask) > 0) {
// If only one type of surface (land or sea) is in the zone, no need for computational fraction calculation
def sea_land_type_rows = datasource.rows("""SELECT $seaLandTypeField, COUNT(*) AS NB_TYPES
FROM $sea_land_mask
GROUP BY $seaLandTypeField""".toString())
if (sea_land_type_rows[seaLandTypeField].count("sea") == 0) {
datasource """
if (sea_land_type_rows[seaLandTypeField].count("sea") == 0) {
datasource """
DROP TABLE IF EXISTS $seaLandFractionTab;
CREATE TABLE $seaLandFractionTab
AS SELECT $grid_column_identifier, 1 AS LAND_FRACTION
FROM $grid"""
indicatorTablesToJoin.put(seaLandFractionTab, grid_column_identifier)
} else {
// Split the potentially big complex seaLand geometries into smaller triangles in order to makes calculation faster
datasource """
indicatorTablesToJoin.put(seaLandFractionTab, grid_column_identifier)
} else {
// Split the potentially big complex seaLand geometries into smaller triangles in order to makes calculation faster
datasource """
DROP TABLE IF EXISTS $tesselatedSeaLandTab;
CREATE TABLE $tesselatedSeaLandTab(id_tesselate serial, the_geom geometry, $seaLandTypeField VARCHAR)
AS SELECT explod_id, the_geom, $seaLandTypeField
Expand All @@ -1954,21 +1958,26 @@ String rasterizeIndicators(JdbcDataSource datasource,
WHERE ST_DIMENSION(the_geom) = 2 AND ST_ISEMPTY(the_geom) IS NOT TRUE
AND ST_AREA(the_geom)>0)')"""

def upperScaleAreaStatistics = Geoindicators.GenericIndicators.upperScaleAreaStatistics(datasource,
grid, grid_column_identifier,
tesselatedSeaLandTab, seaLandTypeField, seaLandTypeField,
prefixName)
tablesToDrop << tesselatedSeaLandTab
if (upperScaleAreaStatistics) {
// Modify columns name to postfix with "_FRACTION"
datasource """
def upperScaleAreaStatistics = Geoindicators.GenericIndicators.upperScaleAreaStatistics(datasource,
grid, grid_column_identifier,
tesselatedSeaLandTab, seaLandTypeField, seaLandTypeField,
prefixName)
tablesToDrop << tesselatedSeaLandTab
if (upperScaleAreaStatistics) {
// Modify columns name to postfix with "_FRACTION"
datasource """
ALTER TABLE ${upperScaleAreaStatistics} RENAME COLUMN TYPE_LAND TO LAND_FRACTION;
ALTER TABLE ${upperScaleAreaStatistics} RENAME COLUMN TYPE_SEA TO SEA_FRACTION;
ALTER TABLE ${upperScaleAreaStatistics} DROP COLUMN THE_GEOM;"""
indicatorTablesToJoin.put(upperScaleAreaStatistics, grid_column_identifier)
} else {
info "Cannot compute the frontal area index."
indicatorTablesToJoin.put(upperScaleAreaStatistics, grid_column_identifier)
} else {
info "Cannot compute the sea land fractions."
}
}
}else{
//Update the final table
sqlUpdateCommand<<"""ALTER TABLE $grid_indicators_table ADD COLUMN LAND_FRACTION DOUBLE PRECISION DEFAULT 1;
ALTER TABLE $grid_indicators_table ADD COLUMN SEA_FRACTION DOUBLE PRECISION DEFAULT 0;"""
}
}

Expand Down Expand Up @@ -2072,6 +2081,9 @@ String rasterizeIndicators(JdbcDataSource datasource,
UPDATE $grid_indicators_table SET ASPECT_RATIO = case when building_fraction = 1 then null else free_external_facade_density / (1 - building_fraction) end
""".toString())
}
//Execute commands
datasource.execute(sqlUpdateCommand.join(" "))

tablesToDrop << createScalesRelationsGridBl
tablesToDrop << buildingCutted

Expand All @@ -2098,7 +2110,7 @@ String cutBuilding(JdbcDataSource datasource, String grid, String building) {
DROP TABLE IF EXISTS $buildingCutted;
CREATE TABLE $buildingCutted as
SELECT *, ST_AREA(THE_GEOM) AS area from
(SELECT a.* EXCEPT(the_geom), st_intersection(a.the_geom, b.the_geom) as the_geom, b.* EXCEPT(the_geom),
(SELECT a.* EXCEPT(the_geom), ST_CollectionExtract(st_intersection(a.the_geom, b.the_geom), 3) as the_geom, b.* EXCEPT(the_geom),
(b.HEIGHT_WALL + b.HEIGHT_ROOF) / 2 AS BUILD_HEIGHT
FROM $grid as a, $building as b where a.the_geom && b.the_geom and st_intersects(a.the_geom, b.the_geom))
as foo
Expand Down
Loading

0 comments on commit 09ac654

Please sign in to comment.