This plugin adds additional density heatmap algorithms to QGIS including geohash, H3, styled heatmap, and polygon density maps. It adds a vector density heatmap explorer to examine hotspot areas of greatest concentrations. It wraps the QGIS Heatmap (Kernel Density Estimation) algorithm into a new version that automatically styles the layer and allows the user to specify the cell size in various units of measure and not just the units of the layer's CRS. It provides an algorithm to create a raster density of polygons. It has processing algorithms to create a gradient style, random style, and raster pseudocolor style so that they can be used in QGIS models. Another tool allows a copied style or a .qml file to be pasted onto all selected layers. Once installed, the plugin is located under Plugins->Density analysis in the QGIS menu, on the toolbar, and can be found in the Processing Toolbox under Density analysis. This shows plugin from the main menu with Geohash density algorithms expanded.
This shows the expanded H3 density algorithms.
Note that several algorithms in this plugin use H3 (Hexagonal hierarchical geospatial indexing system). This is an incredibly fast algorithm for generating hexagon density maps, but requires installation of the H3 python library. The H3 package can be installed by running the OSGeo4W shell as system administrator and running 'pip install h3' or whatever method you use to install python packages. If H3 is not installed, the rest of the algorithms will still work, but you will not be able to run the H3 algorithms. In one test using the QGIS Create grid processing algorithm, followed by Count points in a polygon algorithm took 63.18 seconds to process spatially indexed point data. To do the same thing with H3 only took 3.79 seconds.
Many of the default parameters in the algorithms can be set from the settings dialog found in Plugins->Density analysis->Settings. This allows the user to customize these settings one time.
Given point features, this will create a rectangle, diamond, or hexagon grid histogram of points that occur in each polygon grid cell. This algorithm uses the QGIS Count points in polygon algorithm which is fairly time intensive even though it has been masterfully implemented in core QGIS and significantly beats the speed implemented in commercial software. To optimize the speed make sure your input data is spatially indexed; otherwise, this algorithm will be painfully slow. The advantage to this algorithm is that it gives the most control over the size of the polygon grid cells. If speed is more important then use Styled geohash density map or Styled H3 density map algorithm. Both of these use geohash indexing to count points in each geohash grid cell and are very fast. The former creates a square or rectangular grid and H3 creates a hexagon grid. For H3 support, the H3 library needs to be installed in QGIS. The disadvantage of these geohash density maps is that they have fixed resolutions and you cannot choose anything in between, but this is also what makes them fast.
Here is an example of crime in Chicago. Each point on the left is a criminal event. On the right is a hexagon heatmap counting the number of events in each cell and displaying it as a heatmap. The darker the red, the more crime is in that area.
This shows the parameters used in the algorithm.
These are the basic input parameters:
These are the Advanced Parameters.
Number of gradient colors - This specifies the number of gradient categories that are going to be used. This example uses a value of 15. When we look at the output layer, it shows each category and the number of events that can occur within the category.
Color ramp mode - Select one of Equal Count (Quantile), Equal Interval, Logarithmic scale, Natural Breaks (Jenks), Pretty Breaks, or Standard Deviation. The default value change be changed in Settings.
There are four geohash density algorithm variations. Two are automatically styled and two of them work with multiple vector layers.
This algorithm iterates through every point indexing them using a geohash with a count of the number of times each geohash has been seen. The bounds of each geohash cell is then created as a polygon. Depending on the resolution these polygons are either a square or rectangle. Here is an example.
This shows the algorithm's dialog.
These are the input parameters:
Resolution Level |
Approximate Dimensions |
---|---|
1 | ≤ 5,000km X 5,000km |
2 | ≤ 1,250km X 625km |
3 | ≤ 156km X 156km |
4 | ≤ 39.1km X 19.5km |
5 | ≤ 4.89km X 4.89km |
6 | ≤ 1.22km X 0.61km |
7 | ≤ 153m X 153m |
8 | ≤ 38.2m X 19.1m |
9 | ≤ 4.77m X 4.77m |
10 | ≤ 1.19m X 0.596m |
11 | ≤ 149mm X 149mm |
12 | ≤ 37.2mm X 18.6mm |
These are the Advanced Parameters.
The output geohash table contains a unique identifier ID, geoshash string GEOHASH and the count of number of points or weighted count of the number points within the geohash cell NUMPOINTS.
This is the same as Styled geohash density map, but without the styling. The algorithm iterates through every point of the input layer indexing them using a geohash with a count of the number of times each geohash has been seen and saved to the NUMPOINTS attribute. The bounds of each geohash cell is then created as a polygon. Depending on the resolution these polygons are either a square or rectangle.
This is the same as the Styled geohash density map algorithm with the exception that it supports multiple input point vector layers which contribute to the output density map. If a Weight field is used, then all selected layers must contain the same weight attribute field. To select the input layers, click on the "..." button on the right and it will give a dialog with all of the point vector layers that are available to be included in the output density map.
This is the same as Styled multi-layer geohash density map, but without the styling. The algorithm iterates through every selected point vector layer and every point within the layer, indexing them using a geohash with a count of the number of times each geohash has been seen. The bounds of each geohash cell is then created as a polygon. Depending on the resolution these polygons are either a square or rectangle.
There are four H3 density algorithm variations. Two are automatically styled and two of them work with multiple vector layers.
These algorithms use the H3 (Hexagonal hierarchical geospatial indexing system) library for fast density map generation. They iterate through every point using H3 indexing with a count of the number of times each H3 index has been seen. Each H3 cell is then created as a polygon. The polygons are in a hexagon shape.
To create H3 density maps you will need to install the H3 Library (https://h3geo.org/). The H3 package can be installed by running the OSGeo4W shell as system administrator and running 'pip install h3' or whatever method you use to install python packages. The H3 algorithms will give a warning message if H3 has not been installed.
This algorithm generates a styled H3 density map from a point vector layer.
Here is an example.
This shows the algorithm dialog.
The parameters are as follows:
Resolution Level |
Average Hexagon Edge Length |
---|---|
0 | 1107.71 km |
1 | 418.68 km |
2 | 158.24 km |
3 | 59.81 km |
4 | 22.61 km |
5 | 8.54 km |
6 | 3.23 km |
7 | 1.22 km |
8 | 461.35 m |
9 | 174.38 m |
10 | 65.91 m |
11 | 24.91 m |
12 | 9.42 m |
13 | 3.56 m |
14 | 1.35 m |
15 | 0.51 m |
These are the Advanced Parameters.
This is the same as Styled H3 density map, but without the styling.
This is the same as the Styled H3 density map algorithm with the exception that it supports multiple input point vector layers which contribute to the output density map. If a Weight field is used, then all selected layers must contain the same weight attribute field. To select the input layers, click on the "..." button on the right and it will give a dialog with all of the point vector layers that are available to be included in the output density map.
This is the same as Styled multi-layer H3 density map, but without the styling. The algorithm iterates through every selected vector layer and every point within the layer, indexing them using a H3 geohash index with a count of the number of times each index has been seen. The bounds of each geohash index cell is then created as a polygon.
This will create a grid of H3 polygons based on the extent of a layer, canvas, or user drawn extent. H3 Resolution is a value between 0 and 15 specifying the resolution of the H3 grid.
With this tool you can quickly look at the top scoring values. Select the original point layer and the density heatmap polygon layer generated by the above algorithms. ID should be set to a unique identifier, and Score should be set to the histogram count attribute. If the selected heatmap vector layer has the attributes id and NUMPOINTS, these will be automatically selected.
Once the parameters have been set, click on Display Density Values and the top scores will be listed. If you click on any of entries only that grid cell will be display. A drop down set of actions selects what happens when clicking on one or more of the score entries.
You can then examine the features within the grid cell. Here is an example view.
This algorithm is a wrapper for the native QGIS Heatmap (Kernel Density Estimation) algorithm, but adds automatic styling and simplifies specifying the pixel/grid size of the output image. The user specifies the measurement unit such as kilometers, meters, etc. rather than having to know the units used for the CRS. The algorithm creates a density heatmap raster image. The output image size will be based on the Cell/pixel dimension in measurement units parameter and bounding box of the input vector layer. If either dimension of the output image exceeds Maximum width of height dimensions of output image, then an error will be generated and the user will need to either increase Cell/pixel dimension in measurement units or Maximum width or height dimensions of output image.
The following are the main parameters.
These are Advanced Parameters.
Like the Styled Heatmap, this algorithm uses a raster image to accumulate the summation of rasterized polygon layers and then automatically style the results. Here is an example of the result of summing a cluster of polygons.
The parameters in dialog box are as follows:
These are the Advanced Parameters.
This is the same as the Styled density (raster), but without the styling. It uses a raster image to accumulate the summation of rasterized polygon layers. Here is an example of the result of summing a cluster of polygons.
The parameters in dialog box are as follows:
This is similar to the Polygon density (raster) with the exception that it is vector and not raster based. It calls the QGIS Vector->Geoprocessing Tools->Union algorithm to break up the polygons wherever they overlap. It then runs the QGIS Aggregate algorithm to count the number of polygons that have the same geometry effectively returning the density of each polygon area.
WARNING: There appears to be a bug in the QGIS Union algorithm which I am guessing occurs when a polygon is broken up so small that it not a polygon. If you seen an error message with this algorithm, try running just the Union algorithm on your data without an overlay layer. If that fails report the Union error to the QGIS development team. If you get an error message, you will need to use the raster version of the polygon density algorithm. Here is an example of the output.
The parameters in dialog box are as follows:
This is the same as the Styled density (vector), but without the styling.
QGIS lacks a function to paste a style to more than one layer so this tool was developed to fix that lack in capability. If you have a .qml style or have a style copied on the clipboard you can apply it to all the selected layers.
When pasting a graduated style the symbol class values are preserved unless Automatically reclassify graduated layers is checked. When checked, each layer's minimum and maximum are evaluated along with the graduated mode to reclassify the values.
The purpose of these two algorithms, is to set random and graduated styles using an algorithm. This makes it possible to set a layer's style in the model builder.
Apply a graduated style - This applies a graduated style to a layer. This is one of the building blocks to create a heatmap.
This parallels the layer styling panel. It does not include all the styling parameters, but focuses on those which are important for heatmap styling. Select your input layer, the style field, select one of the color ramps, mode and number of classes. Mode can be Equal Count (Quantile), Equal Interval, Logarithmic scale, Natural Breaks (Jenks), Pretty Breaks, or Standard Deviation. If No feature outlines is checked, then the features will not have outlines.
Apply a random categorized style - This applies a random categorized style to a layer.
Specify the input layer and the field to distinguish between different categories. If No feature outlines is checked, then the features will not have outlines.
This achieves some of the functionality you get from right-mouse clicking on a single band image and selecting properties and selecting the Symbology tab and choosing Singleband pseudocolor for the *Render type. For more information on the parameters visit the QGIS documentation. These are the settings.
The settings are found in the QGIS menu under Plugins->Density Analysis->Settings. These settings allow the user to set default values for some of the most common parameters in the algorithms. This setting is persistent from one launch of QGIS to the next. If the user is consistently using a certain color ramp or a certain cell density, these default parameters can be set and save time later on when then algorithms are run. Here are the default settings: