From c06571d347a609845ba3351ab735c016a02a13ed Mon Sep 17 00:00:00 2001 From: ebocher Date: Tue, 9 Jan 2024 15:27:14 +0100 Subject: [PATCH] Fix #896 --- .../geoclimate/osm/InputDataFormatting.groovy | 34 ++++++++++--------- 1 file changed, 18 insertions(+), 16 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 8992bb21a3..3f2c393a4b 100644 --- a/osm/src/main/groovy/org/orbisgis/geoclimate/osm/InputDataFormatting.groovy +++ b/osm/src/main/groovy/org/orbisgis/geoclimate/osm/InputDataFormatting.groovy @@ -177,24 +177,26 @@ Map formatBuildingLayer(JdbcDataSource datasource, String building, String zone if(mapTypes.size()==1){ new_type= mapTypes.keySet().stream().findFirst().get() }else { - String maxKeyType = mapTypes.max { it.value }.key - def sortValues = mapTypes.sort { -it.value }.keySet() - sortValues.remove(maxKeyType) - switch (maxKeyType) { - case "residential": - if (sortValues.contains("education")) { + def maxType = mapTypes.max { it.value } + if(maxType){ + String maxKeyType = maxType.key + def sortValues = mapTypes.sort { -it.value }.keySet() + sortValues.remove(maxKeyType) + switch (maxKeyType) { + case "residential": + if (sortValues.contains("education")) { + new_type = "education" + } else { + new_type = sortValues.take(1)[0] + } + break + case "education": new_type = "education" - } - else { + break + default: new_type = sortValues.take(1)[0] - } - break - case "education": - new_type="education" - break - default: - new_type = sortValues.take(1)[0] - break + break + } } }