From e5454c21d5aa4a7467555393bf2f23560bc0e79c Mon Sep 17 00:00:00 2001 From: ebocher Date: Fri, 21 Jun 2024 16:15:03 +0200 Subject: [PATCH] Better building formating --- .../geoclimate/osm/InputDataFormatting.groovy | 55 ++++++++++--------- .../geoclimate/osm/WorflowOSMTest.groovy | 5 +- 2 files changed, 31 insertions(+), 29 deletions(-) diff --git a/osm/src/main/groovy/org/orbisgis/geoclimate/osm/InputDataFormatting.groovy b/osm/src/main/groovy/org/orbisgis/geoclimate/osm/InputDataFormatting.groovy index fe8a6d77f3..94e212e972 100644 --- a/osm/src/main/groovy/org/orbisgis/geoclimate/osm/InputDataFormatting.groovy +++ b/osm/src/main/groovy/org/orbisgis/geoclimate/osm/InputDataFormatting.groovy @@ -105,6 +105,7 @@ Map formatBuildingLayer(JdbcDataSource datasource, String building, String zone for (int i = 0; i < geom.getNumGeometries(); i++) { Geometry subGeom = geom.getGeometryN(i) if (subGeom instanceof Polygon && subGeom.getArea() > 1) { + subGeom.normalize() stmt.addBatch """ INSERT INTO ${outputTableName} values( ST_GEOMFROMTEXT('${subGeom}',$srid), @@ -138,27 +139,29 @@ Map formatBuildingLayer(JdbcDataSource datasource, String building, String zone def id_build = 1; datasource.withBatch(100) { stmt -> datasource.eachRow(queryMapper) { row -> - def typeAndUseValues = getTypeAndUse(row, columnNames, mappingTypeAndUse) - def use = typeAndUseValues[1] - def type = typeAndUseValues[0] - if (type) { - String height = row.height - String roof_height = row.'roof:height' - String b_lev = row.'building:levels' - String roof_lev = row.'roof:levels' - def heightRoof = getHeightRoof(height, heightPattern) - def heightWall = getHeightWall(heightRoof, roof_height) - def nbLevels = getNbLevels(b_lev, roof_lev) - def formatedHeight = Geoindicators.WorkflowGeoIndicators.formatHeightsAndNbLevels(heightWall, heightRoof, nbLevels, h_lev_min, type, typeAndLevel) - def zIndex = getZIndex(row.'layer') - String roof_shape = row.'roof:shape' - if (formatedHeight.nbLevels > 0 && zIndex >= 0 && type) { - Geometry geom = row.the_geom - def srid = geom.getSRID() - for (int i = 0; i < geom.getNumGeometries(); i++) { - Geometry subGeom = geom.getGeometryN(i) - if (subGeom instanceof Polygon && subGeom.getArea() > 1) { - stmt.addBatch """ + Geometry geom = row.the_geom + if(geom) { + def typeAndUseValues = getTypeAndUse(row, columnNames, mappingTypeAndUse) + def use = typeAndUseValues[1] + def type = typeAndUseValues[0] + if (type) { + String height = row.height + String roof_height = row.'roof:height' + String b_lev = row.'building:levels' + String roof_lev = row.'roof:levels' + def heightRoof = getHeightRoof(height, heightPattern) + def heightWall = getHeightWall(heightRoof, roof_height) + def nbLevels = getNbLevels(b_lev, roof_lev) + def formatedHeight = Geoindicators.WorkflowGeoIndicators.formatHeightsAndNbLevels(heightWall, heightRoof, nbLevels, h_lev_min, type, typeAndLevel) + def zIndex = getZIndex(row.'layer') + String roof_shape = row.'roof:shape' + if (formatedHeight.nbLevels > 0 && zIndex >= 0 && type) { + def srid = geom.getSRID() + for (int i = 0; i < geom.getNumGeometries(); i++) { + Geometry subGeom = geom.getGeometryN(i) + if (subGeom instanceof Polygon && subGeom.getArea() > 1) { + subGeom.normalize() + stmt.addBatch """ INSERT INTO ${outputTableName} values( ST_GEOMFROMTEXT('${subGeom}',$srid), $id_build, @@ -172,14 +175,15 @@ Map formatBuildingLayer(JdbcDataSource datasource, String building, String zone ${roof_shape ? "'" + roof_shape + "'" : null}) """.toString() - if (formatedHeight.estimated) { - stmt.addBatch """ + if (formatedHeight.estimated) { + stmt.addBatch """ INSERT INTO ${outputEstimateTableName} values( $id_build, '${row.id}') """.toString() + } + id_build++ } - id_build++ } } } @@ -205,7 +209,8 @@ Map formatBuildingLayer(JdbcDataSource datasource, String building, String zone 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 + 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'; CREATE INDEX ON $urbanAreasPart(id_build); create table $buildinType as select diff --git a/osm/src/test/groovy/org/orbisgis/geoclimate/osm/WorflowOSMTest.groovy b/osm/src/test/groovy/org/orbisgis/geoclimate/osm/WorflowOSMTest.groovy index f62e40c7a2..f0e7932c3c 100644 --- a/osm/src/test/groovy/org/orbisgis/geoclimate/osm/WorflowOSMTest.groovy +++ b/osm/src/test/groovy/org/orbisgis/geoclimate/osm/WorflowOSMTest.groovy @@ -654,10 +654,7 @@ class WorflowOSMTest extends WorkflowAbstractTest { def grid_size = 250 //location = nominatim.bbox //location=[46.178404,6.095524,46.222959,6.190109] - location =[ 48.84017284026897, - 2.3061887733275785, - 48.878115442982086, - 2.36742047202511] + location =[49.260483, 6.015968, 49.415665, 6.2368684] def osm_parmeters = [ "description" : "Example of configuration file to run the OSM workflow and store the result in a folder", "geoclimatedb": [