Skip to main content

Simple OSRM routing and Folium map drawing toolkit

Project description

cartons

A lightweight Python toolkit for routing and map visualization.

cartons calculates routes using OSRM (Open Source Routing Machine) and renders them on interactive maps using Folium. With only a few lines of Python, you can compute a route between two coordinates and generate an HTML map displaying the route.

Route Example


Features

  • Simple routing between geographic coordinates
  • Interactive map visualization
  • Lightweight and easy to integrate into scripts
  • Minimal code required
  • Built on top of OSRM and Folium

Installation

Install via pip:

pip install cartons

Quick Example

import cartons
#if you want to see the map for fun, open it using the Webbrowser module
import webbrowser

# Bern → Zürich
m = cartons.draw(
    "https://router.project-osrm.org",
    7.4442153, 46.94686,
    8.5431302, 47.3668725,
    "red",5,"OpenStreetMap","car"
)

filename = "route.html"

m.save(filename)
webbrowser.open(filename)

This generates an interactive HTML map showing the route.

Route Zürich-Bern Example


How It Works

cartons connects to an OSRM routing server to calculate routes and renders them using Folium.

Coordinates
    ↓
cartons routing
    ↓
OSRM route calculation
    ↓
route geometry
    ↓
Folium map rendering
    ↓
Interactive HTML map

API

draw()

Creates a route and returns a Folium map.

draw(base_url, lon1, lat1, lon2, lat2, color="blue", weight=5,tiles="OpenStreetMap",transport="car")
Parameter Description
base_url OSRM routing server URL
lon1 Longitude of starting point
lat1 Latitude of starting point
lon2 Longitude of destination
lat2 Latitude of destination
color Route line color
weight Route line thickness
tiles Map tiles
transport transportation mode for route generation

Returns:

folium.Map

You can then save or modify the map using Folium.

Example:

map = cartons.draw(...)
map.save("route.html")

Example Output

The generated map is fully interactive.

Features include:

  • Zoom and pan
  • Inspect the route visually
  • Export as an HTML file
  • Embed into web pages

Map Zoomed on Luzern in East-West Luzern Route


Use Cases

cartons can be useful for:

  • route visualization
  • travel route maps
  • logistics planning
  • GPS data analysis
  • small mapping tools
  • data science experiments

Development

Clone the repository:

git clone https://github.com/AndPan3/cartons.git
cd cartons

Install in development mode:

pip install -e .

Contributing

Contributions are welcome.

If you find a bug or have ideas for improvements:

  1. Open an issue
  2. Submit a pull request

License

MIT License


Author

AndPan3


Acknowledgements

This project uses:

  • OSRM for routing
  • Folium for map visualization

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

cartons-1.1.3.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

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

cartons-1.1.3-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file cartons-1.1.3.tar.gz.

File metadata

  • Download URL: cartons-1.1.3.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for cartons-1.1.3.tar.gz
Algorithm Hash digest
SHA256 3132b206f9dd6faa1738eb425e3274efd20e555d55b19a96a2c33b7ebde27b46
MD5 1a54e7919a39c7b0eee2759b1e5990d3
BLAKE2b-256 f4bfb033755fd0750289be4f39cda5b0945036635bc31907763738ed4e3a1619

See more details on using hashes here.

Provenance

The following attestation bundles were made for cartons-1.1.3.tar.gz:

Publisher: python-publish.yml on AndPan3/cartons

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cartons-1.1.3-py3-none-any.whl.

File metadata

  • Download URL: cartons-1.1.3-py3-none-any.whl
  • Upload date:
  • Size: 4.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for cartons-1.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 e64d3177e29a83e95314d5a44f179159bf3bec3c0e5da67efec94e5a2df45b0d
MD5 73bebadda847ad82265cc8c10f6dffa8
BLAKE2b-256 442c1d9543958f30ba41a86ecd9c8114551dc4db8b28216c34b622ae1f6849a9

See more details on using hashes here.

Provenance

The following attestation bundles were made for cartons-1.1.3-py3-none-any.whl:

Publisher: python-publish.yml on AndPan3/cartons

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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