User Guide

The Tree Density Calculator can be used in several ways:

  1. As a plugin in QGIS
  2. From the QGIS processing toolbox
  3. As a commandline interface
  4. Adapting the code to fulfil very specific needs

For the last option, we refer the user to the code repository and the API at the end of this document.

For issues, bugs, proposals or remarks, visit the issue tracker.

QGIS Plugin

  1. Select the remote sensing image of the forest.

  2. Determine the sliding window size.

  3. Optionally, choose a polygon vector layer representing the area(s) of interest. Trees will only be counted inside these polygons. The polygons must have an ID field.


    For output, you will get an extra polygon layer with the following attributes: the polygon area in ha, the number of trees and the tree density (trees/ha).

  4. Optionally, choose a snap distance. This distance should be maximum half of the window size.

  5. Optionally, you can have an output layer with Voronoi polygons.

  6. Optionally, choose a filename for the output layer(s).

Command Line Interface

The main command is:


Use -h or --help to list all possible arguments:

>treedensity -h

The image and sliding window size are required arguments. An example:

>treedensity data\input\image.tif 3

By default, the output shapefiles are stored in the same folder as the image file, with the extensions ‘_point.shp’, ‘_mask.shp’ and ‘_voronoi.shp’. To select another file name base (no extension) or another location, use the argument -o or --output:

>treedensity data\input\image.tif 3 -o data\other\new_name

To select a mask for counting the tree density only in a given area, use the argument -m or --mask:

>treedensity data\input\image.tif 3 -m data\input\mask.shp

To select a snap distance, use the argument -s or --snap. This distance should be maximum half of the window size:

>treedensity data\input\image.tif 7 -s 3

To create an output layer with voronoi polygons, use the argument -v or --voronoi:

>treedensity data\input\image.tif 3 -v