Your country

Tools that support it use your country for local currency, number formats, units and paper size. Your choice is saved only in this browser.

Type a name or a two-letter code. Use the up and down arrow keys to move through the countries, Enter to choose one and Escape to close.

GIS & Geospatial Data (QGIS, GeoPandas, PostGIS)  Module 6 – Raster data and remote sensing

Map algebra, NDVI and reclassification

Combine aligned bands cell by cell, compute NDVI and both NDWIs so nodata never leaks, avoid integer traps and reclassify with thresholds you record.

  • Intermediate
  • 20 minutes
  • Examples run with Python 3.14.8 and Pyodide 314.0.7
  • By MySmartCoPilot
Free core, Pro depth: 7 of 20 minutes free
Free: Map algebra applies one formula to every cell of aligned grids · NDVI and NDWI measure the contrast between two bands. With a pass: 2 in-depth parts and 3 interview answers, about 13 minutes.

What you will learn

  • Combine aligned bands cell by cell with a mask, so that nodata never reaches a result
  • Compute NDVI and NDWI and explain what their values mean
  • Avoid integer overflow, zero denominators and unscaled values in band maths
  • Classify a continuous raster with thresholds you can defend and record

Before you start

What you’ll learn · Before you start

What you will learn

  • Combine aligned bands cell by cell with a mask, so that nodata never reaches a result
  • Compute NDVI and NDWI and explain what their values mean
  • Avoid integer overflow, zero denominators and unscaled values in band maths
  • Classify a continuous raster with thresholds you can defend and record

Before you start

On this page

A field reflects 0.0494 of red light and 0.4214 of near-infrared: (0.4214 − 0.0494) ÷ (0.4214 + 0.0494) = 0.790, the NDVI (normalised difference vegetation index): (NIR − red) ÷ (NIR + red), from −1 to 1: negative over water and rising with green leaves, which absorb red light and reflect near-infrared strongly. of dense, healthy crop. Map algebra repeats that formula for every cell of aligned rasters, 480,000 times for the lesson raster, and writes a new raster of the answers.

Here you combine bands cell by cell with a mask that keeps missing cells missing, compute NDVI and the two indices that share the name NDWI (normalised difference water index): A name shared by two indices: McFeeters' (green − NIR) ÷ (green + NIR), which outlines open water, and Gao's (NIR − SWIR) ÷ (NIR + SWIR), which senses water in leaves. A map should say which bands it used., and read what their values say about water, soil, towns and crops. Then you reproduce band maths that goes wrong without an error, and turn NDVI into classes with thresholds you can defend.

Map algebra applies one formula to every cell of aligned grids

map algebra: Computing a new raster from one or more aligned rasters with a formula applied cell by cell, such as a band ratio, a sum or a comparison with a threshold. Kinds that also read a cell's neighbours or a whole zone are moving-window and zonal operations. computes a raster from one or more rasters with a formula that works on each cell by itself: add two bands, divide one by another, compare a band with a threshold. The inputs must be aligned, with the same CRS, pixel size, origin and number of rows and columns, so that row 418, column 100 is the same patch of ground in each; the next lesson shows how to get there. Here is a corner of the lesson raster, three rows by three columns, through the NDVI formula:

Red and near-infrared grids of 3 by 3 cells combined cell by cell into an NDVI grid; the cell missing in both inputs stays nodata.One formula, cell by cellred, band 12217221549422102209496220922100near-infrared, band 2281728154214281028094216280928100NDVI = (NIR - red) / (NIR + red)0.1190.1190.7900.1200.1200.7890.1200.120nodataRows 418 to 420, columns 98 to 100.Dashed: nodata in, nodata out. Blue: NDVI > 0.5.

Rows 418 to 420 and columns 98 to 100 of the lesson raster, through the NDVI formula

Text description of the diagram

Two grids of 3 rows and 3 columns sit side by side at the top. The left one holds the red band: 2217, 2215 and 494 in the first row; 2210, 2209 and 496 in the second; 2209, 2210 and 0 in the third. The right one holds the near-infrared band: 2817, 2815 and 4214; 2810, 2809 and 4216; 2809, 2810 and 0. In both, the bottom-right cell, which holds 0, is drawn grey with a dashed outline: it has no data.

Under them the formula NDVI = (NIR − red) / (NIR + red) points down to a third grid with the result of each cell: 0.119, 0.119 and 0.790 in the first row; 0.120, 0.120 and 0.789 in the second; 0.120, 0.120 and nodata in the third. The two cells above 0.5, 0.790 and 0.789, are shaded light blue: a field of crop. The six cells near 0.12 are bare soil. The bottom-right cell is grey with a dashed outline and reads nodata, because a cell missing in an input stays missing in the output.

Two cells are crop, 0.790 and 0.789, six are bare soil, about 0.12, and one lies in the hole without data. A cell missing in either input must stay missing in the output, whatever its nodata value: A value, such as -9999, that marks a raster cell with no measurement. It is a code, not data, and must be left out of sums, means and counts. More in “Vector and raster data models”. Follow both kinds of cell through the steps:

Interactive · stage by stage One cell through masked map algebra Follow two cells of the lesson raster through the same steps, one with data in both bands and one in the hole without data.
One cell through masked map algebra, step 7 of 7. Showing Read both bands' cell (red 0, NIR 0), Is either value nodata? (yes: nodata), Apply the formula ((NIR - red) / (NIR + red)), Write the output cell (row 420, col 100: nodata). In focus: Write the output cell.yes: write nodataRead both bands' cellred 0, NIR 0Is either value nodata?yes: nodataApply the formula(NIR - red) / (NIR + red)Write the output cellrow 420, col 100: nodata

The drawing shows the whole scene; its 7 steps are listed below.

Every step as text
  1. A cell with data. Row 418, column 100 holds red 494 and near-infrared 4214. Map algebra reads the same cell of both bands, which is why the two grids must line up pixel for pixel.
  2. Check the mask. Neither value is the nodata value, so the cell goes on to the formula.
  3. The formula. (4214 − 494) ÷ (4214 + 494) = 3720 ÷ 4708 = 0.790, a field of dense, healthy crop.
  4. The result. The output raster gets 0.790 in the same row and column. Every other cell goes through the same steps, on its own.
  5. A cell in the hole. Row 420, column 100 is in the hole of 2,400 pixels without data, so both bands hold 0.
  6. The mask decides. Red is the nodata value, so the formula is never reached. Computing it would divide 0 by 0, or worse, give a number that looks like data.
  7. Nodata goes through. The output cell becomes nodata too. A cell missing in any input is missing in the result, so no statistic of the output can count it.

The program applies those steps to all 480,000 pixels and averages the result for each kind of ground:

scene.py: the lesson raster the programs share Python · algebra/scene.py
"""The lesson's raster: two bands, red and near-infrared, of 800 by 600 pixels of 10 m in UTM zone 43N.

Each value is a reflectance times 10,000, stored as an unsigned 16-bit integer, and 0 marks a pixel without data.
The scene is made by whole-number formulas, so every program that imports it, here or in a browser, gets the
same numbers: a river, fields of crops and bare soil, a town, and a hole of 2,400 pixels with no data.
"""

WIDTH, HEIGHT = 800, 600  # columns, rows
TRANSFORM = (10.0, 0.0, 370_000.0, 0.0, -10.0, 2_046_000.0)  # a, b, c, d, e, f
CRS = "EPSG:32643"  # WGS 84 / UTM zone 43N
NODATA = 0


def noise(row, col):
    """A fixed whole number from -40 to 40 for each row and column, the same on every computer."""
    h = ((row * 73_856_093) ^ (col * 19_349_663)) & 0xFFFFFFFF
    h = ((h ^ (h >> 13)) * 1_274_126_177) & 0xFFFFFFFF
    return h % 81 - 40


def wobble(row, col):
    """Texture that changes smoothly over 16 pixels, as real ground does, plus a little noise of its own."""
    r, c, fr, fc = row // 16, col // 16, row % 16, col % 16
    top = noise(r, c) * (16 - fc) + noise(r, c + 1) * fc
    bottom = noise(r + 1, c) * (16 - fc) + noise(r + 1, c + 1) * fc
    return (top * (16 - fr) + bottom * fr) // 256 + noise(row, col) // 8


