NewRainfall, irrigation & groundwater report for your coffee estate

QGIS Scripts Setup & User Guide

This guide covers the one-time QGIS setup and how to run any Future Thota QGIS script. It applies to every script, whether you bought it on its own or as part of the full package. Each script’s own inputs, outputs and settings are described in the README.txt included in your download, and in the comment block at the top of the script itself.

1. One-time setup

1.1 Install QGIS

Install QGIS 3.28 or newer from qgis.org. The Long Term Release (LTR) is recommended. The scripts run inside QGIS’s built-in Python, so you don’t need to install Python separately. They work on Windows, macOS and Linux.

1.2 Check the Python packages

numpy and GDAL come with every QGIS install, and several scripts need nothing else. Some scripts also use rasterio, scipy, shapely, pyproj or matplotlib. These are included in some QGIS installs but not all. Your download’s README.txt lists exactly which ones your scripts need.

To check what your QGIS has, open QGIS, go to Plugins → Python Console, paste this line into the console and press Enter:

import importlib.util as u; print("\n".join(m + (": OK" if u.find_spec(m) else ": MISSING") for m in ["numpy", "osgeo", "matplotlib", "pyproj", "rasterio", "scipy", "shapely"]))

You only need OK for the packages your scripts use. If numpy or osgeo (GDAL) shows MISSING, your QGIS install is incomplete, so reinstall QGIS. If any other package your scripts need shows MISSING, install it as follows, then restart QGIS.

Windows

  1. Close QGIS.
  2. Open the Start menu and launch OSGeo4W Shell, which is installed together with QGIS.
  3. Run the following, listing only the packages you need:
python -m pip install rasterio scipy shapely pyproj matplotlib

If import rasterio then fails in QGIS with a “DLL load failed” error, the pip version doesn’t match QGIS’s own GDAL. Uninstall it (python -m pip uninstall rasterio) and use the QGIS installer’s own package instead. Run OSGeo4W Setup, choose Advanced Install, search for python3-rasterio, and install it. This only works if you installed QGIS with the OSGeo4W network installer.

macOS

  1. In the QGIS Python Console, run this to find QGIS’s own Python:
import sys, os; print(os.path.join(sys.exec_prefix, "bin", "python3"))
  1. Close QGIS, open Terminal, and run the following. Replace the path with the one printed above and keep the quotes:
"/path/printed/above/python3" -m pip install --user rasterio scipy shapely pyproj matplotlib

Linux (Ubuntu / Debian)

sudo apt install python3-rasterio python3-scipy python3-shapely python3-pyproj python3-matplotlib

Re-run the check line afterwards to confirm.

2. Running a script

2.1 Put your data on disk

Load your rasters (.tif) and vector layers (.geojson, .shp, .gpkg) into a QGIS project from files on disk. Results are saved next to the input files, so temporary or scratch layers won’t work as inputs.

2.2 Select the inputs: active and checked layers

There is no dialog box. Scripts find their inputs from the Layers panel. Each script’s reference says which of these it needs:

  • Checked layer: a layer whose tick box is ticked (visible) in the Layers panel. Rasters such as DSM, DTM and NDVI are usually found this way, by their layer name (see 2.3).
  • Active layer: the single layer you have clicked on (highlighted) in the Layers panel. This is usually the vector layer being analysed.

Untick layers you don’t want used. If a script needs one DSM and finds two ticked, it uses the first one in the Layers panel.

2.3 Layer naming

Raster inputs are recognised by their layer name, and capitalisation doesn’t matter. To rename a layer, right-click it in the Layers panel and choose Rename Layer.

Name containsMeaning
_dsmDigital Surface Model (top of trees, buildings and ground)
_dtmDigital Terrain Model (bare ground)
_ndviNDVI raster
_chmCanopy Height Model
canopy_maskBinary canopy mask (1 = canopy, 0 = not)

For example: farm_north_dsm, farm_north_dtm. The exact rule for each script is in its reference section.

2.4 Run it

  1. Go to Plugins → Python Console.
  2. Click Show Editor (the notepad icon) in the console toolbar.
  3. Click Open Script… (the folder icon) and choose the .py file.
  4. Click Run Script (the green ▶ triangle).

Progress messages appear in the Python Console. When the script finishes, the output is added to your project automatically.

Large rasters can take a few minutes, and QGIS may look frozen while a script is working. Let it finish.

2.5 Logs

Each script also writes a log file to a QGIS_Projects folder in your Documents folder:

  • Windows: C:\Users\<you>\Documents\QGIS_Projects\
  • macOS: /Users/<you>/Documents/QGIS_Projects/
  • Linux: /home/<you>/Documents/QGIS_Projects/

The folder is created automatically. If something goes wrong, the log shows which layers the script saw and the full error message. Include it if you contact support.

2.6 Customising

Settings such as thresholds, intervals, colours and lighting are plain values in the script, either near the top of the file or in the function call at the very bottom. The “Customize” line in each script’s reference says where. Edit them in the QGIS script editor, save, and run again.

3. Troubleshooting

“ModuleNotFoundError: No module named ’…’” A Python package is missing. See section 1.2.

“Could not find … in checked layers” or “No active layer” Check that the layer is ticked (or highlighted, for the active layer) and that its name matches the rule in the script’s reference. The first lines of the console output list the layers the script saw.

Results look shifted, or heights or areas are wrong Make sure all inputs use the same projected coordinate system in metres (for example a UTM zone), not degrees (EPSG:4326). Several scripts reproject vectors automatically, but rasters should match each other.

QGIS appears frozen The script is usually still working on a large raster. Wait, and watch the log file grow.

The output didn’t appear in the project Look in the folder of the input file. The output file is saved there even if loading it into QGIS failed.

4. Support

For questions, bugs or custom changes, email [email protected]. Step-by-step tutorials for each script are on the blog, and every script is listed on the QGIS scripts page.