QGIS 3.0 XYZ Tile Layers

Feb 27, 2018 10:21 · 508 words · 3 minute read GIS QGIS

How to add common web basemaps to QGIS

Since QGIS 3.0 changed the underlying Python API for developing plugins, a number of plugin authors have yet to update their plugs to match. One important common plugin yet to be updated—that I get a fair amount of use out of—is QuickMapServices (QMS). Without it, it can be difficult to find and add common basemap layers.

There is however an alternative: you can directly add XYZ Tile Layers to your QGIS map document. These layer types were added as a provider back in 2.18, however there still seems to be a lack of documentation on them.

To add an XYZ Tile Layer to your map document, you must first register it with QGIS. In the Browser Panel (or from the browser panel of the “Data Source Manager”), find the “XYZ Tiles” top level node, right click it and select “New Connection…”

In the resulting dialog, we’re going to provide a name to store it as and a URL with palceholders that will inform QGIS where to retrieve the tiles form based on the current extent and location. For demonstration purposes, we’re going to add the OSM Mapnik basemap:

Here we provided OSM Mapnik as a name (any name will do) and http://tile.openstreetmap.org/{z}/{x}/{y}.png as the URL. The placeholders {z}, {x}, and {y} will be replaced by QGIS with the appropriate information. We’re not too concerned by the other values in this dialog box—most of the tile servers you’ll add wont require authentication or a referer (used to spoof where the tiles are being retrieved from) set.

Once you click okay, it will register the tile layer in the QGIS browser panel so that you can easily add them to your map via drag and drop.

Where to find Tile Layer URLs

What could be considered the difficult part is finding out how to construct the URLs you must pass to the add XYZ Connection dialog, luckily, thanks to the QuickMapServices plugin, we already have an easy place to look: the source of this plugin.

If you browse to the GitHub repository for QMS, you can find the data_sources directory that the plugin uses as the source for the location of each tile server. By clicking into each of the layers, like landsat_gis_lab you can open the metadata.ini file and find the url key/value within the ini. In this case, it’s on line 19: url = http://irs.gis-lab.info/?layers=landsat&request=GetTile&z={z}&x={x}&y={y}. Entering the url after the = symbol into the XYZ Connection dialog would add this as a XYZ Tile Layer to your map.

In addition to these data sources, QMS also provides a contributed pack, you can find those also on GitHub as part of the nextgis/quickmapservices_contrib repository—here you can find everything from Bing to Google maps tile layer URLs.

Here’s a selection of the most common that I use:

Provider/Layer URL
OpenStreetMap Mapnick http://tile.openstreetmap.org/{z}/{x}/{y}.png
OSM Cycle Map http://tile.thunderforest.com/cycle/{z}/{x}/{y}.png
OSM Black and White http://tiles.wmflabs.org/bw-mapnik/{z}/{x}/{y}.png
Esri Imagery/Satellite https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}
Esri Streets https://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer/tile/{z}/{y}/{x}
Esri Topo https://server.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer/tile/{z}/{y}/{x}
Google Satellite https://mt1.google.com/vt/lyrs=s&x={x}&y={y}&z={z}
Google Streets https://mt1.google.com/vt/lyrs=m&x={x}&y={y}&z={z}
Carto Positron https://cartodb-basemaps-a.global.ssl.fastly.net/light_all/{z}/{x}/{y}.png
Stamen Terrain http://a.tile.stamen.com/terrain/{z}/{x}/{y}.png
tweet Share