OpenHistoricalMap/QGIS

From OpenStreetMap Wiki
Jump to navigation Jump to search

You can use QGIS for advanced visualizations that require desktop processing of OpenHistoricalMap data.

Vector data

GeoJSON

The easiest way to load OHM data into QGIS is to install the QuickOSM plugin and configure it to query OHM.

If you need something more custom than what the QuickOSM plugin provides, you can query OHM more manually and export the results as GeoJSON:

  1. Query for the elements using one of the available query services:
  2. Open QGIS's Layer menu and go to Data Source Manager.
  3. In the Data Source Manager window that appears, switch to the Vector tab. Set Vector Dataset(s) to the path to the GeoJSON file. Click Add.
  4. In the dialog that appears, select the geometry types that you want to include on your map.

OSM XML

If you need up-to-date information about a specific element and its children, you can request its data from the REST API in OSM XML format:

  1. Go to the element's page, for example, relation 2,749,168.
  2. Click the Download XML link in the sidebar.
  3. If this is a relation, its geometry is defined by its members. Append /full to the URL to get the entire relation structure.[1]
  4. Save the OSM XML file with the extension .osm.

If the relation structure is too large to load into your browser, you can use a command line tool such as curl or wget. Alternatively, you can use JOSM to download the data (which also affords you another opportunity to tweak the data for your own needs):

  1. In JOSM, open the Download Object dialog and download the element by its ID. If this is a relation, make sure to download the member elements at the same time, because the member elements define the relation's geometry.
  2. If this is a more complex relation, such as a chronology that contains multiple child relations, you need to recursively download the whole relation structure. In the Relations panel, select all the boundary relations, right-click, and choose Download with members from the context menu.
  3. Open the File menu and go to Save As. Save the file with the extension .osm.

QGIS uses GDAL's OSM driver to convert OSM XML data to a compatible format. By default, this driver preserves keys that are appropriate for most OSM use cases. However, it omits the start_date=* and end_date=* keys. If you're creating a time series animation, you need to customize it to include the date keys:

  1. Download the default configuration file.
  2. The file is divided into sections by geometry type. For example, linear ways are defined by the [lines] section, while areas and multipolygons are defined by the [multipolygons] section. Under the relevant section, modify the attributes property to include the missing keys, separated by commas.

Now you can load the OSM XML data into your QGIS project:

  1. Open the Layer menu and go to Data Source Manager.
  2. In the Data Source Manager window that appears, switch to the Vector tab. Set Vector Dataset(s) to the absolute path to the OSM XML file.
  3. If you created a custom GDAL configuration file, set CONFIG_FILE to the absolute path to this file.
  4. Click Add. In the dialog that appears, select the geometry types that you want to include on your map.

For more information, see the chapter "Working with Vector Data" in the QGIS User Guide.

Vector tiles

QGIS can load official OHM tiles and stylesheets directly. In the Browser pane, right-click on Vector Tiles and choose New Generic Connection. In the dialog that appears, set the following settings:

Name
OpenHistoricalMap
URL
https://vtiles.openhistoricalmap.org/maps/osm/{z}/{x}/{y}.pbf
Maximum zoom level
20
Style URL
https://www.openhistoricalmap.org/map-styles/main/main.json (or another stylesheet URL)

Then click OK and double-click on the new OpenHistoricalMap item.

To customize the style, go to the Layers sidebar, right-click on OpenHistoricalMap and go to Properties. In the dialog that appears, switch to the Symbol Style or Labels tabs, then toggle individual style layers or their filters.

For more information, see the chapter "Working with Vector Tiles" in the QGIS User Guide. You can also select features within visible tiles and export them as GeoJSON for further processing. [1]

QGIS tries to convert the stylesheet to its native symbols and layers automatically. Unfortunately, this conversion has some known limitations. [2][3] You'll need to manually adjust the resulting layer to implement any unsupported stylesheet features.

Time series animations

QGIS can streamline the creation of an animated time series map based on OHM vector data layers:

  1. Download the relevant OHM data as vector data.
  2. Customize the data's appearance as needed. You can use the Layout Manager for more control over layout or to add a custom date label.
  3. In the Layers sidebar pane, right-click on each of the OHM-derived layers and choose Properties.
  4. In the Layer Properties window that appears, switch to the Temporal tab.
  5. Enable the Dynamic Temporal Control checkbox and configure the temporal control:
    1. Change Configuration to Start and End Date/Time from Expressions.
    2. Keep Limits as Include Start, Exclude End (default).
    3. Set Start expression to:
      make_date(string_to_array(start_date, '-')[0], string_to_array(start_date, '-')[1] or 1, string_to_array(start_date, '-')[2] or 1)
      
    4. Set End expression to:
      make_date(string_to_array(end_date, '-')[0], string_to_array(end_date, '-')[1] or 1, string_to_array(end_date, '-')[2] or 1)
      
  6. Click OK.
  7. At the top-left corner of the Temporal Controller pane, click the ▶️ Animated movie button.
  8. Click the 💾 Export Animation button.
  9. In the Export Map Animation dialog that appears, configure the animation:
    1. Set Template to ####.png and Output directory to an empty folder named frames.
    2. Adjust the Extent to encompass the bounding box the animation should depict while remaining the desired size.
    3. Click the 🔄 Set to the project fixed time extent or the extent from the project's layers button.
    4. Adjust the Step to reflect the time elapsed between each frame. This will affect the number of frames that QGIS will save out.
  10. Click Save.

Once the frames are generated, you need to assemble them into an animation. Download FFmpeg and run the following command to produce a WebM movie:

ffmpeg -framerate 10 -i path/to/frames/%04d.png OpenHistoricalMap.webm

or a looping APNG image:

ffmpeg -framerate 10 -i path/to/frames/%04d.png -plays 0 -f apng OpenHistoricalMap.png

Or download gifski and run the following command to produce an animated GIF image:

gifski -o OpenHistoricalMap.gif path/to/frames/*.png

References

  1. Spacedman (August 1, 2024). “Downloading administrative boundaries from OpenHistoricalMap”. Geographic Information Systems Stack Exchange. Retrieved March 1, 2025.