Exemple #1
0
    def _gps_item(self, data=None) -> Optional[GPS]:
        if data is not None:
            tags_data = data
        else:
            tags_data = self._all_tags()
        gps = GPS()
        # required gps timestamp or exif timestamp
        gps.timestamp = gps_timestamp(tags_data)
        exif_timestamp = timestamp(tags_data)
        if (not gps.timestamp or
                (exif_timestamp is not None and exif_timestamp > 31556952
                 and abs(gps.timestamp - exif_timestamp) > 31556952)):
            # if there is no gps timestamp or gps timestamp differs with more then 1 year compared to exif_timestamp we
            # choose exif_timestamp
            gps.timestamp = exif_timestamp

        # required latitude and longitude
        gps.latitude = gps_latitude(tags_data)
        gps.longitude = gps_longitude(tags_data)
        if not gps.latitude or \
                not gps.longitude or \
                not gps.timestamp:
            return None

        # optional data
        gps.speed = gps_speed(tags_data)
        gps.altitude = gps_altitude(tags_data)
        return gps
Exemple #2
0
 def waylens_device(gps: GPS):
     """this function fixes an error for waylens metadata when gps speed is logged in m/s"""
     timestamp_error(gps)
     if "waylens" in device_item.device_raw_name:
         gps.speed = str(float(gps.speed) / 3.6)
     gps.latitude = float(gps.latitude)
     gps.longitude = float(gps.longitude)
     gps.horizontal_accuracy = float(gps.horizontal_accuracy)
     if gps.altitude is not None:
         gps.altitude = float(gps.altitude)
     if gps.vertical_accuracy is not None:
         gps.vertical_accuracy = float(gps.vertical_accuracy)
     if gps.speed is not None:
         gps.speed = float(gps.speed)
Exemple #3
0
 def items(self) -> List[SensorItem]:
     with open(self.file_path, 'r') as gpx_file:
         gpx = gpxpy.parse(gpx_file)
         sensors: List[SensorItem] = []
         for track in gpx.tracks:
             for segment in track.segments:
                 for point in segment.points:
                     gps = GPS()
                     gps.speed = point.speed
                     gps.timestamp = point.time.timestamp()
                     gps.latitude = point.latitude
                     gps.longitude = point.longitude
                     gps.altitude = point.elevation
                     sensors.append(gps)
         return sensors
Exemple #4
0
 def next_item(self) -> Optional[SensorItem]:
     with open(self.file_path, 'r') as gpx_file:
         gpx = gpxpy.parse(gpx_file)
         index = 0
         for track in gpx.tracks:
             for segment in track.segments:
                 for point in segment.points:
                     if index == self._data_pointer:
                         gps = GPS()
                         gps.speed = point.speed
                         gps.timestamp = point.time.timestamp()
                         gps.latitude = point.latitude
                         gps.longitude = point.longitude
                         gps.altitude = point.elevation
                         self._data_pointer += 1
                         return gps
     return None
Exemple #5
0
    def items(self) -> List[SensorItem]:
        with self._storage.open(self.file_path, 'r') as geo_json_file:
            geo_json = load(geo_json_file)
            index = 0
            sensors: List[SensorItem] = []
            for feature in geo_json["features"]:
                geometry = feature["geometry"]
                coordinates = geometry["coordinates"]

                for geometry_coordinate in coordinates:
                    if isinstance(geometry_coordinate,
                                  float) and len(coordinates) == 2:
                        # this is a point
                        gps = GPS()
                        gps.timestamp = time.time() + index
                        gps.latitude = coordinates[1]
                        gps.longitude = coordinates[0]
                        sensors.append(gps)
                        break
                    elif isinstance(geometry_coordinate[0],
                                    float) and len(geometry_coordinate) == 2:
                        # this is a list of points
                        longitude = geometry_coordinate[0]
                        latitude = geometry_coordinate[1]
                        gps = GPS()
                        gps.timestamp = time.time() + index
                        gps.latitude = latitude
                        gps.longitude = longitude
                        sensors.append(gps)
                        index += 1
                    else:
                        # this is a list of list of points
                        for geometry_point_coordinate in geometry_coordinate[
                                0]:
                            longitude = geometry_point_coordinate[0]
                            latitude = geometry_point_coordinate[1]
                            gps = GPS()
                            gps.timestamp = time.time() + index
                            gps.latitude = latitude
                            gps.longitude = longitude
                            sensors.append(gps)
                            index += 1
        return sensors