Skip to content

Commit 80f3ff6

Browse files
author
Matin Mahmood
committed
Improve error handling and adjust geom definition criteria
- Added a missing return statement to immediately exit the `lonlat_lookup` function when the `refs` column is unavailable, enhancing error resilience. - Modified the minimum number of references required to classify geometries as areas or ways: now considering a sequence as an area if it's closed (first and last refs are the same) and consists of at least 4 points (previously 3), and as a way if it includes at least 2 points (previously 3). This adjustment aligns better with common geometric definitions, ensuring that areas have a more defined shape and ways are simplified. - Replaced a TODO comment with a debug log statement for instances where geometries have less than the intended number of references, improving debuggability and future maintenance. This change aims to enhance the accuracy of geometrical data processing and improve error handling for better stability and clarity in logs.
1 parent 104f3c4 commit 80f3ff6

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

earth_osm/utils.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def lonlat_lookup(df_way, primary_data):
3838
"""
3939
if "refs" not in df_way.columns:
4040
logger.warning("refs column not found")
41+
return []
4142

4243
def look(ref):
4344
lonlat_row = list(map(lambda r: tuple(primary_data["Node"][str(r)]["lonlat"]), ref))
@@ -52,13 +53,12 @@ def way_or_area(df_way):
5253
raise KeyError("refs column not found")
5354

5455
def check_closed(refs):
55-
if (refs[0] == refs[-1]) and (len(refs) >= 3):
56+
if (refs[0] == refs[-1]) and (len(refs) >= 4):
5657
return "area"
57-
elif len(refs) >= 3:
58+
elif len(refs) >= 2:
5859
return "way"
5960
else:
60-
# TODO: improve error handling
61-
# logger.debug(f"Way with less than 3 refs: {refs}")
61+
logger.debug(f"Way with less than 2 refs: {refs}")
6262
return None
6363

6464
type_list = df_way["refs"].apply(check_closed)

0 commit comments

Comments
 (0)