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,tiles="OpenStreetMap"
)

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
transportation 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 Bern in Bern-Zürich 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.0.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.0-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: cartons-1.1.0.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.0.tar.gz
Algorithm Hash digest
SHA256 998322e4501a740b79e451a52db4144cd08d8b9459de56fcc965792be7ab3a77
MD5 f42cbfdcb271673b435a91051eeda0c6
BLAKE2b-256 c73f0e0f43b42949ea479b2245e03c71d150bbc6e6886c65df917854de451c6a

See more details on using hashes here.

Provenance

The following attestation bundles were made for cartons-1.1.0.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.0-py3-none-any.whl.

File metadata

  • Download URL: cartons-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.4 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 51fe422d683cd024ee2b77841f417d71ca992546daa9ed2b842a18c24cd21258
MD5 1714ed8ccf64353432a3ee7521bceffe
BLAKE2b-256 1f9b0e247b4c680c741bcbec3bf7182d435f9b52469badbfdd9fd5d07d85cfae

See more details on using hashes here.

Provenance

The following attestation bundles were made for cartons-1.1.0-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