Skip to content
Snippets Groups Projects

Implement a dialog to plot and export GPS data

Merged Kien Le requested to merge feature-#19-gps_plotter_q330 into master
1 file
+ 55
58
Compare changes
  • Side-by-side
  • Inline
@@ -336,67 +336,64 @@ class MSeed(DataTypeModel):
# preconditions hold and raise an error if not.
self.check_q330_gps_status_format(log_lines[idx:idx+13])
last_timemark = log_lines[idx+11][19:]
fix_type = log_lines[idx+3][10:]
# If fix type is off, there is no location data available
# so we set them all to 0.
if fix_type == 'OFF':
self.gps_points.append(
GPSPoint(last_timemark, fix_type, 0, 0, 0, 0)
)
continue
if fix_type == 'NONE' and log_lines[idx + 1] == 'Time: ':
self.gps_points.append(
GPSPoint(last_timemark, fix_type, 0, 0, 0, 0)
)
continue
num_sats_used = int(log_lines[idx+8].split(': ')[1])
# Height is encoded as a float followed by the unit. We
# don't know how many characters the unit is composed of,
# so we have to loop through the height string backward
# until we can detect the end of the height value.
height_str: str = log_lines[idx+4].split(': ')[1]
# Start pass the end of the string and look backward one
# index every iteration so we don't have to add 1 to the
# final index.
i = len(height_str)
current_char = height_str[i - 1]
while current_char != '.' and not current_char.isnumeric():
i -= 1
current_char = height_str[i - 1]
height = float(height_str[:i])
# Latitude and longitude are encoded in the format
# <degree><decimal minute><cardinal direction>. For
# latitude, <degree> has two characters, while <degree> for
# longitude has three.
raw_latitude = log_lines[idx+5].split(': ')[1]
lat_degree = int(raw_latitude[:2])
lat_minute = float(raw_latitude[2:-1]) / 60
latitude = lat_degree + lat_minute
if raw_latitude[-1].lower() == 's':
latitude = -latitude
raw_longitude = log_lines[idx+6].split(': ')[1]
long_degree = int(raw_longitude[:3])
long_minute = float(raw_longitude[3:-1]) / 60
longitude = long_degree + long_minute
if raw_longitude[-1].lower() == 's':
longitude = -longitude
# Make latitude and longitude always nonnegative to make
# plotting easier. Latitude ranges from -90 to 90, while
# longitude ranges from -180 to 180.
latitude += 90
longitude += 180
point = self.extract_gps_point(log_lines[idx:idx+12])
print(point)
self.gps_points.append(
GPSPoint(last_timemark, fix_type, num_sats_used,
height, latitude, longitude)
point
)
def extract_gps_point(self, gps_status_lines: List[str]) -> GPSPoint:
print(gps_status_lines)
# Last timemark and fix type are always available, so we have to get
# them before doing anything else.
last_timemark = gps_status_lines[11][19:]
fix_type = gps_status_lines[3][10:]
# If location data is missing, we set them to 0.
if gps_status_lines[5] == 'Latitude: ':
return GPSPoint(last_timemark, fix_type, 0, 0, 0, 0)
num_sats_used = int(gps_status_lines[8].split(': ')[1])
# Height is encoded as a float followed by the unit. We
# don't know how many characters the unit is composed of,
# so we have to loop through the height string backward
# until we can detect the end of the height value.
height_str: str = gps_status_lines[4].split(': ')[1]
# Start pass the end of the string and look backward one
# index every iteration so we don't have to add 1 to the
# final index.
i = len(height_str)
current_char = height_str[i - 1]
while current_char != '.' and not current_char.isnumeric():
i -= 1
current_char = height_str[i - 1]
height = float(height_str[:i])
# Latitude and longitude are encoded in the format
# <degree><decimal minute><cardinal direction>. For
# latitude, <degree> has two characters, while for longitude, <degree>
# has three.
# To make the GPS points easier to plot, we convert the latitude and
# longitude to decimal degree.
raw_latitude = gps_status_lines[5].split(': ')[1]
lat_degree = int(raw_latitude[:2])
lat_minute = float(raw_latitude[2:-1]) / 60
latitude = lat_degree + lat_minute
if raw_latitude[-1].lower() == 's':
latitude = -latitude
raw_longitude = gps_status_lines[6].split(': ')[1]
long_degree = int(raw_longitude[:3])
long_minute = float(raw_longitude[3:-1]) / 60
longitude = long_degree + long_minute
if raw_longitude[-1].lower() == 'w':
longitude = -longitude
gps_point = GPSPoint(last_timemark, fix_type, num_sats_used,
latitude, longitude, height)
return gps_point
@staticmethod
def check_q330_gps_status_format(gps_status_lines: List[str]):
if gps_status_lines[12].lower() != 'pll status':
Loading