Created
May 23, 2019 01:00
-
-
Save travishathaway/3d4f7be277a33367b95a697c4d86a6de to your computer and use it in GitHub Desktop.
Convert Degree Minutes to Decimal Degrees
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def convert_degree_dec_min_to_degree_dec(degree_dec_min: str): | |
""" | |
Converts a string that looks like this: | |
- "12238.2974W" | |
To this: | |
- -122.63829 | |
In other words, it converts the "Degrees and Decimal Minutes" format | |
to "Degree Decimals" | |
More information here: https://www.maptools.com/tutorials/lat_lon/formats | |
:param degree_dec_min: A string in the Degree and Decimal Minutes format | |
:return: A float in the Degree Decimals format or None | |
""" | |
try: | |
is_negative = 'W' in degree_dec_min or 'S' in degree_dec_min | |
minutes = float(degree_dec_min[-8:-1]) / 60 | |
dd = float(degree_dec_min[:-8]) + minutes | |
if is_negative: | |
return dd * -1 | |
else: | |
return dd | |
except (ValueError, IndexError): | |
return |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment