Book Image

QGIS Python Programming Cookbook

Book Image

QGIS Python Programming Cookbook

Overview of this book

Table of Contents (16 chapters)
QGIS Python Programming Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Using the Bing aerial image service


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.

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...

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:

  1. First, we import the GDAL library:

    from osgeo import gdal
    
  2. Next, we create the XML file, describing the Bing service as a string:

    xml = """<GDAL_WMS>
      <Service name="VirtualEarth">
        <ServerUrl>
          http:/...