Skip to main content

Generate static map images with Swisstopo, OpenStreetMap, and ESRI satellite tiles

Project description

kartli

kartli

Generate static map images from Python or the command line.
Swisstopo, OpenStreetMap, and ESRI satellite tiles. Markers, polygons, lines, scale bars.

Install

pip install kartli

Requires Python 3.12+.

Python SDK

All methods return self, so you can chain everything:

from kartli import Map

(
    Map(width=800, height=600)
    .marker(46.9480, 7.4474, label="Start", color="blue")
    .marker(46.9510, 7.4380, label="End", color="red")
    .area(
        [(46.948, 7.443), (46.950, 7.443), (46.950, 7.450), (46.948, 7.450)],
        label="Area of interest",
        color="orange",
        opacity=0.3,
    )
    .line(
        [(46.9480, 7.4474), (46.9510, 7.4380)],
        label="Route",
        color="green",
        label_position=0.5,
    )
    .set_scale(25_000)  # 1:25'000
    .render("map.png")
)

Or build step by step:

from kartli import Map, Marker, Area

m = Map(width=800, height=600)
m.add_marker(Marker(coord=(46.948, 7.447), label="Bern"))
m.add_area(Area(coords=[...], label="Zone", color="red"))
m.set_zoom(15)
m.render("map.png")

Tile sources

Auto-detects Swisstopo for Swiss coordinates, OSM otherwise. Override explicitly:

from kartli import Map, SwisstopoTiles, OsmTiles, EsriSatelliteTiles

Map(tile_source=SwisstopoTiles())                                    # topo map
Map(tile_source=SwisstopoTiles(layer="ch.swisstopo.swissimage"))     # aerial
Map(tile_source=EsriSatelliteTiles())                                # satellite (global)
Map(tile_source=OsmTiles())                                          # OSM

Zoom

Set zoom by level or map scale (mutually exclusive):

m.set_zoom(15)
m.set_scale(25_000)  # 1:25'000

Or omit both — zoom is auto-computed to fit all markers/areas/lines.

Swiss LV95 coordinates

Use Coord.from_lv95() to work with Swiss LV95 (EPSG:2056) coordinates directly. The original values are preserved to avoid precision loss in coordinate conversions.

from kartli import Coord, Map

m = Map()
m.add_marker(Marker(coord=Coord.from_lv95(2600072, 1199545), label="Bern"))
m.set_center(Coord.from_lv95(2600072, 1199545))
m.render("bern.png")

Output

PNG or PDF, detected from extension. render() also returns a PIL Image:

m.render("map.png")
m.render("map.pdf")
img = m.render()  # no file, just the Image object

CLI

# Polygon on Swisstopo (auto-detected)
kartli render \
  --area "46.947,7.443;46.949,7.441;46.951,7.444;46.952,7.448;46.950,7.451" \
  -o polygon.png

# Markers at 1:25'000 scale
kartli render \
  --center 46.948,7.448 \
  --scale 1:25000 \
  --marker 46.9480,7.4474,Start \
  --marker 46.9510,7.4380,End \
  -o markers.png

# Satellite tiles, no scale bar
kartli render \
  --center 46.948,7.448 \
  --zoom 15 \
  --tiles swisstopo-satellite \
  --no-scalebar \
  -o satellite.png

# PDF output
kartli render \
  --center 46.948,7.448 \
  --scale 1:50000 \
  -o map.pdf

# Swiss LV95 coordinates
kartli render \
  --lv95 \
  --center 2600072,1199545 \
  --marker 2600072,1199545,Bern \
  -o bern.png

Tile sources

--tiles value Source
(auto) Swisstopo for Swiss coords, OSM otherwise
swisstopo Swiss topo map
swisstopo-satellite Swiss aerial imagery
osm OpenStreetMap
esri-satellite ESRI World Imagery (global)

Options

Flag Description
--center LAT,LON Map center (auto-computed from objects if omitted)
--zoom N Zoom level (mutually exclusive with --scale)
--scale 1:N Map scale, e.g. 1:25000 (mutually exclusive with --zoom)
--marker LAT,LON[,LABEL] Add marker (repeatable)
--area LAT,LON;LAT,LON;... Add polygon (repeatable)
--line LAT,LON;LAT,LON;... Add line (repeatable)
--lv95 Interpret all coordinates as LV95 East,North (EPSG:2056)
--size WxH Image size in pixels (default: 800x600)
--no-scalebar Hide the scale bar
-o FILE Output file (.png or .pdf, default: map.png)

Tile caching

Tiles are cached to ~/.cache/kartli/. Second render of the same area is instant.

License

MIT

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

kartli-0.2.0.tar.gz (129.7 kB view details)

Uploaded Source

Built Distribution

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

kartli-0.2.0-py3-none-any.whl (22.9 kB view details)

Uploaded Python 3

File details

Details for the file kartli-0.2.0.tar.gz.

File metadata

  • Download URL: kartli-0.2.0.tar.gz
  • Upload date:
  • Size: 129.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for kartli-0.2.0.tar.gz
Algorithm Hash digest
SHA256 81d5fa51987e5cb657cc094e87eef2c630e084ada743bf781f992fc5df2a0453
MD5 5032fa7f6f39d0f50d2ad3c4924de2d8
BLAKE2b-256 be3a6df0d116565d40b81e20c1216da3c52ecfcaaee56b94dbc0faa4d3764ce0

See more details on using hashes here.

File details

Details for the file kartli-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: kartli-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 22.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for kartli-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5381a83b88ac6216e6d07b1ed13d2e4e5ef3cef2a779cc4756996edfebe46717
MD5 f5578a1930a596f3dca8e9794b4f3932
BLAKE2b-256 4751bfdf4bf2386ff9e5f9e36eb21db50940cfbc93491069162197b4b6ee5efa

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