Skip to main content

osm2threejs logo

osm2threejs

PyPI version Python versions pipeline status License: MIT DOI Downloads

3D city models from OpenStreetMap or GeoJSON in pure Python, with no dependencies: one call gives planners, GIS analysts and web developers an interactive three.js page, a validator-clean glTF 2.0 (GLB) file, OBJ, DXF and 3D GeoJSON.

The osm2threejs HTML viewer in Chrome: a district of 393 buildings extruded from GeoJSON footprints, with terracotta roof caps, two towers, a courtyard block, a park with trees, a street grid and a river, in the Warm Sand and Slate theme, with sun altitude and azimuth sliders and a building, road and tree count

The page city.to_html() writes, rendered in headless Chrome. The district is synthetic GeoJSON built by docs/assets/make_assets.py.

Why osm2threejs?

  • No dependencies. The package uses only the Python standard library: no GDAL, Shapely, NumPy or JavaScript build step. It runs the same way in notebooks, web services and CI jobs.
  • Valid 3D files. Buildings are exported as closed solids with outward-facing walls, courtyard walls, and triangulated roof and floor caps. The GLB of the district above passes the Khronos glTF Validator 2.0.0-dev.3.10 with 0 errors and 0 warnings.
  • Reads real OSM tagging. Heights come from height, building:levels (3.2 m per level) and min_height. Multipolygon buildings keep their courtyards, and road widths follow highway and lanes.
  • Fast. On a laptop (Ryzen 5 4600H, Python 3.12), a 3,537-building city builds in 0.10 s, writes its HTML page in 0.08 s and its GLB in 0.31 s.
  • Tested and typed. 99 tests with 93 % line and branch coverage, a py.typed marker, and a clean mypy run.
  • Polite networking. Overpass queries rotate over 3 mirrors with a retry each and a 7-day SHA-256 disk cache. Nominatim geocoding sends an identifying User-Agent.

Installation

pip install osm2threejs
Extra Installs Use it for
geo Shapely, GeoPandas your own analysis next to osm2threejs; the package never imports them
dev pytest, pytest-cov, ruff, mypy, build, twine running the test suite and building releases

Python 3.9 to 3.13. CI runs the tests on 3.9, 3.11 and 3.13.

Quickstart

This runs offline on inline GeoJSON. Feature properties act as OSM tags.

import osm2threejs as o3

geojson = {"type": "FeatureCollection", "features": [
    {"type": "Feature", "properties": {"building": "yes", "building:levels": "4"},
     "geometry": {"type": "Polygon", "coordinates": [[[29.0, 41.0], [29.0004, 41.0],
                  [29.0004, 41.0003], [29.0, 41.0003], [29.0, 41.0]]]}},
    {"type": "Feature", "properties": {"highway": "residential", "name": "Demo Street"},
     "geometry": {"type": "LineString", "coordinates": [[28.9995, 40.9998], [29.001, 40.9998]]}},
]}

city = o3.from_geojson(geojson, theme="Cyberpunk Neon", name="Demo Block")
print(city.summary())
print(f"building height: {city.buildings[0].height_m} m")

city.to_html("demo_city.html")       # interactive three.js page
city.to_glb("demo_city.glb")         # Blender, Unity, Unreal, glTF viewers
city.to_obj("demo_city.obj")
city.to_dxf("demo_city.dxf")
city.to_geojson("demo_city.geojson")
{'name': 'Demo Block', 'theme': 'Cyberpunk Neon', 'bbox': (28.9995, 40.9998, 29.001, 41.0003), 'building_count': 1, 'road_count': 1, 'total_road_km': 0.13, 'waterbody_count': 0, 'park_count': 0, 'tree_count': 0}
building height: 12.8 m

For live OpenStreetMap data, use o3.from_place("Kadıköy, İstanbul", radius_meters=600) or o3.from_bbox((min_lon, min_lat, max_lon, max_lat)). Both need internet access.

Features

Inputs

  • from_place: Nominatim geocoding plus a radius in metres.
  • from_bbox: Overpass download of buildings, multipolygon buildings, roads, parks, water and trees.
  • from_geojson: GeoJSON (a dict or a JSON string) or an Overpass elements payload.
  • geojson_to_overpass and generate_3d_city expose the two steps of from_geojson.

City model (CityModel3D)

  • Buildings (BuildingMesh) carry their height, base height, levels, roof:shape, colours and courtyard rings.
  • Roads (RoadMesh) get a width from their class and lanes. Water, parks and trees are kept as separate layers.
  • summary(), building_count, road_count, total_road_km and tree_count describe the model.

Exports

  • to_html: a single HTML file that loads three.js r147 from jsDelivr, with orbit controls, sun altitude and compass-azimuth sliders, and shadows.
  • to_glb and to_obj: closed building solids in local metres (+X east, +Y up, -Z north), with theme-coloured PBR materials in the GLB.
  • to_dxf (3D polylines for buildings and roads) and to_geojson (PolygonZ, LineStringZ and PointZ; buildings and roads keep their OSM tags).
  • show() and _repr_html_ display the viewer inline in Jupyter and Colab.

Themes: 12 palettes, listed by list_themes() and returned by get_theme(name). Names match case-insensitively; an unknown name falls back to Editorial Paper.

