Skip to content

Instantly share code, notes, and snippets.

@Jxck-S
Created February 14, 2024 20:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jxck-S/f8909c15a267be20da1b9ed3dada4e85 to your computer and use it in GitHub Desktop.
Save Jxck-S/f8909c15a267be20da1b9ed3dada4e85 to your computer and use it in GitHub Desktop.
Python Coordinate Tools.
def standardize_longitude(longitude):
while longitude < -180:
longitude += 360
while longitude > 180:
longitude -= 360
return longitude
def standardize_latitude(latitude):
while latitude < -90:
latitude += 180
while latitude > 90:
latitude -= 180
return latitude
def crosses_prime_meridian(lon2, lon1):
if abs(lon1 - lon2) > 180:
return False
else:
return (lon1 < 0 and lon2 > 0) or (lon1 > 0 and lon2 < 0)
def crosses_idl(longitude1, longitude2):
"""
This function checks if a path from longitude1 to longitude2 crosses the International Date Line.
Args:
longitude1 (float): The longitude of the first point.
longitude2 (float): The longitude of the second point.
Returns:
bool: True if the path crosses the International Date Line, False otherwise.
"""
# If the absolute difference between the two longitudes is greater than 180,
# it means the shortest path crosses the International Date Line.
return abs(longitude1 - longitude2) > 180
# Test the function with your example
# print(crosses_idl(176.10410748771642, -175.78437775630897)) # Output: True
# print(crosses_prime_meridian(176.10410748771642,-175.78437775630897 ))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment