Spatial Aggregation Mean icon
QGIS 3 & 4 PLUGIN

Spatial Aggregation Mean

Step-by-step user manual for batch aggregation of monthly climate CSV grids to district means

Version 1.3.2 | July 2026
Authors
Mr. Akmaul Hoque  |  Dr. Manish Kumar Naskar  |  Dr. Debasish Chakraborty  |  Dr. Koushik Bag
Water Management Section, Division of System Research and Engineering (DSRE)
ICAR Research Complex for NEH Region, Umiam, Meghalaya, India

This plugin converts gridded monthly climate CSV files into district-wise monthly mean tables. It uses only native PyQGIS and the Python standard library.

No external Python installation: GeoPandas, Pandas, SciPy, Rtree, Pyogrio, Google Colab and Google Drive are not required.

1. Introduction and Purpose

The plugin reads one or many CSV files containing longitude, latitude and twelve monthly values. It assigns each valid grid point to district polygons, calculates a monthly arithmetic mean for every district and fills uncovered districts using the nearest N grid points.

Typical applications

2. Plugin Functions and Processing Logic

StageOperation
Input detectionFinds CSV files in the selected folder and optionally its subfolders.
Column detectionRecognizes accepted coordinate fields and full or abbreviated month headers.
CRS handlingTransforms the selected polygon layer internally to WGS 84 (EPSG:4326).
Internal aggregationAverages valid monthly values from grid points intersecting each district.
FallbackUses the nearest N grid points when a district contains no valid point.
ExportCreates one result CSV per input and a processing report.
Boundary points: A point exactly on a shared boundary may intersect more than one adjacent district and may contribute to both.

3. System Requirements

RequirementSupported setting
QGISQGIS 3.22+ and QGIS 4.x
Operating systemWindows, Linux or macOS
Polygon layerAny QGIS-readable polygon source, including Shapefile and GeoPackage
CSV coordinatesWGS 84 longitude and latitude in decimal degrees
PermissionsRead access to inputs and write access to output folder

4. Installing the Plugin from ZIP

  1. Save spatial_aggregation_mean_with_manual.zip. Do not extract it.
  2. Open QGIS.
  3. Choose Plugins → Manage and Install Plugins.
  4. Open Install from ZIP.
  5. Browse to the plugin ZIP and select it.
  6. Click Install Plugin.
  7. Open the Installed tab and confirm that Spatial Aggregation Mean is enabled.

Confirm successful installation

Not visible? Enable the plugin in the Installed tab and restart QGIS.

5. Preparing the District Polygon Layer

Duplicate selected values: Polygon parts with the same selected value are combined logically and produce one output row.

Recommended checks

  1. Load the boundary layer and open its Attribute Table.
  2. Check names/codes for blanks, spelling differences and duplicates.
  3. Use Vector → Geometry Tools → Check Validity when needed.
  4. Confirm the CRS under Layer Properties → Source.

6. Preparing Monthly Climate CSV Files

Accepted headers

DataAccepted field names
Longitudelong, longitude, lon, lng, x
Latitudelat, latitude, y
MonthsJanuary-December, or common abbreviations such as jan, feb, mar, sep/sept

Correct example

longitude,latitude,january,february,march,april,may,june,july,august,september,october,november,december
91.75,25.60,8.2,9.5,12.4,16.1,18.0,19.2,19.8,19.6,18.7,15.9,12.4,9.1
91.85,25.60,8.1,9.4,12.3,16.0,17.9,19.1,19.7,19.5,18.6,15.8,12.3,9.0

Rules

Avoid recursive reprocessing: Keep the output folder outside the input folder when subfolder search is enabled.

7. Running the Plugin Step by Step

  1. Add the district polygon layer to QGIS.
  2. Click the toolbar icon, or choose Vector → Spatial Aggregation Mean → Spatial Aggregation Mean.
  3. Select the District polygon layer.
  4. Select the District name or unique ID field.
  5. Browse to the folder containing input CSV files.
  6. Select a separate output folder.
  7. Keep nearest grid points at 8, unless another documented value is required.
  8. Enable subfolder search only when necessary.
  9. Keep _DistrictMean or enter a suitable output suffix.
  10. Click Run.
  11. Review the Log for files processed, invalid rows, fallback districts and saved paths.
  12. Open the output folder and inspect the report and result CSVs.
Processing Toolbox route: Processing Toolbox → Spatial Aggregation Mean → Climate aggregation → Spatial Aggregation Mean.

8. Understanding Plugin Parameters