The same synthetic district rendered by the osm2threejs viewer in six themes: Editorial Paper, Cyberpunk Neon, Blueprint Architectural, Warm Sand and Slate, Tinted Gray Teal and Realistic Satellite

Geometry generators return dataclasses with plain vertex and face buffers in local metres (or keyframes and particle settings), ready for three.js or your own pipeline. They cover roofs (generate_roof_mesh: flat, gabled, hipped, pyramidal, mansard, skillion), road ribbons, trees, Gerstner-wave water, suspension bridges, tunnels, tram tracks, noise barriers, power lines, wind and solar farms, plazas with crosswalks, helipads, marinas, street furniture, traffic, weather particles, building LODs, POI callouts and camera fly-throughs.

Screening helpers: calculate_solar_position, project_building_shadow, bake_static_building_shadows, compute_rooftop_solar_potential and compute_building_thermal_loss.

City exports are LOD1: flat-topped prisms. A pitched roof:shape is kept as an attribute and drawn as a cap in the theme's roof colour. Use generate_roof_mesh for pitched roof geometry on a single footprint.

Command line

$ osm2threejs --help
usage: osm2threejs [-h] [-v] {build,themes,geocode} ...

Headless 3D City Generator from OpenStreetMap into Three.js WebGL & 3D Assets.

positional arguments:
  {build,themes,geocode}
                        Available subcommands
    build               Generate 3D City Model from place name or bounding box
    themes              List all available visual themes
    geocode             Geocode place name to bounding box

options:
  -h, --help            show this help message and exit
  -v, --version         show program's version number and exit
osm2threejs build --place "Alsancak, İzmir" --theme "Cyberpunk Neon" --out-html city.html --open
osm2threejs build --bbox 27.13,38.42,27.16,38.45 --out-glb izmir.glb --out-dxf izmir.dxf
osm2threejs themes
python -m osm2threejs geocode "Eiffel Tower, Paris" --radius 800

Pass the full theme name, such as "Anime Pastel". A partial name like anime falls back to Editorial Paper.

Documentation

API What it does
from_place(place_name, theme, radius_meters, default_building_levels) Geocode a place and build its city
from_bbox(bbox, theme, name, default_building_levels) Build from a (min_lon, min_lat, max_lon, max_lat) box
from_geojson(geojson_data, theme, name, default_building_levels) Build from GeoJSON or Overpass JSON, offline
CityModel3D.to_html / to_glb / to_obj / to_dxf / to_geojson Write the five output formats
query_overpass(query_str, timeout, endpoints, use_cache) Run Overpass QL with mirror rotation and caching
list_themes(), get_theme(name) The 12 built-in palettes
generate_roof_mesh(ring, base_height, roof_type, roof_height) Roof mesh with its area and tilt
  • urbanshadow: exact shadow polygons and sun hours. It reads the buildings of city.to_geojson() with buildings_from_geojson(fc, height_field="height_m").
  • streetform: street-network form and connectivity metrics. It reads the road lines of city.to_geojson() with read_lines(fc, where={"layer": ["highway"]}).

Citation

If you use osm2threejs in research, please cite the Zenodo record 10.5281/zenodo.23677253. The metadata is in CITATION.cff.

Eminoğlu, Y. (2026). osm2threejs (Version 0.13.2) [Computer software]. Zenodo. https://doi.org/10.5281/zenodo.23677253

License

MIT. See LICENSE. Map data from OpenStreetMap is © OpenStreetMap contributors (ODbL).

Metadata

Release files for osm2threejs 0.13.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for osm2threejs 0.13.2
File Size Uploaded Provenance Actions
osm2threejs-0.13.2.tar.gz 85.7 kB With provenance Details for osm2threejs-0.13.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for osm2threejs 0.13.2
File Interpreter ABI Platform Actions
osm2threejs-0.13.2-py3-none-any.whl Python 3 none any Details for osm2threejs-0.13.2-py3-none-any.whl

Total release size: 163.8 kB

Release files / osm2threejs-0.13.2.tar.gz

Download URL osm2threejs-0.13.2.tar.gz
Size 85.7 kB
Tags Source
SHA-256 checksum
How to use checksums
200e83141f40896d09db8d3d487f954ded350e56bc0c7edab20716bd99a172c8
BLAKE2b-256 checksum
How to use checksums
d1bc6e6d75040b62bd4de15e7f03d321e2a979b05bd87344ea50323c4fdf56cf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.18

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitLab CI/CD, verified by PyPI on Dec 1, 2026.

Transparency log

Release files / osm2threejs-0.13.2-py3-none-any.whl

Download URL osm2threejs-0.13.2-py3-none-any.whl
Size 78.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
21318e6e4a0de4c37bb9e201930864adc3dd5f314ab276c39fe5139e8dbb6cf5
BLAKE2b-256 checksum
How to use checksums
9ca1f42e1a6228ebcbd960776c17ce8f6a80930cbdf5856e91efa0b18947c46d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.18

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitLab CI/CD, verified by PyPI on Dec 1, 2026.

Transparency log

Security for osm2threejs 0.13.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for osm2threejs-0.13.2.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitLab CI/CD, verified by PyPI on Dec 1, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page