BY PACKT BOOKS
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.
How to do it…
We will add a WMS weather data layer for precipitation to a QGIS map.
- 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=http://wms.openweathermap.org/service’
- Next we just create the raster layer specifying wms as the type:rlayer = QgsRasterLayer(service, “precip”, “wms”)
- Finally we add the precipitation layer to the map:
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.
Δεν υπάρχουν σχόλια:
Δημοσίευση σχολίου