Waterways from OpenStreetMap as SVG

1 minute read

Published:

Rivers and streams create organic, recognizable shapes that work well as design elements. Here I extract the waterway network around Offenbach am Main from OpenStreetMap and export it as a clean SVG.

Fetching waterways

OSMnx handles the query:

import osmnx as ox

tags = {'waterway': ['river', 'stream', 'canal', 'drain', 'ditch']}
gdf = ox.features.features_from_address(
    "Offenbach am Main, Germany", tags=tags, dist=5000
)

A 5 km radius around the city center captures the Main and all tributaries (Bieber, Rodau, Hainbach, plus several canals near the harbor).

Filtering and export

OSM waterway features can be points, lines, or polygons. For a clean river network, keep only lines:

gdf_lines = gdf[gdf.geometry.type.isin(['LineString', 'MultiLineString'])]

Matplotlib saves directly to SVG:

fig, ax = plt.subplots(figsize=(12, 12))
gdf_lines.plot(ax=ax, color='blue', linewidth=1.5, alpha=0.8)
ax.set_aspect('equal')
plt.savefig('offenbach_waterways.svg', format='svg', bbox_inches='tight')

The result shows the distinctive shape of the Main at Offenbach – the old harbor branching off – with smaller streams radiating inland. The SVG scales to any size, and the GeoJSON export (gdf_lines.to_file(...)) works for web maps or further processing.

The same code works for any city – just change the address and radius.