Skip to main content

A package for plotting and animating .gpx files

Project description

walkmapper

This is a fork of the original walkmapper package from sam-olson.

About

A Python package for plotting and animating your walk/run/bike ride routes.

Install walkmapper using the command line:

pip install walkmapper

You can then run the example script:

python example.py

The package works by analyzing .gpx files, a common file format used by GPS devices. The Asics Runkeeper app was used in the development of this package, as it allows you to record GPS locations on your smart phone and export them from your account in the browser.

Open Street Map is a great resource for grabbing maps to use as backgrounds. Just select "Share" on the map sidebar, size your image with "Set custom dimensions", and download. Rename the photo using the methods described below, allowing the package to properly parse the latitudes and longitudes.


You can get the latitudes and longitudes of the image you have downloaded using "Share" in OpenStreetMap, by following these steps, as long as you have not checked Set custom dimensions, and you have not panned or zoomed tha map after downloading the image:

  1. Paste this into your shell (including the single quote at the end), but do not press enter yet: python3 -c "import sys;print([round(float(s), 4) for s in sys.argv[1].split('?bbox=')[1].split('&amp')[0].split('%2C')])" '
  2. Select HTML under the Link or HTML section of the Share panel.
  3. Copy the HTML, it should start with <iframe, and it should be all in one line, with no line breaks.
  4. Then paste the copied HTML into your shell after the single quote, add a single quote at the end, and press Enter.

The output will be in the format [LowerLeftLon, LowerLeftLat, UpperRightLon, UpperRightLat]. For example, processing the HTML for a map centered on Portland, OR would output [-122.7077, 45.4761, -122.5831, 45.5372].


The class SingleRoute contains methods for analyzing and plotting a single route. It is also possible to obfuscate your address with a privacy bubble if you plan on sharing on the internet:

from walkmapper.routes import SingleRoute

route = SingleRoute("path/to/your/file.gpx", home_lat=45.0000, home_lon=-122.0000, privacy_bubble_rad=150)

From here you can plot the .gpx file over a map image using the SingleRoute.plot method. The map image should have the following format: Description_UpperRightLat_UpperRightLon_LowerLeftLat_LowerLeftLon.png. If a latitude or longitude is negative, its value should be preceded by an m. For example, a map centered on Portland, OR would have the file name: Portland_45.5372_m122.5831_45.4761_m122.7077.png. Providing the coordinates of the upper right and lower left corners of the map image in the title allows the plotting functions to parse these values and put appropriate boundaries on the matplotlib images.

The function map_file_name in walkmapper.utils makes formatting an image title far easier:

from walkmapper.utils import map_file_name

# this function automatically renames the image
map_file_name("images/portland.png", 45.5372, -122.5831, 45.4761, -122.7077, "Portland")

# saves over images/portland.png with images/Portland_45.5372_m122.5831_45.4761_m122.7077.png

You can also create a snake animation, where the route is drawn out from start to finish, by using the SingleRoute.snake_animation method.


The class MultipleRoutes contains methods for analyzing, plotting, and animating multiple routes:

from walkmapper.routes import MultipleRoutes

# compile all .gpx files in a folder into a list
files = [f"folder/{i}" for i in os.listdir("folder") if i.endswith(".gpx")]

# create instance of MultipleRoutes
routes = MultipleRoutes(files, home_lat=45.0000, home_lon=-122.0000, privacy_bubble_rad=150)

Once a MultipleRoutes instance is created, you can display the data several ways:

map_file = "Portland_45.5372_m122.5831_45.4761_m122.7077.png"

# plot all routes with map background
routes.basic_plot(map_file)

# plot heat map
routes.heat_map(map_file, n_bins=100, alpha=0.5)

# create .mp4 animation displaying one route after another
routes.basic_route_animation(map_file_path, fps=2, dpi=300)

# create an .mp4 animation that draws out each route sequentially
routes.snake_animation(frame_distance=50, map_file_path=map_file, fps=60, dpi=300)

See example.py for an example script, and the directory example for example data, maps, and animations.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

walkmapper2-0.1.3.tar.gz (11.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

walkmapper2-0.1.3-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

Details for the file walkmapper2-0.1.3.tar.gz.

File metadata

  • Download URL: walkmapper2-0.1.3.tar.gz
  • Upload date:
  • Size: 11.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.25.1 requests-toolbelt/0.9.1 urllib3/1.26.6 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.9

File hashes

Hashes for walkmapper2-0.1.3.tar.gz
Algorithm Hash digest
SHA256 f869625bf6c1318090edefa2dd083028fc30e949b3de5d6fdfc16b40d3e728ce
MD5 414d8122e097e64dc014d7b9b9c052f0
BLAKE2b-256 eec83172964dedfe40da67318eba89417cb96b852e40f3f78240b105eb4dff6c

See more details on using hashes here.

File details

Details for the file walkmapper2-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: walkmapper2-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 11.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.25.1 requests-toolbelt/0.9.1 urllib3/1.26.6 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.9

File hashes

Hashes for walkmapper2-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 30196dcca89d5f9462fbc06e2999705ed2b64a12672928c6f06e12cef0e7939c
MD5 d707a03658f39db204504e2e2fcdd3a8
BLAKE2b-256 fda61889c261a31ab6c8669bafa6322916f4633a54d446a0953e3a7e0f9ae17f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page