Module 5/5 · Weeks 13–15 · 27 h

Spatial analysis and GIS mapping

UAT 452 Remote Sensing and Geographic Information Systems for UAS

About 85 minDraft, awaiting reviewLast updated 21 October 2026

Lesson

By the end of this module you will be able to

  1. Use zonal statistics, buffers and overlays to answer spatial questions
  2. Detect change between two dates with a threshold based on data error
  3. Produce maps with all essential elements that communicate correctly
  4. Integrate drone and satellite data to support decisions
  5. Design a two-table project database and join it with other geospatial data

Prerequisites: Module 4 Spatial data structures and coordinate systems

Why this matters

All the data prepared so far are only valuable if they help staff decide: which fields to visit first, which are affected by falling canal water, and whether a change seen in the images is real or just data error. This module brings together the most used spatial analysis tools and ends with a map delivered to real users.

Zonal statistics, buffers and overlays

  • Zonal statistics summarise raster values within each polygon, such as mean NDVI per field, turning millions of pixels into an easy table
  • Buffers create an area within a set distance of a feature, such as 30 m from the canal
  • Overlays, such as intersect or union, find which fields lie within the buffer and by how much

Example 1 Finding fields to visit

Mean NDVI from zonal statistics (a short sample of 4 values per field) and the buffer of a 1,000 m canal.

import math

ndvi = {  # NDVI values per plot for zonal statistics
    "P01": [0.78, 0.81, 0.80, 0.79], "P02": [0.74, 0.76, 0.75, 0.73],
    "P03": [0.52, 0.49, 0.61, 0.55], "P04": [0.80, 0.79, 0.82, 0.81],
}
LIMIT = 0.65
for plot, values in ndvi.items():
    mean = sum(values) / len(values)
    print(f"{plot}: mean NDVI {mean:.3f} {'-> field check' if mean < LIMIT else ''}")

L, D = 1000, 30                           # canal 1,000 m long, 30 m buffer on both sides
print(f"buffer area {2 * D * L + math.pi * D * D:,.0f} m2 (flat sides + round ends)")
P01: mean NDVI 0.795 
P02: mean NDVI 0.745 
P03: mean NDVI 0.542 -> field check
P04: mean NDVI 0.805 
buffer area 62,827 m2 (flat sides + round ends)

Field P03 has a mean NDVI of about 0.54, below the 0.65 threshold the office set for this rice stage, so it is the first to visit. A 30 m buffer on both sides of the canal with round ends covers m², used to find which fields will be affected by upcoming canal dredging.

Top view of four paddy fields, P01 and P02 above and P03 and P04 below, with a blue canal and its round-ended buffer running between the two rows. Field P03 is pink, showing NDVI below 0.65; the others are green
Figure 1 Four paddy plots and the canal buffer

Change detection

Comparing images from two dates is the most direct way to find newly emerging problems, but every image has error. If one date has error and the other , the difference has error

A change counts as real only if the difference exceeds , with a common choice. If errors are normal and independent, pure error exceeds this threshold only about 5% of the time.

Example 2 Did NDVI really fall?

The NDVI error on each date is about 0.03, estimated from areas that should not change, such as a concrete yard.

import math

SIGMA = 0.03                              # NDVI error on each date (standard deviation)
sigma_diff = SIGMA * math.sqrt(2)         # error of the two-date difference
threshold = 2 * sigma_diff
before = [0.80, 0.79, 0.81, 0.78, 0.80, 0.77]
after = [0.78, 0.81, 0.62, 0.55, 0.79, 0.72]
print(f"sigma of difference {sigma_diff:.3f}, threshold {threshold:.3f}")
for i, (a, b) in enumerate(zip(before, after), 1):
    d = b - a
    print(f"cell {i}: change {d:+.2f} {'-> real change' if abs(d) > threshold else ''}")
sigma of difference 0.042, threshold 0.085
cell 1: change -0.02 
cell 2: change +0.02 
cell 3: change -0.19 -> real change
cell 4: change -0.23 -> real change
cell 5: change -0.01 
cell 6: change -0.05 

Cells 3 and 4 fell by 0.19 and 0.23, well beyond the threshold of about 0.085, so they count as real change. Cell 6 fell by 0.05, which looks like a drop but is within the error. Before comparing, both images must be in reflectance (module 2) and co-registered; otherwise apparent differences may come from calibration or image shifts.

Bar chart of NDVI differences for six cells, vertical axis from minus 0.3 to plus 0.3, with dashed purple lines at plus and minus 0.085. Cells 3 and 4 fall beyond the line as pink bars; the other cells are small blue bars within the threshold
Figure 2 NDVI difference between two dates against the threshold

Pairs that can be compared

Before subtracting, ask whether the two dates are comparable. There are three conditions. One: NDVI can actually be computed on each date. If NIR + Red is zero the denominator is zero and the result is undefined (NoData), not 0, because 0 describes a surface whose NIR equals its Red, such as bare soil. Two: both dates have a reflectance calibration and illumination record (module 2). Three: the two images lie on the same positions (band registration and date-to-date alignment). Conditions two and three are different things. Reflectance calibration gives the numbers the same meaning; alignment makes the pixels refer to the same ground. Having one does not imply the other. A pair that fails a condition goes on the open-items list with a request for evidence, and no difference is delivered.

The same idea applies to monitoring a waterline or shoreline on two dates. The position of the waterline moves with the water level. Without the water level and one shared height reference for both dates, a measured shift in distance cannot yet be concluded to be coastal change.

Example 3 Four zones, two dates and comparability

Use the threshold from Example 2 ( = 0.03 per date). Zone Z3 has the same NDVI on both dates, but the second date has no calibration record. Zone Z4 has no data on the first date (Red and NIR are both 0).

import math

SIGMA = 0.03                                   # NDVI error per date, as in Example 2
THRESHOLD = 2 * SIGMA * math.sqrt(2)           # 2 x sigma of the difference

def ndvi(red, nir):
    """NDVI, or None (NoData) when the denominator is zero."""
    return None if nir + red == 0 else (nir - red) / (nir + red)

# zone: (red, nir, radiometric record present) for date 1 and date 2
zones = {
    "Z1": ((0.22, 0.58, True), (0.20, 0.60, True)),
    "Z2": ((0.14, 0.66, True), (0.26, 0.54, True)),
    "Z3": ((0.12, 0.68, True), (0.12, 0.68, False)),
    "Z4": ((0.00, 0.00, True), (0.10, 0.50, True)),
}
for zone, (d1, d2) in zones.items():
    n1, n2 = ndvi(d1[0], d1[1]), ndvi(d2[0], d2[1])
    if n1 is None or n2 is None:
        status = "HOLD: NDVI undefined on one date"
    elif not (d1[2] and d2[2]):
        status = "HOLD: no radiometric record"
    else:
        d = n2 - n1
        status = f"delta {d:+.2f} " + ("-> real change" if abs(d) > THRESHOLD else "-> within error")
    shown = [f"{n:.2f}" if n is not None else "n/a" for n in (n1, n2)]
    print(f"{zone}: NDVI {shown[0]} -> {shown[1]}  {status}")
print(f"threshold {THRESHOLD:.3f}")
Z1: NDVI 0.45 -> 0.50  delta +0.05 -> within error
Z2: NDVI 0.65 -> 0.35  delta -0.30 -> real change
Z3: NDVI 0.70 -> 0.70  HOLD: no radiometric record
Z4: NDVI n/a -> 0.67  HOLD: NDVI undefined on one date
threshold 0.085

