osm-rasterizer¶
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¶
- Fetch — Features are downloaded via the Overpass API (using osmnx) from OpenStreetMap or OpenHistoricalMap and clipped to the exact bounding box. An optional
dateparameter queries the historical state of the map (OSM: Overpass[date:]attic query; OHM: filtering bystart_date/end_datetags). - Project — The bbox and geometries are reprojected to the best-fit UTM CRS (or a user-specified CRS).
- Rasterize — Each feature class is burned into a
uint8grid using rasterio. Linestrings are optionally buffered to a real-world width (from theline_widthoption or the features' ownwidth/lanestags) before burning; otherwise they render one pixel wide. - Merge / fill — Bands are optionally merged into a single categorical layer, and empty pixels optionally filled using a Euclidean distance transform (scipy).
- Write — Output is a cloud-optimised, LZW-compressed, tiled GeoTIFF.
License¶
MIT. OpenStreetMap data is © OpenStreetMap contributors (ODbL); OpenHistoricalMap data is CC0.