While there are many services that provide street map tiles, there are far fewer services that provide imagery services. One excellent free service for both maps and, more importantly, imagery is Microsoft's Bing map services. We can access Bing imagery programmatically in QGIS using GDAL's WMS capability coupled with virtual files.
You don't need to do any preparation for this recipe other than opening the Python console plugin within QGIS.
Similar to the approach used for the previous Using the OpenStreetMap service recipe, we will create an XML file as a string to describe the service, turn it into a GDAL virtual file, and load it as a raster in QGIS. To do this, we need to perform the following steps:
from osgeo import gdal
xml = """<GDAL_WMS> <Service name="VirtualEarth"> <ServerUrl> http://a${server_num}.ortho.tiles.virtualearth.net/tiles/a${quadkey}.jpeg?g=90 </ServerUrl> </Service> <MaxConnections>4</MaxConnections> <Cache/> </GDAL_WMS>"""
vfn = "/vsimem/bing.xml"
gdal.FileFromMemBuffer(vfn, xml)
rasterLyr = QgsRasterLayer(vfn, "BING") rasterLyr.isValid()
QgsMapLayerRegistry.instance().addMapLayers([rasterLyr])
GDAL has drivers for various map services. The service name for Bing is VirtualEarth
. The ${}
clauses in the server URL provide placeholders, which will be replaced with instance-specific data when GDAL downloads styles. When using this data, you should be aware that it has copyright restrictions. Be sure to read the Bing usage agreement online.