Adding Real-Time Weather Data from OpenWeatherMap: QGIS Python Programming CookBook



Learn how to add real-time weather data from OpenWeatherMap in QGIS using Python from this section as part of this preview chapter, Creating Dynamic Maps from QGIS Python Programming CookBook. With 140 short, reusable recipes to automate geospatial processes in QGIS, the QGIS Python Programming CookBook teaches readers how to use Python and QGIS to create and transform data, produce appealing GIS visualizations, and build complex map layouts.

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 (OGC) 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 that service to access a real-time weather data layer.

Getting ready

The only preparation needed for this recipe is to open the QGIS Python Console by clicking the Plugins menu and selecting PythonConsole.

Free weekly newsletter

Fill out your e-mail address to receive our newsletter!

How to do it…

We will add a WMS weather data layer for precipitation to a QGIS map.

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

service = ‘crs=EPSG:900913&dpiMode=7&featureCount=10&format=image/png&layers=precipitation&styles=&url=’

  1. Next we just create the raster layer specifying wms as the type:

rlayer = QgsRasterLayer(service, “precip”, “wms”)

  1. Finally we add the precipitation layer to the map:


How it works…

A WMS request is typically a HTTP GET request with all of the parameters as part of the URL. In PyQGIS, you use a URL-encoded format but specify the parameters separate from the URL.The following map image shows the output of the precipitation layer in QGIS.

QGIS Python Programming CookBook

<– Previous: Bing Aerial Image Service   |     Next: Labeling and Map Transparency –>

Photo of author
About the author