Created
November 6, 2018 01:31
-
-
Save reportingsjr/65195f67e43f47d8a5200f3b6742d875 to your computer and use it in GitHub Desktop.
Janky data manipulation
This file contains 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 _parse_degrees(nmea_data): | |
# Parse a NMEA lat/long data pair 'dddmm.mmmm' into a pure degrees value. | |
# Where ddd is the degrees, mm.mmmm is the minutes. | |
if nmea_data is None or len(nmea_data) < 3: | |
return None | |
raw_integer_part, raw_fractional_part = nmea_data.split(".") | |
integer_part = int(raw_integer_part) | |
fractional_part = int(raw_fractional_part) | |
# Convert the two parts in to an integer that is shifted left 6 decimals | |
# This gives us the value to 6 decimal places as an integer | |
return ((integer_part // 100) * 10000 + \ | |
((integer_part % 100) * 10000 + fractional_part)/60)*100 | |
To get use what this returns: | |
lat = str(int(gps.latitude)) | |
lng = str(int(gps.longitude)) | |
if lat[0] == '-': | |
print('lat={}.{}'.format(lat[:3],lat[3:])) | |
else: | |
print('lat={}.{}'.format(lat[:2],lat[2:])) | |
if lng[0] == '-': | |
print('lng={}.{}\n'.format(lng[:3],lng[3:])) | |
else: | |
print('lng={}.{}\n'.format(lng[:2],lng[2:])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment