Skip to content

Python API

import mapstyle as ms

render_map

ms.render_map(db, mode=None, layers=True, planner=False, dashboard=False,
              interaction=None, paths="google", **kwargs)

The whole map of a duckOSM database as one page. Returns roadstyle's map object: .save(path) writes the HTML file, .html is the page as a string, and in Jupyter it shows itself.

Argument Default
db path of a duckOSM .duckdb file
mode "all" which network stands out: all, driving, walking, cycling (guide)
layers True the base-map layers: True = all, a list of names, or False = roads only (guide)
paths "google" how paths look: google, osm, komoot, cyclosm
theme "osm" the whole map's colours: osm, google, grey, or a file of yours (guide)
planner False add the route planner
dashboard False make it a dashboard
interaction None how a layer opens: {"crossings": {"clickable": True, "tooltip": True, "popup": False}}
**kwargs passed to roadstyle.render_edges: e.g. tiles=True, basemap="positron", view_3d=True, arrows=False (not palette or settings: the mode sets those)
ms.render_map("tartu.duckdb", mode="cycling", tiles=True).save("tartu.html")
ms.render_map("monaco.duckdb", theme="grey", dashboard=True)
ms.render_map("monaco.duckdb", layers=["buildings", "water"], basemap="positron")

export_style and export_inline

from mapstyle.export import export_style, export_inline
export_style(db, out_dir, *, base_url, mode=None, paths="google", theme="osm", **kwargs)
export_inline(db, *, mode=None, paths="google", theme="osm", **kwargs)

The same map as render_map, for another map app instead of a page. Needs roadstyle 0.24.0 or later. export_style writes style.json, vector tiles and a sprite into out_dir (served at base_url) and returns the path of style.json. export_inline returns one style with the data inside (GeoJSON sources, no files). The base map's layers keep the values of layers.yaml: colour by kind, outlines, dashes, textures, icons and zoom ranges. A layer that is unticked there starts hidden. The images go into the style's metadata["roadstyle:images"]. The buildings in 3D are a layer ov<i>-3d (fill-extrusion, from the height of each building; off at first). **kwargs go to render_map.

load_roads

roads = ms.load_roads(db)     # a GeoDataFrame

One row per edge_id over the database's mode networks, with driving / walking / cycling flags (which modes can use the edge), the OSM tags mapstyle draws by (highway, name, bridge, tunnel, layer, oneway, …) and duckOSM's walk_type (sidewalk, crossing, …). edge_id and osm_id are strings: duckOSM's hashed ids can pass 2⁵³, more than JavaScript numbers hold.

load_layers

fcs = ms.load_layers(db)                   # {layer name: GeoJSON FeatureCollection}
fcs = ms.load_layers(db, ["buildings"])    # a subset

The base-map layers of styles/layers.yaml, in drawing order, each with kind, name and the OSM id per feature. A layer whose features.* table is missing is skipped with a logged hint.

MODES

("driving", "walking", "cycling"): the travel modes of a duckOSM database.