← All projects
QGIS PluginPyQGISRaster AnalysisOpen Source
RasterSample — QGIS Plugin
Sketch polygons on the map, inspect raster statistics inside them, and save the ones you keep as sample features. An interactive QGIS plugin, built from a FOSS4G PyQGIS workshop checkpoint and published on the official QGIS Plugin Repository.
The Question
- Pulling raster statistics for a hand-drawn area of interest in QGIS usually means digitizing a layer, running Zonal Statistics as a separate tool, and repeating that round trip for every polygon — could sketching, inspecting, and saving be one continuous action instead?
- Could it be built cleanly enough, and reviewed rigorously enough, to publish on the official QGIS Plugin Repository rather than stay a personal script?
Approach
- Built from the final checkpoint of the FOSS4G Advanced PyQGIS Scripting and Automation workshop, then developed into a full plugin with a dock panel UI and message-bar feedback in place of
print()debugging - Statistics are computed inside the polygon with
QgsZonalStatistics, not over its bounding box, and the polygon is reprojected to the raster’s CRS first — so results stay correct even when the project CRS differs from the raster’s - Layer and band are chosen explicitly in the panel rather than assumed from the active layer
- Written Qt6-ready from the start — imports through
qgis.PyQt, scoped enums,QMetaTypefield types — so the same codebase runs on QGIS 3.40+ (Qt5) and QGIS 4 (Qt6) - Reviewed and approved by a QGIS.org plugin reviewer and published to the official Plugin Repository as Raster Inspector (now listed under its current name, RasterSample)
Features
- Sketch: left-click to add polygon vertices, right-click to finish
- Inspect: the panel shows mean, min, max, and pixel count for the polygon as soon as it closes
- Save or discard: add a sample ID and note, then press S to save to a memory layer, or Esc to drop it
- Sample schema: saved features carry
sample_id, note, raster, band, mean, min, max, pixel_count, created— ready to export with Save Features As… - Ships with a real test raster — a 30 m Denali-area DEM — so the workflow can be tried immediately after install
Sample Data
