Getting OHM country borders to work in Maptiler

Hello,

I have spent the past 2 days trying to figure out a way to get country borders from a specific year into Maptiler. The end goal is to use this for an After Effects animation, using the Geolayers plugin.

I tried exporting the country borders from planet.ohm file but I couldn’t get it to filter out a specific year. I ended up running in circles with ChatGPT being unable to figure this out.

My process using Osmium:

Filter and export country borders from a single year.

osmium tags-filter planet-250212_0001.osm.pbf boundary=administrative start_date="1938" -o borders-1938.osm.pbf	

Convert to GPKG

ogr2ogr -f "GPKG" national-borders-1938..gpkg national-borders-1938.osm.pbf

Import into QGIS to get the result below.

As you can see it appears I am getting the admin borders from multiple years, as well as sub-regions. I have tried other similar approaches without success.
I tried using overpass but again hit a dead end as I don’t fully understand if thats what would be appropriate to use anyway.

It appears I don’t know what I’m doing! Any help would be much appreciated, I have started a course on GCIS but still very new to this.

Thanks.

Hi, I’m unfamiliar with After Effects, but hopefully I can point you in the right direction. Are you referring to the GEOlayers 3 plugin and MapTiler’s GEOlayers licensing? All the tutorials I found focused on raster tiles, but MapTiler does seem to suggest that they support custom styles, so hopefully they do support vector tiles. If so, you could upload a variation of one of our official stylesheets that filters all the layers based on the start_date and end_date properties.

Since you’ve already gone through the trouble of downloading the planet, Osmium is normally a fine tool to use, but its tag processing is a bit primitive. First, if you only care about international borders, add a filter for admin_level=2.

As for the dates, note that in our data model, a version of a boundary that exists from 1900 to 2000 will only be recorded in the database as a single boundary relation, not 100 boundary relations. To get the boundaries in 1938, you’ll need to filter for start_date=* that’s less than or equal to 1938 and end_date=* that’s greater than or equal to 1938. The osmium command line tool doesn’t have a built-in operator for inequalities or regular expressions. If you’re comfortable with Python, Node.js, or C++, there are Osmium libraries for those languages that would enable you to do date comparisons.

The Overpass API is fine for this purpose. This OverpassQL query returns all the international borders in 1938:

relation["boundary"="administrative"]["admin_level"="2"]["start_date"](if:
  t["start_date"] < "1939" &&
  (!is_tag("end_date") || t["end_date"] >= "1938"));
out geom;

If you ever find yourself needing more than just the international boundaries at a given time, QLever would fare better than the Overpass API with that greater volume of data. Here’s a SPARQL query based on this documented example that returns all the international borders in 1938:

PREFIX osmkey: <https://www.openstreetmap.org/wiki/Key:>
PREFIX osm2rdfkey: <https://osm2rdf.cs.uni-freiburg.de/rdf/key#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX geo: <http://www.opengis.net/ont/geosparql#>
SELECT ?boundary ?name ?start_date ?end_date ?geometry WHERE {
  ?boundary osmkey:boundary "administrative" .
  ?boundary osmkey:admin_level "2"^^xsd:int .
  ?boundary osm2rdfkey:start_date ?start_date .
  ?boundary osmkey:name ?name .
  ?boundary geo:hasGeometry/geo:asWKT ?geometry .
  OPTIONAL {
    ?boundary osm2rdfkey:end_date ?end_date .
  }
  FILTER(YEAR(?start_date) < 1939 && COALESCE(YEAR(?end_date), 9999) >= 1938)
}

After running this query, click the “Map view” button and then “Export as GeoJSON” to get the geometries in a format that QGIS can handle. This query includes intrayear boundary changes, so there may be some overlapping geometries.

Depending on your needs, this tutorial might also be relevant. It focuses on pulling in a vector basemap from Mapbox, but that shouldn’t be necessary because we already provide a freely usable vector tileset.

1 Like

Hey thanks for the in-depth response, you’ve been massively helpful. Using overpass and importing the geojson into maptiler, I was able to get the 1975 map borders working in After Effects. This is a game changer! It’s also made me realise there is a lot more I need to learn based off all of this information.

Much appreciated.

1 Like