Skip to content

Instantly share code, notes, and snippets.

@do-me
Last active October 30, 2025 14:54
Show Gist options
  • Select an option

  • Save do-me/16b4f974d82f7b99bf2e43bda2c4a6a5 to your computer and use it in GitHub Desktop.

Select an option

Save do-me/16b4f974d82f7b99bf2e43bda2c4a6a5 to your computer and use it in GitHub Desktop.
Extract Bundesländer polygons from germany-latest.osm.pbf to bundeslaender.parquet fast with osmium and ogr2ogr
osmium tags-filter germany-latest.osm.pbf r/boundary=administrative -o temp_boundaries.osm.pbf --overwrite
osmium tags-filter temp_boundaries.osm.pbf r/admin_level=4 -o bundeslaender.osm.pbf --overwrite
time ogr2ogr -f Parquet bundeslaender.parquet bundeslaender.osm.pbf multipolygons
@do-me
Copy link
Author

do-me commented Oct 30, 2025

  • Download the latest pbf file from Geofabrik.
  • Osmium cannot change filter conditions (lol) so one must run two commands with temp file in between.
  • Takes 18s in total.
image

Note that due to the way osmium works, sometimes small pieces of neighboring states are included. Filtering by admin_level == 4 yields clean geometries.

import geopandas as gpd 
gdf = gpd.read_parquet("/Users/dome/work/gbc/basemap_de_addresses/in/bundeslaender.parquet")
gdf[gdf.admin_level == "4"]
image

Also, these geometries align perfectly with the official ones from BKG you can get here: https://gdz.bkg.bund.de/index.php/default/verwaltungsgebiete-1-25-000-stand-31-12-vg25.html

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment