remisalmon / gpx-interpolate

Python function to interpolate GPX data using piecewise cubic Hermite splines
MIT License
49 stars 12 forks source link
gps gpx interpolation python

gpx_interpolate.py

Python script to interpolate GPX files using piecewise cubic Hermite splines.

Interpolates latitude, longitude, elevation and speed at any spatial resolution.

Usage

Script

usage: gpx_interpolate.py [-h] [-r RES] [-n NUM] [-s] FILE [FILE ...]

interpolate GPX files using piecewise cubic Hermite splines

positional arguments:
  FILE               GPX file

optional arguments:
  -h, --help         show this help message and exit
  -r RES, --res RES  interpolation resolution in meters (default: 1)
  -n NUM, --num NUM  force point count in output (default: disabled)
  -s, --speed        save interpolated speed

Module

from gpx_interpolate import gpx_interpolate

gpx_data = {'lat':lat,
            'lon':lon,
            'ele':ele,
            'tstamp':tstamp,
            'tzinfo':tzinfo}

gpx_data_interp = gpx_interpolate(gpx_data, res=1.0)

where:

ele, tstamp and tzinfo are optional and can be set to None.

Example

:black_circle: = input GPX data, :red_circle: = interpolated GPX data
plot.png

Test

Run ./test.sh

Requirements

gpxpy==1.5.0
scipy==1.8.0
numpy==1.22.2