]> marstr Code Repo - marstr/orthographic.git/commitdiff
Correction in number/float detection for floors, as it caused another crash in overni...
authorMarcus Str. <marcus@marstr.online>
Tue, 4 Feb 2025 07:10:57 +0000 (08:10 +0100)
committerMarcus Str. <marcus@marstr.online>
Tue, 4 Feb 2025 07:10:57 +0000 (08:10 +0100)
osmxml.py

index 3826b0a9c91b8f49b1491d2f9c95ff36eb7fef7b..c90879cad3a15a41d7d35f6a19ad4c2925a4e211 100644 (file)
--- a/osmxml.py
+++ b/osmxml.py
@@ -203,6 +203,19 @@ class mstr_osmxml:
 \r
         # Return the found surface type\r
         return surface\r
+    \r
+\r
+    # Again, a crash on number checking of levels.\r
+    # Short call for sanity check\r
+    def is_float(element: any) -> bool:\r
+        #If you expect None to be passed:\r
+        if element is None: \r
+            return False\r
+        try:\r
+            float(element)\r
+            return True\r
+        except ValueError:\r
+            return False\r
 \r
 \r
     # Find the levels of a building (for shadow rendering)\r
@@ -217,8 +230,9 @@ class mstr_osmxml:
                     a = tag.getAttribute("k")\r
                     v = tag.getAttribute("v")\r
                     if a == "building:levels":\r
-                        lvl = int(float(v)) # <- This blew layergen and maskgen at some buildings with 1.5 floors\r
-                        break\r
+                        if self.is_float(v) == True:\r
+                            lvl = int(float(v)) # <- This blew layergen and maskgen at some buildings with 1.5 floors\r
+                            break\r
         return lvl\r
     \r
     # Find minimum level of a building\r