Skip to content

Instantly share code, notes, and snippets.

@PawaritL
Last active July 16, 2021 10:43
Show Gist options
  • Save PawaritL/dc610f1e120447b94b22a44748e61351 to your computer and use it in GitHub Desktop.
Save PawaritL/dc610f1e120447b94b22a44748e61351 to your computer and use it in GitHub Desktop.
Checks if two provided longitude coordinates crosses the antimeridian (180th meridian)
def check_crossing(lon1: float, lon2: float, validate: bool = False, dlon_threshold: float = 180.0):
"""
Assuming a minimum travel distance between two provided longitude coordinates,
checks if the 180th meridian (antimeridian) is crossed.
"""
if validate and any([abs(x) > 180.0 for x in [lon1, lon2]]):
raise ValueError("longitudes must be in degrees [-180.0, 180.0]")
return abs(lon2 - lon1) > dlon_threshold
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment