Skip to content

osm-rasterizer

osm-rasterizer logo osm-rasterizer logo

PyPI version Python 3.12+ License: MIT

Convert OpenStreetMap vector features into GeoTIFF rasters. Define feature classes using OSM tags, specify a bounding box and resolution, and get a multi-band or single-layer categorical raster as output. Also supports OpenHistoricalMap for rasterizing places as they existed at any point in history.

Quick start

pip install osm-rasterizer

osm-rasterizer \
    --bbox "minx,miny,maxx,maxy" \
    --feature 'name:{"osm_key": "value"}' \
    --output output.tif \
    --resolution 10

Or from Python:

from osm_rasterizer import rasterize

result = rasterize(
    bbox=(-0.15, 51.48, -0.08, 51.52),  # central London
    features=[
        ("building", {"building": True}),
        ("water", {"natural": "water"}),
    ],
    resolution=10.0,
)

See Installation, CLI Usage, Examples, and the Python API reference.

How it works

  1. Fetch — Features are downloaded via the Overpass API (using osmnx) from OpenStreetMap or OpenHistoricalMap and clipped to the exact bounding box. An optional date parameter queries the historical state of the map (OSM: Overpass [date:] attic query; OHM: filtering by start_date/end_date tags).
  2. Project — The bbox and geometries are reprojected to the best-fit UTM CRS (or a user-specified CRS).
  3. Rasterize — Each feature class is burned into a uint8 grid using rasterio. Linestrings are optionally buffered to a real-world width (from the line_width option or the features' own width/lanes tags) before burning; otherwise they render one pixel wide.
  4. Merge / fill — Bands are optionally merged into a single categorical layer, and empty pixels optionally filled using a Euclidean distance transform (scipy).
  5. Write — Output is a cloud-optimised, LZW-compressed, tiled GeoTIFF.

License

MIT. OpenStreetMap data is © OpenStreetMap contributors (ODbL); OpenHistoricalMap data is CC0.