Downloads large georeferenced images from a WMS service in tiles and combines them into one virtual raster.
WMS services usually limit the size of a single image. wms-downloader splits a large bounding box into square tiles and downloads each tile with a separate GetMap request. It then creates a GDAL VRT file, which can be opened as one image in e.g. QGIS or converted with gdal_translate.
pip install wms-downloader # from PyPI
pip install git+https://github.com/codeforberlin/wms-downloader # directly from GitHub
Creating the VRT file requires gdalbuildvrt from GDAL, which needs to be installed separately, e.g. with brew install gdal or apt install gdal-bin.
Create a config.yml specifying your setup, e.g. for the true orthophotos of Berlin from 2024:
service:
version: 1.1.1
url: https://gdi.berlin.de/services/wms/truedop_2024
srs: EPSG:25833
format: jpeg
transparent: false
layer: truedop_2024
bbox:
west: 360000.0
south: 5790000.0
east: 420000.0
north: 5840000.0
size: 10000
resolution: 5000
timeout: 300
projection: EPSG:25833
directory: images
vrtfile: tiles.vrtwhere:
servicedescribes the WMS service:versionis the WMS version,1.1.1or1.3.0,urlis the URL of the service, without query parameters,srsis the projection used for the requests,formatis the image format, e.g.jpegorpng, which is also used as file extension,transparentsets whether the background should be transparent (only forpng), andlayeris the name of the layer,
bboxis the bounding box for the map you want to retrieve, in the units ofprojection,sizeis the edge length of a single tile, in the units ofprojection,resolutionis the width and height of a single tile in pixels,timeoutis the timeout for a single request in seconds,projectionis the projection of the downloaded images and the VRT file,directoryis the directory where the downloaded images are stored, andvrtfileis the path to the created VRT file.
The example covers Berlin with 6 × 5 tiles of 10 × 10 km and 5000 × 5000 pixels, i.e. 30 requests with 2 m per pixel.
Then run the script with the config.yml as argument:
wms-downloader config.yml
Each tile is stored in directory as <west>_<south>_<resolution>.<format>, together with an .aux.xml file containing its georeference. Tiles which already have an .aux.xml file are skipped, so an interrupted download can simply be started again. The VRT file is only created if it does not exist yet, so delete it after downloading additional tiles.