Z1 is comparable and differs by only +0.05, which is inside the error; this does not mean the crop improved by 5%. NDVI is dimensionless, so a difference of 0.05 is 0.05 index units. Z2 is comparable and fell by 0.30, far beyond the threshold, so it is the first zone to send people to inspect, with the cause still unknown. For Z3, equal numbers do not show that the crop stayed the same, because we do not know whether the light on the second date differed from the first. Z4 offers only the second-date value, a single-date figure and not a difference.

Integrating drone and satellite data

In the case study the office uses both sources:

  1. Sentinel-2 on every clear pass to monitor field NDVI across the district and find fields with unusual drops
  2. The multispectral drone flown only over fields the satellite flags, to see whether the problem is patchy or covers the whole field
  3. Staff visits to the spots the drone highlights to confirm the cause, such as water shortage, disease or pests, recorded as checkpoints for the next map assessment

This tiered approach saves a great deal of flying, because not every field needs to be flown every week.

Making the map

A map delivered to users must be understandable without anyone explaining it. Essential elements:

  • A title stating the subject, area and data date
  • A legend explaining colours and value ranges
  • A scale bar and north arrow
  • Coordinate system, data sources and author

Colours must match the data type. Ordered values such as NDVI use a light-to-dark ramp in one or two hues; categories such as rice, water and soil use clearly different colours. Choose schemes that people with colour-vision deficiency can distinguish, not red versus green alone.

The project database and joining other geospatial data

Results from several rounds belong in a database, not in a new column added every day (Shapefile column names are limited to 10 characters, as module 4 noted). Design two tables: a plot table with one row per plot, and an observation table with one row per plot per date. The plot ID is the primary key of the plot table and a foreign key in the observation table, which stops observations from referring to a plot that does not exist. A GeoPackage is a single SQLite file that holds vectors, raster tiles and attribute tables under the OGC standard (version 1.4.0), so this SQL works on it, but SQLite enforces foreign keys only when PRAGMA foreign_keys = ON is issued on every connection. Store a missing value as NULL, not 0, by the same rule as NoData.

Data from other agencies, such as canals, land-use plans or land parcels, joins to the drone results with Join attributes by location in QGIS. Choose a relationship such as intersect or within, and choose a one-to-one or one-to-many join. Before joining, check the datum and coordinate system of every layer (the datum section in module 4), and record the source, the date and the accuracy of each layer.

Example 4 Storing two rounds for three plots and querying with SQL

Use the 0.085 threshold from Example 2. For plot P03 the NDVI of the second round could not be computed, so it is stored as NULL.

import sqlite3

db = sqlite3.connect(":memory:")
db.execute("PRAGMA foreign_keys = ON")    # SQLite checks foreign keys only when asked
db.executescript("""
CREATE TABLE plot (plot_id TEXT PRIMARY KEY);
CREATE TABLE observation (
    plot_id TEXT NOT NULL REFERENCES plot (plot_id), obs_date TEXT NOT NULL, ndvi REAL,
    PRIMARY KEY (plot_id, obs_date));
""")
db.executemany("INSERT INTO plot VALUES (?)", [("P01",), ("P02",), ("P03",)])
db.executemany("INSERT INTO observation VALUES (?, ?, ?)", [
    ("P01", "09-05", 0.80), ("P01", "09-19", 0.79), ("P02", "09-05", 0.75), ("P02", "09-19", 0.62),
    ("P03", "09-05", 0.70), ("P03", "09-19", None)])   # None = NULL = no valid NDVI
try:
    db.execute("INSERT INTO observation VALUES ('P99', '09-19', 0.5)")
except sqlite3.IntegrityError as err:
    print("rejected:", err)
rows = db.execute("""SELECT a.plot_id, b.ndvi - a.ndvi FROM observation a JOIN observation b
    ON a.plot_id = b.plot_id AND a.obs_date = '09-05' AND b.obs_date = '09-19' ORDER BY a.plot_id""")
for plot_id, delta in rows:
    verdict = "HOLD: no valid NDVI" if delta is None else ("real change" if abs(delta) > 0.085 else "within error")
    print(plot_id, "n/a" if delta is None else f"{delta:+.2f}", verdict)
