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

Adding real-time weather data from OpenWeatherMap


Real-time data is one of the most exciting data types you can add to a modern map. Most data producers make data available through Open GIS Consortium standards. One such example is OpenWeatherMap, which offers an OGC Web Map Service (WMS) for different real-time weather data layers. In this recipe, we'll access this service to access a real-time weather data layer.

Getting ready

To prepare for this recipe, you just need to open the QGIS Python Console by clicking on the Plugins menu and selecting Python Console.

How to do it...

We will add a WMS weather data layer for precipitation to a QGIS map, as follows:

  1. First, we specify the parameters for the service:

    service = 'crs=EPSG:900913&dpiMode=7&featureCount=10&format=image/png&layers=precipitation&styles=&url=http://wms.openweathermap.org/service'
    
  2. Next, we create the raster layer, specifying wms as the type:

    rlayer = QgsRasterLayer(service, "precip", "wms")
    
  3. Finally, we add...