Skip to content

Instantly share code, notes, and snippets.

@brews
Last active May 3, 2023 23:30
Show Gist options
  • Save brews/cb0fa9a81d5388b590de3aa441105dad to your computer and use it in GitHub Desktop.
Save brews/cb0fa9a81d5388b590de3aa441105dad to your computer and use it in GitHub Desktop.
Convert 0 - 360 longitude to -180 - 180 longitude or -180 - 180 to 0 - 360 longitude in Python
def lon360to180(lon):
return (lon + 180.0) % 360.0 - 180.0
# The inverse going from -180 - 180 to 0 - 360 is
def lon180to360(lon):
return lon % 360.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment