Using the OpenStreetMap service
Cloud-based technology is moving more and more data to the Internet, and GIS is no exception. QGIS can load web-based data using Open GIS Consortium standards, such as Web Map Service (WMS). The easiest way to add WMS layers is using the Geospatial Data Abstraction Library (GDAL) and its virtual filesystem feature to load a tiled layer.
Getting ready
You don't need to do any preparation for this recipe, other than opening the Python console plugin within QGIS.
How to do it...
We will create an XML template that describes the tiled web service from OpenStreetMap we want to import. Then, we'll turn it into a GDAL virtual file and load it as a QGIS raster layer. To do this, we need to perform the following steps:
First, we import the GDAL library:
from osgeo import gdal
Next, we'll create our XML template, describing the OpenStreetMap tiled web service:
xml = """<GDAL_WMS> <Service name="TMS"> <ServerUrl>http://tile.openstreetmap.org/${z}/${x}/${y...