Administrative borders Germany

Hello
I use overpass turbo not often and have absolutely no experience. Maybe someone can help me with an example?
I need the administrative borders (admin_level 5) of Germany. Only the borders and only the cost lines (not the area on the sea). I need no perfect resolution (reduce data, maybe 200m between points).

My first try is:

[out:json];
// gather results
rel[boundary=administrative][admin_level=5]({{bbox}});
// print results
out geom;

But it shows boundaries on the sea and not only Germany.
Any hint?

Maybe try in the Germany category, it’s normally really active and helpful: Deutschland (Germany) - OpenStreetMap Community Forum (but please try it in german language)

It’s probably not that easy, please read the topic Landmasse - können wir evtl darauf "verzichten"? - #19 by Nakaner until the end.

That’s because this part of the sea is part of Germany. There has been a polygon, which is the one you are looking for, called the landmass polygon. It has been removed in January this year. The reason was that it was a lot of work to maintain it and it can be calculated from other data.

My opinion: It’s very difficult to create it from other data. I didn’t manage to do so yet and I doubt that it is possible using overpass. Instead I’m using an old version, I once saved as a poly file.

1 Like

First of all, only few German states have polygons of admin level 5 (Regierungsbezirk) at all. Almost all abolished that level of administration. But you asked for admin level 5 and I will respond assuming that this level exists all over Germany.

You can’t achieve this with Overpass. Use PostgreSQL with PostGIS instead:

  • Download the extract for Germany in .osm.pbf format from Geofabrik Downloads
  • Install PostgreSQL and PostGIS. Instructions depend on your operating system. There are lots of instructions on the internet how to do this.
  • Install GDAL (includes the og2ogr).
  • Create a database after you have PostgreSQL installed.
  • Enable PostGIS in this database.
  • Install Osmp2pgsql.
  • Load the OpenStreetMap data extract into the database using osm2pgsql -d gis --output pgsql --hstore --multi-geometry path/to/osm_file.osm.pbf
    You might have to add more command line options for username, password, port etc.
  • Download land polygons derived from OpenStretMap data (shape file format, WGS84, not split) because Osm2pgsql does not load them into the database itself. Unzip the download.
  • Load them into the database using
    shp2pgsql -s 4326 -cDI land_polygons.shp land gis | psql -d gis
    As an alternative, you can use ogr2ogr as well.
  • Log into the database and execute following SQL commands:
CREATE TABLE al5 AS
  SELECT osm_id, name, way AS geom
    FROM planet_osm_polygon
    WHERE osm_id < 0 AND boundary = 'administrative' AND admin_level = '5';

CREATE INDEX ON al5 USING gist(geom);

CREATE TABLE al5_on_land AS
  SELECT a.osm_id, a.name, ST_CollectionExtract(ST_Intersection(a.geom, ST_Union(l.geom)), 3) AS geom
    FROM al5 AS a
    JOIN land AS l
      ON a.geom && l.geom AND ST_Intersects(a.geom, l.geom)
    GROUP BY a.osm_id, a.name;

Now you have a database table al5_on_land containing the admin level 5 polygons on land. You can export them using ogr2ogr (adding username, password, port etc. might be necessary):

ogr2ogr -f GeoJSON output.json "PG:dbname=gis" al5_on_land -nlt MultiPolygon

Further instructions/informations:

Note for experienced readers of this guide: You could use the new flex output of Osmp2gsql. There is an example and extensive, excellent documentation covering it. In order to keep the instructions simple, I used the old pgsql output.

Just a quick note to say that you can use Overpass to query for things that have been since deleted. This query finds https://www.openstreetmap.org/relation/62351 as it was on 15th January this year in https://www.openstreetmap.org/changeset/161423215. I’ve no idea if that relation is correct, complete or actually what you want, but it is how it was prior to deletion.

2 Likes

As a side note, it would be really awesome if Postpass or something similar came with some conveniences for this sort of query. People very commonly want boundaries without water for cartography and data visualization. Apparently there are paid services for this data but nothing particularly geared toward the OSM community.

2 Likes

You need to replace the id with 62781 to get what I was looking for. The other deleted ids are landmasses of smaller areas, e.g. of some states.

Thank you. Well it looks like not so easy I think.
I solved it with QGIS and hand working. Maybe not the best move or finest work, but I get what I need.