Not the Shortest Path: Convert GPX Files for 3D Animation

Animated runs from my days back in Sherbrooke. Can you spot Mont Bellevue?

What is ‘Not the Shortest Path’?

Some Context

Road Network Mountain of Montreal. The Center point of the island is used to derive the height of each segment of the road network. A smoothing modifier is applied to the mesh to create the gradually appearing effect. Inspired by Craig’s Coral Cities.
  • GDAL/OGR: for initial data loading and manipulations
  • PostGIS: for geospatial data manipulation
  • DBT: for structuring and automating data pipelines
  • Blender: for creating 3D animations
Portland Road Network. A failed attempt at mimicking Craig’s Coral Cities with Blender.

The Problem

  • X coordinate
  • Y coordinate
  • elevation
  • time
  • point number (just in case)

Retrieving Strava Data

Example dump of a Strava profile

Converting a Single GPX File

GPX to SHP

ogr2ogr -f "ESRI SHAPEFILE" 1150471868 data/strava_dump/activities/1150471868.gpx
An example runs in Sherbrooke, Qc.
The attribute table of the track_points layer
ogr2ogr -f "ESRI SHAPEFILE" activity_1150471868 data/strava_dump/activities/1150471868.gpx -fieldTypeToString DateTime

GPX to CSV

ogr2ogr -f "CSV" activity_1150471868 data/strava_dump/activities/1150471868.gpx -fieldTypeToString DateTime
Track points CSV without any geometry information
ogr2ogr -f "CSV" activity_1150471868 data/strava_dump/activities/1150471868.gpx -fieldTypeToString DateTime -lco GEOMETRY=AS_XYZ
Track points CSV with XYZ

PostGIS Pipeline with DBT

Converting a Directory of GPX Files

5 GPS Tracks from Sherbrooke. The animated trails are created with emission particles.

Refactoring our Pipeline

  1. Finding an efficient way to distinguish which activity every point belongs to within the database table.
  2. Adapting the Blender data importer to not directly use the file path (not covered here).
-- auto-generated definition
create table public.track_points
(
filename text,
x numeric,
y numeric,
z integer,
track_fid integer,
track_seg_id integer,
track_seg_point_id integer,
ele numeric,
time text,
magvar text,
geoidheight text,
name text,
cmt text,
"desc" text,
src text,
link1_href text,
link1_text text,
link1_type text,
link2_href text,
link2_text text,
link2_type text,
sym text,
type text,
fix text,
sat text,
hdop text,
vdop text,
pdop text,
ageofdgpsdata text,
dgpsid text
);

alter table track_points
owner to postgres;

Limiting The Number of Points

with points as (
select filename,
track_seg_point_id num_point,
st_transform(st_setsrid(st_makepoint(x, y, ele), 4326), 3857) geom,
time
from track_points
)
select filename, num_point, st_x(geom) x, st_y(geom) y, st_z(geom) z, time
from points
where num_point % 20 = 0
Animated runs from my days back in Sherbrooke. Can you spot Mont Bellevue?

Conclusion

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Zachary Déziel

Zachary Déziel

Product Manager @ Anagraph. Geogeek and outdoor enthousiast. Twitter @zacdezgeo