Details for overland-to-gpx.ipynb

Published by gedankenstuecke

Description

Convert your Overland data (which is in GeoJSON format) to GPX format, allowing you to use the data e.g. in Google Earth!

0

Tags & Data Sources

GPS location data location movement maps mapping Overland connection

Comments

Please log in to comment.

Notebook
Last updated 3 months, 1 week ago

Turn Overland GeoJSON into GPX Tracks

With the Overland iOS app and its integration into Open Humans you can collect GPS records of yourselves as fine or coarse as you prefer. By default the integration stores your data as GeoJSON files which contain all records for a given month on Open Humans.

But while GeoJSON is great for many web-based tools to read and use the data, other software that you might want to run locally (e.g. Google Earth) want to get the data as GPX. This notebook will take all of your Overland data sets and turn them into GPX files.

The waypoints that Overland saves are transformed into Tracks, so that you can more easily visualize your movement. Your files will be stored in a folder called gpx/ on your notebook server.

Converting the files

First, we define some functions which take a given monthly file, read it, and then transform it. Then we get the list of all Overland files from Open Humans, convert the and store them in the gpx/ folder.

Running the cell below can take some time, depending on how much data Overland has collected so far:

In [1]:
import os
from ohapi import api
import json
import requests
import glob 

# create path for gpx files if non-existent 
if not os.path.exists('gpx/'):
    os.mkdir('gpx/')


def read_geojson(f_object):
    '''
    read geojson from overland based on OH API output
    '''
    geo_json = requests.get(f_object['download_url']).json()
    return geo_json

def write_gpx(geo_json, fname):
    # open file
    gpx = open('gpx/{}.gpx'.format(fname), 'w')
    #write header
    gpx.write('<?xml version="1.0" encoding="UTF-8"?>\n')
    gpx.write('<gpx version="1.0">\n')
    track_name = ''
    for i in geo_json:
        # if new day, new track
        if track_name != i['properties']['timestamp'][:10]:
            # if this is not the first track ever: finish current track
            if track_name:
                gpx.write('</trkseg></trk>\n')
            track_name = i['properties']['timestamp'][:10]
            gpx.write('<trk><name>{}</name><number>1</number><trkseg>'.format(track_name))
        gpx.write('<trkpt lat="{}" lon="{}">\n'.format(
                i['geometry']['coordinates'][1],
                i['geometry']['coordinates'][0]))
        gpx.write('<time>{}</time>\n'.format(i['properties']['timestamp']))
        gpx.write("</trkpt>\n")
    gpx.write('</trkseg></trk>\n')
    gpx.write('</gpx>\n')
    gpx.close()
    

member_data = api.exchange_oauth2_member(os.getenv('OH_ACCESS_TOKEN'))
for data in member_data['data']:
    if data['source'] == "direct-sharing-186" and 'overland-data-' in data['basename']:
        geo_json = read_geojson(data)
        write_gpx(geo_json, data['basename'][:-5])

And that's already all of it. If we now look into the gpx folder we should see a couple of newly converted GPX files:

In [2]:
for i in glob.glob('gpx/*'):
    print(i)
gpx/overland-data-2018-10.gpx
gpx/overland-data-2018-11.gpx
gpx/overland-data-2018-12.gpx

Indeed, there are the GPX files for all the data I have collected through Overland. You can now download these from the file list by navigating to the gpx folder, selecting the files and choosing Download. You can re-run this notebook at any point to update your files and get the latest data points as GPX.

Enjoy exploring your location data.