ParameterPurposeRecommended
District polygon layerDefines reporting units.Clean boundary layer.
District fieldCreates output rows and groups repeated polygon parts.Unique code or standardized name.
Input folderContains monthly gridded CSV files.One variable/scenario per run.
Output folderStores result CSVs and report.Separate writable folder.
Nearest grid pointsControls fallback average.8.
Recursive searchIncludes CSV files in subfolders.Off unless needed.
Output suffixText added before .csv._DistrictMean

A smaller nearest count preserves more local variation; a larger count creates a smoother estimate. Use the same setting across comparable datasets.

9. Understanding Outputs and Reports

Input model_01.csv produces model_01_DistrictMean.csv by default.

DISTRICT,january,february,march,april,may,june,july,august,september,october,november,december
East Khasi Hills,7.93,9.18,12.21,15.87,17.71,18.93,19.54,19.31,18.42,15.61,12.10,8.87
Ri Bhoi,8.41,9.72,12.88,16.52,18.35,19.64,20.13,19.92,18.98,16.17,12.69,9.36

Processing report

ColumnMeaning
input_csvSource path.
statussuccess or failed.
output_csvCreated output path.
grid_pointsValid coordinate rows used.
districts_with_pointsDistricts containing grid points.
districts_nearest_fallbackDistricts using nearest-point values.
messageError reason for failed inputs.
No overwriting: If an output already exists, the plugin creates _2, _3 and so on.

10. Quality-Control Checks

Before running

After running

January mean = (8.0 + 8.5 + 9.0) / 3 = 8.5

11. Common Errors and Troubleshooting

Message/symptomCauseAction
No CSV files foundWrong folder or files only in subfolders.Select correct folder or enable recursive search.
Longitude/latitude not foundUnsupported field names.Rename to longitude/latitude or lon/lat.
Missing month columnsMonth absent or misspelled.Add all 12 accepted month fields.
No valid grid rowsCoordinates blank, swapped, projected or out of range.Correct coordinates to WGS 84 decimal degrees.
Many fallback districtsGrid/boundary mismatch or coarse coverage.Display a sample point layer and inspect overlap.
Permission deniedFile open or folder read-only.Close files and use a writable local folder.
Plugin shown as incompatible/deprecated in QGIS 4An older plugin ZIP with qgisMaximumVersion=3.99 is installed.Uninstall the older version, restart QGIS, and install version 1.3.2 or later.
Manual does not openIncomplete installation or missing browser association.Reinstall complete ZIP or open docs/user_manual.html.

Diagnose coordinate problems

  1. Use Layer → Add Layer → Add Delimited Text Layer.
  2. Set X to longitude and Y to latitude.
  3. Set CRS to EPSG:4326.
  4. Compare points with the district boundary.
  5. If points appear in another country or the ocean, check swapped fields and decimal formatting.

12. Updating, Disabling and Uninstalling

  1. Finish or cancel active processing.
  2. Open Installed plugins.
  3. Disable or uninstall the previous version.
  4. Restart QGIS if Windows keeps files locked.
  5. Install the new ZIP and test one sample file.

Uninstalling the plugin does not remove previously generated outputs.

13. Processing Toolbox and Model Designer Use

The plugin is a QGIS Processing provider and can be added to a graphical model. Create model inputs for the polygon layer, district field, input folder and output folder, then add Spatial Aggregation Mean.

Model limitation: Multiple CSV files are written to a folder; the graphical model does not automatically load all of them as map layers.

14. Technical Notes and Limitations

Recommended citation

Chakraborty, D., Hoque, A., Naskar, M. K., & Bag, K. (2026). Spatial Aggregation Mean: QGIS plugin for district-wise aggregation of gridded monthly climate data (Version 1.3.2). Water Management Section, DSRE, ICAR Research Complex for NEH Region, Umiam, Meghalaya, India.

15. Quick-Reference Checklist

Appendix: Glossary

TermMeaning in this plugin
CSVA delimited text table saved with the .csv extension.
CRSCoordinate reference system used to locate spatial data correctly.
WGS 84 / EPSG:4326Longitude-latitude coordinate system expected for CSV points.
Point-in-polygonTest used to determine which district contains or intersects a grid point.
Nearest neighbourClosest point or set of points to a district reference point.
Fallback districtA district without an internal grid point, filled from the nearest N points.
Processing reportCSV summary of input paths, outputs, status and error messages.

Support and Institutional Contact

Water Management Section, DSRE
ICAR Research Complex for NEH Region
Umroi Road, Umiam, Ri-Bhoi, Meghalaya - 793103, India
Email: akmaulhoque41@gmail.com

For support: Provide the QGIS version, operating system, one sample CSV header, selected polygon field, exact error message and processing report.