From 5adb6733ef444710d96f834b9c8bc443dcce25be Mon Sep 17 00:00:00 2001 From: "Marcus Str." Date: Tue, 4 Feb 2025 08:10:57 +0100 Subject: [PATCH] Correction in number/float detection for floors, as it caused another crash in overnight rendering. --- osmxml.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/osmxml.py b/osmxml.py index 3826b0a..c90879c 100644 --- a/osmxml.py +++ b/osmxml.py @@ -203,6 +203,19 @@ class mstr_osmxml: # Return the found surface type return surface + + + # Again, a crash on number checking of levels. + # Short call for sanity check + def is_float(element: any) -> bool: + #If you expect None to be passed: + if element is None: + return False + try: + float(element) + return True + except ValueError: + return False # Find the levels of a building (for shadow rendering) @@ -217,8 +230,9 @@ class mstr_osmxml: a = tag.getAttribute("k") v = tag.getAttribute("v") if a == "building:levels": - lvl = int(float(v)) # <- This blew layergen and maskgen at some buildings with 1.5 floors - break + if self.is_float(v) == True: + lvl = int(float(v)) # <- This blew layergen and maskgen at some buildings with 1.5 floors + break return lvl # Find minimum level of a building