From 6e46d9815fa554a7f331756a49175031d0fb4502 Mon Sep 17 00:00:00 2001 From: nicolas-f Date: Wed, 19 Feb 2025 16:54:00 +0100 Subject: [PATCH] fix import of non buildings as buildings --- .../wps/Import_and_Export/Import_OSM.groovy | 53 +++++++++---------- 1 file changed, 26 insertions(+), 27 deletions(-) diff --git a/wps_scripts/src/main/groovy/org/noise_planet/noisemodelling/wps/Import_and_Export/Import_OSM.groovy b/wps_scripts/src/main/groovy/org/noise_planet/noisemodelling/wps/Import_and_Export/Import_OSM.groovy index 156e6c079..0cc882302 100644 --- a/wps_scripts/src/main/groovy/org/noise_planet/noisemodelling/wps/Import_and_Export/Import_OSM.groovy +++ b/wps_scripts/src/main/groovy/org/noise_planet/noisemodelling/wps/Import_and_Export/Import_OSM.groovy @@ -393,6 +393,7 @@ public class OsmHandler implements Sink { boolean ignoreRoads boolean ignoreGround boolean removeTunnels + Object parametersMap OsmHandler(Logger logger, boolean ignoreBuildings, boolean ignoreRoads, boolean ignoreGround, boolean removeTunnels) { this.logger = logger @@ -400,26 +401,9 @@ public class OsmHandler implements Sink { this.ignoreRoads = ignoreRoads this.ignoreGround = ignoreGround this.removeTunnels = removeTunnels - } - - @Override - public void initialize(Map arg0) { - } - - @Override - public void process(EntityContainer entityContainer) { - - - - if (entityContainer instanceof NodeContainer) { - nb_nodes++; - Node node = ((NodeContainer) entityContainer).getEntity(); - nodes.put(node.getId(), node); - } else if (entityContainer instanceof WayContainer) { - - // This is a copy of the GeoClimate file : buildingsParams.json (https://github.com/orbisgis/geoclimate/tree/master/osm/src/main/resources/org/orbisgis/geoclimate/osm) - String buildingParams = """{ + // This is a copy of the GeoClimate file : buildingsParams.json (https://github.com/orbisgis/geoclimate/tree/master/osm/src/main/resources/org/orbisgis/geoclimate/osm) + String buildingParams = """{ "tags": { "building": [], "railway": [ @@ -1081,8 +1065,21 @@ public class OsmHandler implements Sink { } } }""" + this.parametersMap = new JsonSlurper().parseText(buildingParams) + + } + + @Override + public void initialize(Map arg0) { + } - def parametersMap = new JsonSlurper().parseText(buildingParams) + @Override + public void process(EntityContainer entityContainer) { + if (entityContainer instanceof NodeContainer) { + nb_nodes++; + Node node = ((NodeContainer) entityContainer).getEntity(); + nodes.put(node.getId(), node); + } else if (entityContainer instanceof WayContainer) { def tags = parametersMap.get("tags") def columnsToKeep = parametersMap.get("columns") def typeBuildings = parametersMap.get("type") @@ -1105,15 +1102,17 @@ public class OsmHandler implements Sink { } } - if ( closedWay && columnsToKeep.any{ (it == tag.getKey()) }) { - for (typeHighLevel in typeBuildings) { - for (typeLowLevel in typeHighLevel.getValue()) { - if (typeLowLevel.getKey() == (tag.getKey())) { - if (typeLowLevel.getValue().any { it == (tag.getValue()) }) { - isBuilding = true; + if(!isBuilding) { + if (closedWay && columnsToKeep.any { (it == tag.getKey()) }) { + for (typeHighLevel in typeBuildings) { + for (typeLowLevel in typeHighLevel.getValue()) { + if (typeLowLevel.getKey() == (tag.getKey())) { + if (typeLowLevel.getValue().any { it == (tag.getValue()) }) { + // some amenity designate an area but this it not a building + isBuilding = way.getTags().any({ Tag it -> (it.key.startsWith("building")) }) + } } } - } } }