QGIS Script · Python
Survey Grid Generator
Subdivides any field or area into equal-sized rectangular cells clipped to your polygon boundary. Set one parameter — cell size in metres — and the script handles the rest. Each cell becomes a sampling unit: pair the output with the Zonal Statistics Calculator to compute mean or median NDVI, NDRE, NDWI, or any other index per cell — then take action at the grid level rather than the whole-field level.
What you get
grid_generation.pyWhat it does
Equal-sized rectangular cells
Generates a regular grid where every cell is the same width and height in metres. Set grid_size at the bottom of the script — e.g. 10 for a 10×10 m grid, 50 for 50×50 m.
Clip to polygon boundary
If polygon layers are checked, the grid is clipped to their combined shape. Only cells inside the boundary are kept — irregular field shapes are handled cleanly.
Auto UTM reprojection
Detects geographic CRS (degrees) and automatically reprojects to the appropriate UTM zone so your cell size is in real metres, not decimal degrees.
Grid cells only — index calculation is separate
This script generates the grid geometry. To get NDVI, NDRE, NDWI, or any other index per cell, run the Zonal Statistics Calculator on the grid output. The two scripts are designed to work together.
How to use it
- 1
Load your boundary polygon layer and check (tick) it in the Layers panel.
- 2
Open Plugins → Python Console → Show Editor.
- 3
Paste the script. At the bottom, set
grid_sizein metres (e.g.50for a 50×50 m grid). - 4
Click Run.
Pairs well with
This script generates the grid only. To sample vegetation indices per cell, use it with:
- Zonal Statistics Calculator — computes mean or median of any raster (NDVI, NDRE, NDWI, elevation) per grid cell; best for fully covered fields where crops fill each cell
- Canopy NDVI Median Calculator — canopy-only NDVI per polygon, suited to tree crops or orchards where individual canopies are mapped; requires DTM and DSM to generate the canopy mask that excludes bare soil
- Layer Colour Classifier — colour-code each grid cell by its index value for visual field maps
Requirements
- QGIS 3.28 or newer
- QGIS processing framework — bundled
- (Optional) polygon GeoJSON layers to clip the grid
Also in the GIS Utilities Pack
Get all 4 GIS utility scripts for $49 — save $29 vs buying individually.