Creating a dot density map
A dot density map uses point density to illustrate a field value within a polygon. We'll use this technique to illustrate population density in some US census bureau tracts.
Getting ready
You will need to download the census tract layer and extract it to a directory named census
in your qgis_data
directory from https://github.com/GeospatialPython/Learn/raw/master/GIS_CensusTract.zip.
How to do it...
We will load the census layer, create a memory layer, loop through the features in the census layer, calculate a random point within the feature for every 100 people, and finally add the point to the memory layer. To do this, we need to perform the following steps:
- In the QGIS Python console, we'll import the
random
module:import ...
Get QGIS Python Programming Cookbook - Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.