Ejemplo n.º 1
0
 def listGpxInBox(self, bounds, ifrom=None, iend=None):
     latm = bounds['_southWest']['lat']
     latM = bounds['_northEast']['lat']
     lngm = bounds['_southWest']['lng']
     lngM = bounds['_northEast']['lng']
     res = []
     for p in sorted(glob.glob(self.gpx_cwd + '/*.gpx'))[slice(ifrom,
                                                               iend)]:
         print(p)
         glatm, glatM, glngm, glngM = self.getGpxBounds(p)
         # surely out of the box
         if glatM < latm or glatm > latM or glngM < lngm or glngm > lngM:
             continue
         # surely in the box
         if latm < glatm < glatM < latM and lngm < glngm < glngM < lngM:
             res.append(p)
             continue
         # need fine evaluation
         try:
             with open(p, 'r') as gpx_file:
                 gpx = gpx_parser.parse(gpx_file)
             for (point, t, s, i) in gpx.walk():
                 if latm < point.latitude < latM and lngm < point.longitude < lngM:
                     res.append(p)
                     break
         except BaseException as e:
             print("Failed with", p, e)
     self.maybe_save_gpxbounds_cache()
     self.all_gpx = res
Ejemplo n.º 2
0
def add_points(agg, step, gpx_path):
    with open(gpx_path, 'r') as gpx_file:
        gpx = parser.parse(gpx_file)
    prev = None
    for (point, t, s, i) in gpx.walk():
        #if prev is None:
            y = int(point.latitude / step)
            x = int(point.longitude / step)
            agg[y, x] += 1
Ejemplo n.º 3
0
 def getGpxBounds(self, p):
     if p in self.gpxbounds_cache:
         return self.gpxbounds_cache[p]
     res = 0, 0, 0, 0
     try:
         with open(p, 'r') as gpx_file:
             gpx = gpx_parser.parse(gpx_file)
             res = gpx.get_bounds()
     except BaseException as e:
         print("Failed with", p, e)
     self.gpxbounds_cache[p] = res
     self.gpxbounds_cache_needs_saving = True
     return res
Ejemplo n.º 4
0
def getCoords(gpx_filename):
    coord_list = []

    with open(gpx_filename, 'r') as gpx_file:
        gpx = parser.parse(gpx_file)
        print("{} tracks loaded".format(len(gpx)))

        for track in gpx:
            print('Track with {} segments and {} points'.format(
                len(track), track.get_points_no()))
            for segment in track:
                print('Segment with %s points % len(segment)')
                for point in segment:
                    coord_list.append(point)

    return coord_list
Ejemplo n.º 5
0
    def __generate_from_gpx_file(arg_input_file: os.DirEntry,
                                 arg_output_path: str):
        logger.info("Generating GPS output file: " + arg_output_path +
                    " from input file: " + arg_input_file.path)
        return_value = True
        input_file_object = open(arg_input_file.path, 'r')
        gpx_data = gpx_parser.parse(input_file_object)

        with open(arg_output_path, 'w', newline='') as output_file:
            output_writer = csv.writer(output_file)
            for track in gpx_data.tracks:
                for segment in track.segments:
                    for point in segment.points:
                        output_writer.writerow([
                            point.time.strftime("%Y%m%d_%H_%M_%S_%f"),
                            point.latitude, point.longitude, point.speed,
                            point.horizontal_dilution, point.satellites
                        ])
        return return_value
Ejemplo n.º 6
0
def gpx_to_json(gpx_file, json_file):
    lookup = {}

    with open(gpx_file, 'r') as f:
        gpx = parser.parse(f)
        points = gpx[0].points

        for i in range(len(points)):
            key = int(points[i].time.replace(tzinfo=timezone.utc).timestamp())
            lookup[key] = {}
            lookup[key]["latitude"] = points[i].latitude
            lookup[key]["longitude"] = points[i].longitude

            if i < len(points) - 1:
                lookup[key]["speed_m_s"] = points[i].speed_between(points[i +
                                                                          1])
            else:
                lookup[key]["speed_m_s"] = points[i - 1].speed_between(
                    points[i])

    with open(json_file, "w") as j:
        json.dump(lookup, j)
Ejemplo n.º 7
0
def ParseGPX(path):
    with open(path, "r") as gpx_file:
        gpx = parser.parse(gpx_file)

    return gpx
Ejemplo n.º 8
0
def parse_gpx_file(filename):
    with open(filename, 'r') as gpx_file:
        gpx = parser.parse(gpx_file)
    return gpx
plt.imshow(rgb)

track_list = []
distList = []
dur_list = []
# Single column file containing list of track files
track_list_file = './tracks/track_list.txt'
with open(track_list_file) as fp:
    for cnt, line in enumerate(fp):
        track_list.append(line.strip(' \r\n'))

# GPX files are assumed to contain only one track segment - only reading first
for gpx_file_name in track_list:
    gpx_path = './tracks/' + gpx_file_name
    with open(gpx_path, 'r') as gpx_file:
        gpx = parser.parse(gpx_file)
        distM = gpx.length_2d()
        distList.append(distM)

        time_bounds = gpx.get_time_bounds()
        dur = time_bounds[-1] - time_bounds[0]
        dur_list.append(dur)

    # Test whether track is inside image boundary and exclude if not
    track_bound = gpx.get_bounds()
    top = img_bound[0] < track_bound[0] < img_bound[1]
    bottom = img_bound[0] < track_bound[1] < img_bound[1]
    left = img_bound[2] < track_bound[2] < img_bound[3]
    right = img_bound[2] < track_bound[3] < img_bound[3]
    if top and bottom and left and right:
        show_track = True
Ejemplo n.º 10
0
def loadgpx():
    with open('input/test.gpx', 'r') as gpx_file:
        gpx = parser.parse(gpx_file)
        print("{} tracks loaded".format(len(gpx)))
    return gpx