Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce the time to format the building when the urban areas are used #984

Merged
merged 1 commit into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -203,15 +203,15 @@ Map formatBuildingLayer(JdbcDataSource datasource, String building, String zone
//Tessellate the urban_areas to perform the intersection on large geometry
datasource.execute("""DROP TABLE IF EXISTS $triangles;
CREATE TABLE $triangles as
SELECT * FROM st_explode('(SELECT CASE WHEN ST_AREA(THE_GEOM) > 100000
THEN ST_Tessellate(st_snaptoself(the_geom, -0.001)) ELSE THE_GEOM END AS THE_GEOM,
SELECT * FROM st_explode('(SELECT CASE WHEN ST_NPoints(THE_GEOM) > 2500
THEN st_subdivide(the_geom, 2500) ELSE THE_GEOM END AS THE_GEOM,
type FROM $urban_areas)')""".toString())
datasource.createSpatialIndex(triangles)

datasource.execute """DROP TABLE IF EXISTS $urbanAreasPart, $buildinType ;
CREATE TABLE $urbanAreasPart as SELECT b.type, a.id_build, st_area(st_intersection(a.the_geom,b.the_geom))/st_area(a.the_geom) as part
FROM $outputTableName a, $triangles b
WHERE a.the_geom && b.the_geom and st_intersects(a.the_geom, b.the_geom) AND a.TYPE ='building';
WHERE a.the_geom && b.the_geom and st_intersects(st_buffer(a.the_geom, 0), b.the_geom) AND a.TYPE ='building';
CREATE INDEX ON $urbanAreasPart(id_build);
create table $buildinType as select
MAX(part) FILTER (WHERE type = 'residential') as "residential",
Expand Down Expand Up @@ -1046,36 +1046,38 @@ String formatUrbanAreas(JdbcDataSource datasource, String urban_areas, String zo
queryMapper += columnsMapper(columnNames, columnToMap)
if (zone) {
datasource.createSpatialIndex(urban_areas)
queryMapper += ", st_intersection(a.the_geom, b.the_geom) as the_geom " +
queryMapper += ", st_snaptoself(st_intersection(a.the_geom, b.the_geom), -0.001) as the_geom " +
"FROM " +
"$urban_areas AS a, $zone AS b " +
"WHERE " +
"a.the_geom && b.the_geom "
} else {
queryMapper += ", a.the_geom as the_geom FROM $urban_areas as a"
queryMapper += ", st_snaptoself(a.the_geom, -0.001) as the_geom FROM $urban_areas as a"

}
def constructions = ["industrial", "commercial", "residential"]
int rowcount = 1
datasource.withBatch(100) { stmt ->
datasource.eachRow(queryMapper) { row ->
if (!row.building) {
def typeAndUseValues = getTypeAndUse(row, columnNames, mappingType)
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
Geometry geom = row.the_geom
if(geom) {
if (!row.building) {
def typeAndUseValues = getTypeAndUse(row, columnNames, mappingType)
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
}
}
}
if (type) {
Geometry geom = row.the_geom
int epsg = geom.getSRID()
for (int i = 0; i < geom.getNumGeometries(); i++) {
Geometry subGeom = geom.getGeometryN(i)
if (subGeom instanceof Polygon && subGeom.getArea() > 1) {
stmt.addBatch "insert into $outputTableName values(ST_GEOMFROMTEXT('${subGeom}',$epsg), ${rowcount++}, '${row.id}', ${singleQuote(type)})".toString()
if (type) {
int epsg = geom.getSRID()
for (int i = 0; i < geom.getNumGeometries(); i++) {
Geometry subGeom = geom.getGeometryN(i)
if (subGeom instanceof Polygon && subGeom.getArea() > 1) {
stmt.addBatch "insert into $outputTableName values(ST_GEOMFROMTEXT('${subGeom}',$epsg), ${rowcount++}, '${row.id}', ${singleQuote(type)})".toString()
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,12 +288,12 @@ class InputDataFormattingTest {
}

def h2GIS = H2GIS.open("${file.absolutePath + File.separator}osm_gislayers;AUTO_SERVER=TRUE".toString())
def zoneToExtract = "Nimes"
def zoneToExtract = "Lorient"

//def nominatim = org.orbisgis.geoclimate.osmtools.OSMTools.Utilities.getNominatimData(zoneToExtract)
// zoneToExtract = nominatim.bbox

zoneToExtract = [62.2, 28.2, 62.4, 28.4]
//zoneToExtract = [62.2, 28.2, 62.4, 28.4]

//zoneToExtract =[44.795480,12.323227,45.004622,12.627411]
Map extractData = OSM.InputDataLoading.extractAndCreateGISLayers(h2GIS, zoneToExtract)
Expand Down Expand Up @@ -321,7 +321,7 @@ class InputDataFormattingTest {

//Buildings
def inputBuildings = OSM.InputDataFormatting.formatBuildingLayer(h2GIS,
extractData.building,extractData.zone,null)
extractData.building,extractData.zone,inputUrbanAreas)
h2GIS.save(inputBuildings.building,"${file.absolutePath + File.separator}building.fgb", true)

println("Building formatted")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ class WorflowOSMTest extends WorkflowAbstractTest {
def grid_size = 250
//location = nominatim.bbox
//location=[46.178404,6.095524,46.222959,6.190109]
location =[49.260483, 6.015968, 49.415665, 6.2368684]
//location =[47.693558, -3.5087318, 47.814945, -3.284718]
def osm_parmeters = [
"description" : "Example of configuration file to run the OSM workflow and store the result in a folder",
"geoclimatedb": [
Expand All @@ -675,7 +675,7 @@ class WorflowOSMTest extends WorkflowAbstractTest {
"parameters" :
["distance" : 0,
"rsu_indicators" : [
"indicatorUse": ["LCZ", "TEB"] //, "UTRF"]
"indicatorUse": ["LCZ"]//, "TEB"] //, "UTRF"]

], /*"grid_indicators" : [
"x_size" : grid_size,
Expand Down
Loading