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

Creating a heat map


A heat map is used to show the geographic clustering of data using a raster image that shows density. The clustering can also be weighed using a field in the data to not only show geographic density but also an intensity factor. In this recipe, we'll use earthquake point data to create a heat map of the impact of an earthquake and weigh the clustering by the earthquake's magnitude.

Getting ready

This recipe requires no preparation.

How to do it...

We will build a map with a worldwide base layer of countries and earthquake locations, both in GeoJSON. Next, we'll run the SAGA kernel density estimation algorithm to produce the heat map image. We'll create a layer from the output, add a color shader to it, and add it to the map.

To do this, we need to perform the following steps:

  1. First, we'll import the Python libraries that we'll need in the Python console:

    from PyQt4.QtCore import *
    from PyQt4.QtGui import *
    import processing
    
  2. Next, using the following code, we'll define our map...