Skip to content

Python function to interpolate GPX data using piecewise cubic Hermite splines

License

Notifications You must be signed in to change notification settings

remisalmon/gpx-interpolate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

82 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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:

  • lat, lon are the trackpoints latitude and longitude (in degree)
  • ele (optional) is the trackpoints elevation (in meter)
  • tstamp (optional) is the trackpoints timestamps (in second)
  • tzinfo (optional) is the trackpoints timezone as a datetime.tzinfo subclass instance (None for UTC)
  • res is the interpolation resolution in meters (1.0 by default, disabled if num is passed)
  • num (optional) is the number of trackpoints of the interpolated data (None by default)

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

Example

⚫ = input GPX data, 🔴 = interpolated GPX data
plot.png

Test

Run ./test.sh

Requirements

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

About

Python function to interpolate GPX data using piecewise cubic Hermite splines

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published