rejected: FOREIGN KEY constraint failed
P01 -0.01 within error
P02 -0.13 real change
P03 n/a HOLD: no valid NDVI

The database refuses P99, which is not in the plot table. P02 changed for real (-0.13), P01 is within the error, and P03 is held back instead of being counted as zero, because NULL minus anything is NULL. The result matches Example 3, but a new round is added as new rows, with no change to the table structure.

Module lab

Lab: from data to a work-order map

  1. Compute mean NDVI per field with Zonal Statistics in QGIS from the module 3 raster, checking against the code in Example 1
  2. Create a 30 m buffer around the canal, intersect it with the fields layer, and find each field’s area inside the buffer
  3. Take NDVI from two dates of Sentinel-2 or drone data, compute the difference, estimate from unchanging areas, and apply the threshold in Example 2
  4. Produce a one-page A4 work-order map showing fields to visit, with all map elements
  5. Have another group read the map without explanation, and record what they misunderstood

Common mistakes

Watch out

  • Judging a whole field from a single pixel’s NDVI instead of zonal statistics
  • Buffering in a geographic coordinate system while entering the distance in metres
  • Treating every difference as real change without comparing it with data error
  • Comparing two dates that were not calibrated to reflectance
  • Maps without a legend, date or coordinate system, or using red versus green alone

Summary

  • Zonal statistics summarise raster values per polygon; buffers and overlays answer what is near or overlapping
  • A two-date difference has error ; count change as real beyond about
  • Use satellites for overviews, drones for detail and field visits to confirm causes
  • Maps need a title, legend, scale bar, north arrow, coordinate system and sources, with colours suited to the data type

Check your understanding

  1. What are zonal statistics used for?
  2. What is the approximate area of a 20 m round-ended buffer on both sides of a 500 m line?
  3. With NDVI error of 0.04 on each of two dates, what is the error of the difference?
  4. Using the threshold from question 3, does a difference of −0.10 count as real change?
  5. Why should maps not rely on red versus green alone?
Answers
  1. To summarise raster values, such as the mean, within each polygon
  2. m²
  3. The threshold is about 0.113, so a 0.10 difference does not yet count as real change
  4. People with red-green colour-vision deficiency cannot tell them apart

Key formulas

Error of a two-date difference
Change threshold
Buffer area of a straight line

Key references

  1. Longley, P. A., Goodchild, M. F., Maguire, D. J., & Rhind, D. W. (2015). Geographic information science and systems (4th ed.). Wiley.
  2. QGIS Project. QGIS user guide. link
  3. Lillesand, T., Kiefer, R. W., & Chipman, J. (2015). Remote sensing and image interpretation (7th ed.). Wiley. link
  4. European Space Agency. S2 mission. SentiWiki (Copernicus). link
  5. Congalton, R. G. (1991). A review of assessing the accuracy of classifications of remotely sensed data. Remote Sensing of Environment, 37(1), 35-46. https://doi.org/10.1016/0034-4257(91)90048-B link
  6. Open Geospatial Consortium. OGC GeoPackage encoding standard (version 1.4.0). link
  7. SQLite. SQLite foreign key support. SQLite documentation. link
  8. QGIS Project. Vector general: Join attributes by location. QGIS user guide. link
  9. Supavetch, S., & Chunithipisan, S. (2012). The development of RTSD coordinates transformation service for mobile device. In Proceedings of the Asian Conference on Remote Sensing 2012 (ACRS 2012). Asian Association on Remote Sensing. link

Further reading

Study the assigned knowledge units in advance, review media and take the module quiz

In class / field

Lab or field practice from worksheets with a safety checklist

Learning evidence: Checked worksheets and quiz results

Module quiz

This is a formative self-check, not a graded exam

Knowledge domain: Surveying, mapping and geoinformatics · Inspection, industry and surveillance · Artificial intelligence and computer vision · Aircraft, structures and design