Skip to content

Commit

Permalink
Improve error handling and adjust geom definition criteria
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
mnm-matin committed Mar 3, 2024
1 parent 104f3c4 commit 80f3ff6
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions earth_osm/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def lonlat_lookup(df_way, primary_data):
"""
if "refs" not in df_way.columns:
logger.warning("refs column not found")
return []

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

def check_closed(refs):
if (refs[0] == refs[-1]) and (len(refs) >= 3):
if (refs[0] == refs[-1]) and (len(refs) >= 4):
return "area"
elif len(refs) >= 3:
elif len(refs) >= 2:
return "way"
else:
# TODO: improve error handling
# logger.debug(f"Way with less than 3 refs: {refs}")
logger.debug(f"Way with less than 2 refs: {refs}")
return None

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

0 comments on commit 80f3ff6

Please sign in to comment.