def cover(row, col):
    """What lies under a pixel: water, town, soil, crop, or None in the hole without data."""
    if 420 <= row < 460 and 100 <= col < 160:
        return None
    if abs(row - (260 + col * col // 4000)) < 18:
        return "water"
    if 60 <= row < 200 and 520 <= col < 700:
        return "town"
    field_row, field_col = row // 80, col // 100
    if (field_row * 3 + field_col) % 5 == 0:
        return "soil"
    return "crop"


def pixel(row, col):
    """(red, nir) of one pixel, reflectance times 10,000."""
    kind = cover(row, col)
    if kind is None:
        return NODATA, NODATA
    w = wobble(row, col)
    if kind == "water":
        return 350 + w, 200 + w // 2
    if kind == "town":
        return 1_700 + w, 2_200 + w
    if kind == "soil":
        return 2_200 + w, 2_800 + w
    vigour = ((row // 80) * 7 + (col // 100) * 13) % 10  # 0 to 9, one value per field
    return 800 - vigour * 40 + w, 3_000 + vigour * 150 + (col % 100) * 3 + w


def bands():
    """The two bands as lists of rows: red, then near-infrared."""
    red, nir = [], []
    for row in range(HEIGHT):
        pairs = [pixel(row, col) for col in range(WIDTH)]
        red.append([p[0] for p in pairs])
        nir.append([p[1] for p in pairs])
    return red, nir
NDVI cell by cell, with the hole kept out Python · algebra/ndvi_grid.py
"""NDVI cell by cell: a 3 x 3 corner of the lesson raster, then every pixel, with nodata kept out."""
from scene import HEIGHT, NODATA, WIDTH, cover, pixel


def ndvi(red, nir):
    """(NIR - red) / (NIR + red) in floating point, or None where either band has no data."""
    if red == NODATA or nir == NODATA:
        return None
    return (nir - red) / (nir + red)


def show(value):
    return "nodata" if value is None else f"{value:.3f}"


rows, cols = range(418, 421), range(98, 101)
print("row  band" + "".join(f"  col {c:>3}" for c in cols))
for r in rows:
    print(f"{r}  red " + "".join(f"{pixel(r, c)[0]:>9}" for c in cols))
    print(f"{r}  nir " + "".join(f"{pixel(r, c)[1]:>9}" for c in cols))
    print(f"{r}  ndvi" + "".join(f"{show(ndvi(*pixel(r, c))):>9}" for c in cols))

totals, counts, missing = {}, {}, 0
for r in range(HEIGHT):
    for c in range(WIDTH):
        value = ndvi(*pixel(r, c))
        if value is None:
            missing += 1
            continue
        kind = cover(r, c)
        totals[kind] = totals.get(kind, 0.0) + value
        counts[kind] = counts.get(kind, 0) + 1

valid = sum(counts.values())
print(f"pixels with data: {valid:,}; nodata: {missing:,}")
print(f"mean NDVI of the pixels with data: {sum(totals.values()) / valid:.4f}")
for kind in ("water", "town", "soil", "crop"):
    print(f"  {kind:>5}: {counts[kind]:>7,} pixels, mean NDVI {totals[kind] / counts[kind]:.3f}")

Output

row  band  col  98  col  99  col 100
418  red      2217     2215      494
418  nir      2817     2815     4214
418  ndvi    0.119    0.119    0.790
419  red      2210     2209      496
419  nir      2810     2809     4216
419  ndvi    0.120    0.120    0.789
420  red      2209     2210        0
420  nir      2809     2810        0
420  ndvi    0.120    0.120   nodata
pixels with data: 477,600; nodata: 2,400
mean NDVI of the pixels with data: 0.5046
  water:  28,000 pixels, mean NDVI -0.273
   town:  25,200 pixels, mean NDVI 0.128
   soil:  94,900 pixels, mean NDVI 0.120
   crop: 329,500 pixels, mean NDVI 0.710

Recorded with Python 3.14.8 on macOS 26 arm64. To run it yourself: mise exec python@3.14.8 -- python3 ndvi_grid.py

477,600 pixels have data, and their mean NDVI is 0.5046: water −0.273, town 0.128, soil 0.120 and crop 0.710. On whole arrays, NumPy’s masked arrays do the same bookkeeping: a True in the mask marks a value as invalid, and computations such as a mean leave it out (NumPy, numpy.ma). rasterio returns such an array from read(masked=True).

Checkpoint

Check: Map algebra, cell by cell, with masks

  1. Question 1 of 2 What does a cell-by-cell map algebra operation such as NDVI use to compute one output cell?

    Choose one answer.

    Show the answer: Question 1 of 2

    Answer: The same cell of each input raster, and nothing else

    Map algebra of this kind applies one formula to each cell by itself, which is why the inputs must be aligned: the same row and column has to be the same patch of ground in every one of them.

  2. Question 2 of 2 In row 420, column 100 of the lesson raster, red is the nodata value, 0, and so is near-infrared. What should the NDVI output hold there?

    Choose one answer.

    Show the answer: Question 2 of 2

    Answer: Nodata

    The mask is checked first: either band at its nodata value makes the output cell nodata, and the formula is never evaluated. That is how the lesson's 2,400 empty pixels stay out of the mean of 0.5046.

NDVI and NDWI measure the contrast between two bands

Each index here is a normalised difference of two bands, (a − b) ÷ (a + b), which lies between −1 and 1 whenever neither band is negative. NDVI compares near-infrared with red: the chlorophyll of green leaves takes in most of the visible light for photosynthesis, while the cells of the leaf send much of the near-infrared back (NASA Earth Observatory). It was described for monitoring vegetation on the Great Plains with ERTS images (Rouse and others). NASA reads 0.1 and below as rock, sand or snow, 0.2 to 0.3 as shrub and grassland, and 0.6 to 0.8 as temperate and tropical rainforest.

NDWI names two indices. McFeeters defined one from green and near-infrared to outline open water (McFeeters); Gao defined another from near-infrared and shortwave infrared to sense the liquid water in leaves (Gao). On Sentinel-2, green is B3, red B4, near-infrared B8 and shortwave infrared B11, at about 1,610 nm (SentiWiki). The program computes all three for four surfaces, with illustrative reflectances:

NDVI and the two NDWIs on four surfaces Python · algebra/indices.py
"""Three normalised differences for four surfaces: NDVI and the two indices called NDWI."""

# Reflectance, 0 to 1, in four bands: illustrative values for this lesson, shaped like real surfaces
# (green 560 nm, red 665 nm, near-infrared 833 nm, shortwave infrared 1610 nm, about Sentinel-2's B3, B4, B8, B11).
SURFACES = {
    "water": {"green": 0.060, "red": 0.035, "nir": 0.020, "swir": 0.010},
    "crop": {"green": 0.080, "red": 0.050, "nir": 0.400, "swir": 0.200},
    "soil": {"green": 0.150, "red": 0.220, "nir": 0.280, "swir": 0.350},
    "town": {"green": 0.140, "red": 0.170, "nir": 0.220, "swir": 0.250},
}


def normalised_difference(a, b):
    """(a - b) / (a + b): from -1 to 1, the contrast between two bands."""
    return (a - b) / (a + b)


print(f"{'surface':>8} {'NDVI':>7} {'NDWI (green, NIR)':>18} {'NDWI (NIR, SWIR)':>17}")
for name, s in SURFACES.items():
    ndvi = normalised_difference(s["nir"], s["red"])
    ndwi_water = normalised_difference(s["green"], s["nir"])  # McFeeters (1996): open water
    ndwi_leaves = normalised_difference(s["nir"], s["swir"])  # Gao (1996): water in leaves
    print(f"{name:>8} {ndvi:>7.3f} {ndwi_water:>18.3f} {ndwi_leaves:>17.3f}")

Output

 surface    NDVI  NDWI (green, NIR)  NDWI (NIR, SWIR)
   water  -0.273              0.500             0.333
    crop   0.778             -0.667             0.333
    soil   0.120             -0.302            -0.111
    town   0.128             -0.222            -0.064

Recorded with Python 3.14.8 on macOS 26 arm64. To run it yourself: mise exec python@3.14.8 -- python3 indices.py

Only water has a positive green and near-infrared NDWI, 0.500, and only water a negative NDVI. The near-infrared and shortwave index gives water and crop the same 0.333: it was made for water in leaves, not for finding ponds. Name the two bands of every NDWI you publish.

reclassification: Turning a raster of continuous values into classes with a table of thresholds, such as NDVI below 0 as water and 0.3 or more as vegetation. The table and the image's date belong with the result. turns such an index into classes with a table of thresholds, such as NDVI below 0 as water and 0.3 or more as vegetation. Its thresholds are decisions about one place and one date, so a reclassification is only as good as the table kept with it.

Key idea

An index is a contrast between two named bands: NDVI is near-infrared against red, and an NDWI means nothing until you say which two bands it compares.

Checkpoint

Check: NDVI and the two NDWIs

  1. Question 1 of 2 A pixel reflects 0.05 of red light and 0.40 of near-infrared. What is its NDVI, to three decimals?

    Type a number.

    A hint

    NDVI = (NIR - red) ÷ (NIR + red).

    Show the answer: Question 1 of 2

    Answer: 0.778 (anything from 0.777 to 0.779 counts)

    (0.40 − 0.05) ÷ (0.40 + 0.05) = 0.35 ÷ 0.45 = 0.778, the crop of the lesson's four surfaces, in NASA's range for dense vegetation.

  2. Question 2 of 2 A map labelled only "NDWI" shows the same value, 0.333, over a reservoir and over a field of crops. Which NDWI was computed?

    Choose one answer.

    Show the answer: Question 2 of 2

    Answer: Gao's, from near-infrared and shortwave infrared, which senses water in leaves

    Green against near-infrared outlines open water; near-infrared against shortwave infrared measures water in vegetation. A label without its two bands leaves the reader to guess which one they are looking at.

Band maths that fails without an error, reproduced and fixed Pro: opens with a Pro, Premium or Ultimate pass

Three mistakes give wrong NDVI with no error message: integers that wrap round, cells that divide 0 by 0, and digital numbers used without their scale and offset. Each is reproduced here on the lesson raster, with its fix.

In this part:

  • Integer sums that wrap round in 8 and 16 bits
  • Zero denominators, and a hole that leaks into the mean
  • Digital numbers need their scale and offset
  • Three checks that catch all three failures

1 diagram · 2 runnable examples (Python) · about 8 minutes

Opening this part with your pass…

This part opens with any MySmartCoPilot pass.

  • Pro pass · 1 week₹79$2.99
  • 30 days₹179$5.99
  • 1 year₹1,699$45

One payment; a pass never renews. The price shown is the total you pay: no fees or charges are added at checkout.

It also opens every other in-depth part in Learn and every Pro tool. Sales are final, except where the law gives you a right to withdraw, for example in the EU and the UK (refund policy).

Reclassification with thresholds you can defend and record Pro: opens with a Pro, Premium or Ultimate pass

A reclassification is a table of decisions written as numbers. Here you write one for the lesson raster, measure how far a single threshold moves an area, and run the same table on a second date.

In this part:

  • A class table with half-open classes and its own nodata
  • One threshold moves an area by a fifth, measured
  • Choosing the threshold from field plots, with numbers
  • The same table on a second date
  • Reclassify NDVI with a table and measure the classes
    • Results of the sample tests

3 runnable examples (Python) · 1 exercise with sample tests · about 6 minutes

Opening this part with your pass…

This part opens with any MySmartCoPilot pass.

  • Pro pass · 1 week₹79$2.99
  • 30 days₹179$5.99
  • 1 year₹1,699$45

One payment; a pass never renews. The price shown is the total you pay: no fees or charges are added at checkout.

It also opens every other in-depth part in Learn and every Pro tool. Sales are final, except where the law gives you a right to withdraw, for example in the EU and the UK (refund policy).

Practise: NDVI with a mask

The exercise computes NDVI with a mask on the lesson’s corner and averages it, and the self-check covers the ideas of the first two sections, from cell-by-cell algebra to the two NDWIs:

Exercise · Easy · Python

Compute NDVI with a mask, and its mean

The red and near-infrared bands of a small raster are given as lists of rows of whole numbers, and nodata is the value that marks a pixel without data in either band.

  • ndvi_grid(red, nir, nodata) returns the NDVI of every pixel, (nir - red) / (nir + red), as a list of rows of the same shape, with None wherever either band holds nodata or where nir + red is 0.
  • mean_ndvi(grid) returns (mean, count): the mean of the values that are not None, rounded to 4 decimals, and how many there were. A grid with no values returns (None, 0).

The sample tests use the 3 by 3 corner of the lesson raster, rows 418 to 420 and columns 98 to 100, and a tiny grid with a pixel whose bands are both 0.

Starter code · masked.py

def ndvi_grid(red, nir, nodata):
    """NDVI of every pixel, a list of rows, with None where either band has no data or the sum is 0."""
    # Replace this line: go through the rows and columns of both bands together.
    return []


def mean_ndvi(grid):
    """(mean rounded to 4 decimals, count) of the values that are not None; (None, 0) if there are none."""
    # Replace this line: leave out every None before you sum.
    return None, 0
The sample tests · test_masked.py
from masked import mean_ndvi, ndvi_grid

RED = [[2217, 2215, 494], [2210, 2209, 496], [2209, 2210, 0]]
NIR = [[2817, 2815, 4214], [2810, 2809, 4216], [2809, 2810, 0]]


def test_lesson_corner():
    """computes NDVI cell by cell and keeps the nodata cell as None"""
    grid = ndvi_grid(RED, NIR, 0)
    assert round(grid[0][2], 3) == 0.790
    assert round(grid[1][0], 3) == 0.120
    assert grid[2][2] is None


def test_shape_is_kept():
    """returns a grid of the same shape as the bands"""
    grid = ndvi_grid(RED, NIR, 0)
    assert len(grid) == 3 and all(len(row) == 3 for row in grid)


def test_mean_leaves_nodata_out():
    """averages the eight cells with data, not nine"""
    assert mean_ndvi(ndvi_grid(RED, NIR, 0)) == (0.287, 8)


def test_zero_sum_and_other_nodata_value():
    """masks a pixel whose bands are both 0, and honours another nodata value"""
    grid = ndvi_grid([[100, 0], [-9999, 300]], [[300, 0], [500, -9999]], -9999)
    assert grid[0][0] == 0.5
    assert grid[0][1] is None and grid[1][0] is None and grid[1][1] is None
    assert mean_ndvi(grid) == (0.5, 1)


def test_empty():
    """returns (None, 0) when no cell has data"""
    assert mean_ndvi([[None, None]]) == (None, 0)


def test_equal_bands():
    """gives 0, not nodata, to a pixel whose two bands are equal"""
    assert ndvi_grid([[200, 0]], [[200, 0]], 0) == [[0.0, None]]
A hint

Check the mask before you divide: if r == nodata or n == nodata or r + n == 0, put None in the output cell and go on to the next one. For the mean, collect the values that are not None first, then divide their sum by how many there are.

The sample tests run on this device, in your browser (Pyodide): nothing is sent to mysmartcopilot.com. The first run downloads Python (about 13.5 MB), which is kept for the next runs. A check in your browser is feedback for you, not proof that the code is right for every input.

Practice that adapts to you

Practise this lesson

6 questions about 7 ideas of this lesson. Each answer is explained at once, and what you get right is kept in this browser.

  1. Question 1 of 6 Which of these is a cell-by-cell map algebra operation?

    Choose one answer.

    Show the answer: Question 1 of 6

    Answer: NDVI from a red and a near-infrared band

    A cell-by-cell operation reads one cell of each input and writes one cell: band ratios, sums, comparisons with a threshold. Operations that read neighbours or whole zones are other kinds of map algebra.

  2. Question 2 of 6 Two bands have the same CRS, pixel size and shape, but one grid starts 5 m east of the other. What does cell-by-cell NDVI then compute?

    Choose one answer.

    Show the answer: Question 2 of 6

    Answer: Values that mix two neighbouring patches of ground in every cell, so the grids must be aligned first

    Map algebra needs aligned grids: the same CRS, pixel size, origin and shape. The next lesson shows how to put rasters on one grid before combining them.

  3. Question 3 of 6 Band A has 1,200 nodata cells and band B has 800, and 300 cells are nodata in both. How many cells of an index computed from A and B are nodata?

    Type a number.

    A hint

    A cell is missing in the output when it is missing in either input; do not count the shared ones twice.

    Show the answer: Question 3 of 6

    Answer: 1700 cells

    1,200 + 800 − 300 = 1,700. The output's mask is the union of the inputs' masks, which is why the output can have more missing cells than either band.

  4. Question 4 of 6 What range of values can NDVI take?

    Choose one answer.

    Show the answer: Question 4 of 6

    Answer: From −1 to 1

    With reflectances that are never negative, (NIR − red) ÷ (NIR + red) lies between −1 and 1, so a value outside that range means the computation went wrong, not the ground.

  5. Question 5 of 6 Of the lesson's four surfaces, which has a negative NDVI?

    Choose one answer.

    Show the answer: Question 5 of 6

    Answer: Water

    NDVI is negative where red exceeds near-infrared, as over water, and rises with green leaves: about 0.12 for soil and towns, 0.71 on average for the lesson's crops.

  6. Question 6 of 6 You must map open water from Sentinel-2. Which bands go into the index?

    Choose one answer.

    Show the answer: Question 6 of 6

    Answer: B3 and B8, green and near-infrared

    Choose the index by what it measures, then name its bands: green and near-infrared for open water, written as (B3 − B8) ÷ (B3 + B8) on Sentinel-2.

Interview questions

Three longer questions start from this lesson, from an index above 1 to a threshold that moves an answer; the bank gives what each tests and a first step:

  1. Fresher to mid

    A colleague's NDVI raster has values above 100 over every reservoir and river, while fields and towns look normal. What happened, how do you prove it, and how do you change the pipeline so that it cannot happen again?

    Model answer, Pro. Model answers open with any pass; prices are in the notice on this page. First step and follow-ups

  2. Mid to senior

    You are asked for the area of healthy crop in a district from one Sentinel-2 image, using NDVI. How do you choose the threshold, and what do you report with the area?

    Model answer, Pro. First step and follow-ups

  3. Mid to senior

    The mean NDVI of a district fell from 0.75 to 0.52 between two Sentinel-2 images taken a year apart, in the same month, yet the fields look the same on both. How do you investigate before anyone reports a drought?

    Model answer, Pro. First step and follow-ups

Flashcards · 7 cards

Recall it, then check

Say the answer to yourself before you look: recalling it is what makes it stick.

  1. What is map algebra, and what must its input rasters share?

    A formula applied to each cell on its own, such as adding, dividing or comparing bands. The inputs must be aligned (the same CRS, pixel size, origin, rows and columns), so that a cell is the same patch of ground in every input.

  2. What should happen to a cell that is missing in one input of a map algebra formula?

    It stays missing in the output, whatever the nodata value. NumPy's masked arrays keep that bookkeeping, a True in the mask marking an invalid value that a mean leaves out, and rasterio returns one from read(masked=True).

  3. What is NDVI, and why does it pick out green vegetation?

    (NIR − red) ÷ (NIR + red), between −1 and 1. Chlorophyll absorbs most visible light while leaf cells send much near-infrared back: a field reflecting 0.4214 near-infrared and 0.0494 red gives 0.790, dense healthy crop.

  4. What do NDVI values say about the ground?

    Below 0 is typically water; 0.1 and below rock, sand or snow; 0.2 to 0.3 shrub and grassland; 0.6 to 0.8 temperate and tropical rainforest, by NASA's reading. The lesson's town averaged 0.128 and its crop 0.710.

  5. Which two indices share the name NDWI, and what does each measure?

    McFeeters' NDWI, from green and near-infrared, outlines open water; Gao's, from near-infrared and shortwave infrared, senses the water in leaves and gave water and crop the same 0.333. Name the two bands of every NDWI you publish.

  6. Which Sentinel-2 bands are green, red, near-infrared and shortwave infrared?

    B3 is green, B4 red, B8 near-infrared and B11 shortwave infrared, at about 1,610 nm.

  7. What is reclassification, and what must be kept with its result?

    Turning a continuous raster into classes with a table of thresholds, such as NDVI below 0 as water and 0.3 or more as vegetation. The thresholds are decisions about one place and one date, so the table travels with the result.

Key takeaways

  • Map algebra applies one formula to the same cell of aligned rasters, and a cell missing in any input stays missing in the output.
  • NDVI, (NIR − red) ÷ (NIR + red), runs from −1 to 1: negative for water, about 0.1 for bare ground and 0.6 to 0.8 for rainforest.
  • Two indices are called NDWI: green with near-infrared outlines open water, near-infrared with shortwave infrared senses water in leaves.
  • Reclassification turns an index into classes through a table of thresholds, which must be kept with the result.

Terms in this lesson

map algebra
Computing a new raster from one or more aligned rasters with a formula applied cell by cell, such as a band ratio, a sum or a comparison with a threshold. Kinds that also read a cell's neighbours or a whole zone are moving-window and zonal operations.
NDVI (normalised difference vegetation index)
(NIR − red) ÷ (NIR + red), from −1 to 1: negative over water and rising with green leaves, which absorb red light and reflect near-infrared strongly.
NDWI (normalised difference water index)
A name shared by two indices: McFeeters' (green − NIR) ÷ (green + NIR), which outlines open water, and Gao's (NIR − SWIR) ÷ (NIR + SWIR), which senses water in leaves. A map should say which bands it used.
reclassification
Turning a raster of continuous values into classes with a table of thresholds, such as NDVI below 0 as water and 0.3 or more as vegetation. The table and the image's date belong with the result.

References

Related tools

Report a problem with this lesson

Quick answers and tool search

Type to search tools or to get a quick answer, for example 18% of 2500. Use the up and down arrow keys to move through the results, Enter to choose, and Escape to close.