Foundations to Frontier
Tests
C. Programming, Tools and HPC › C7 Scientific Data Formats

Geospatial Data: GeoTIFF, Rasters and Vectors

Geospatial data come in two forms: rasters (grids of pixels such as satellite images, elevation models and land-cover maps, usually GeoTIFF or Cloud-Optimized GeoTIFF) and vectors (points, lines and polygons such as roads, field boundaries and flight paths, in GeoJSON, Shapefile or GeoPackage). Both need a coordinate reference system (CRS) and a projection that maps the curved Earth to a flat grid. This topic covers geotransforms, CRSs and EPSG codes, the main projections and their distortions, geodesic distance and area, vector operations, band arithmetic such as NDVI, resampling and the tools (GDAL, rasterio, GeoPandas, Shapely, PROJ). In the exercises you implement geotransforms, Web Mercator, haversine distance, polygon area on the plane and the sphere, point-in-polygon tests, GeoJSON parsing and NDVI; then you measure how wrong Mercator and naive degree areas are, and what three downsampling methods do to class areas and river connectivity in a land-cover map.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Flattening the Earth

You cannot peel an orange and lay the skin flat without stretching or tearing it. Every map projection makes the same compromise: it can keep shapes, or areas, or some distances correct, but never all of them. Web maps use Mercator, which keeps shapes but makes Greenland look as big as Africa, which is in fact 14 times larger. When you measure fields, forests or flood areas from data, the projection you measure in matters.

Equal circles on three map projections
projection:
-60°0°60°
at 60°: map area ×4.00 of true · height/width of the circle: 1.00 (round: conformal)
Every blue circle and the orange one has the same 800 km radius on the Earth. Mercator preserves angles and local shape, which is why navigation charts and web maps use it, but scales area by sec²φ: ×4 at 60°, ×33 at 80°. Measuring areas or distances directly in Mercator (or in raw degrees) is a common analysis bug; use an equal-area projection for areas and geodesic formulas for distances.
Why engineers care

Satellite imagery, drone surveys, ground-station coverage, launch and landing zones, autonomous-vehicle maps and flight planning are all geospatial data. Getting a coordinate system wrong can move a feature by hundreds of metres; measuring area in the wrong projection can be off by a factor of four.

📝 Quick check (Level 0)
0/3 answered
  1. 1. A raster is…
  2. 2. Mercator keeps…
  3. 3. On Mercator, a region at 60° latitude appears…

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

Rasters and vectors

Raster Vector
Represents continuous fields, imagery discrete objects
Formats GeoTIFF / COG, NetCDF, Zarr, JPEG2000 GeoJSON, Shapefile, GeoPackage, GeoParquet, FlatGeobuf
Python rasterio, rioxarray, GDAL Shapely, GeoPandas, Fiona/pyogrio

A CRS defines the datum (the Earth model, e.g. WGS 84) and the coordinates: geographic (longitude, latitude in degrees, EPSG:4326) or projected (metres: UTM zones such as EPSG:32633, Web Mercator EPSG:3857, equal-area projections). Coordinates are meaningless without their CRS.

import rasterio, geopandas as gpd
with rasterio.open("S2_B04_B08.tif") as src:         # Cloud-Optimized GeoTIFF, read by window
    red, nir = src.read([1, 2]).astype("float32")
    print(src.crs, src.transform)                      # EPSG:32633, Affine(10, 0, 500000, 0, -10, 4200000)
fields = gpd.read_file("fields.gpkg").to_crs(src.crs)   # reproject vectors to the raster CRS
fields["area_ha"] = fields.to_crs("EPSG:6933").area / 1e4   # area in an equal-area CRS
📝 Quick check (Level 1)
0/3 answered
  1. 1. EPSG:4326 is…
  2. 2. To measure area in square metres you should use…
  3. 3. A field boundary is best stored as…

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 35 minUndergraduate students and practising engineers.

Geotransforms

A north-up raster’s affine geotransform (GDAL order x₀, Δx, 0, y₀, 0, Δy with Δy < 0) maps pixel (col, row), counted from the top-left corner, to X = x₀ + col·Δx and Y = y₀ + row·Δy; pixel centres sit at col + 0.5. Rotated grids use the off-diagonal terms; inverting the 2 × 2 matrix maps coordinates back to pixels.

Distances and areas

  • Haversine: d = 2R·asin √(sin²(Δφ/2) + cos φ₁ cos φ₂ sin²(Δλ/2)), with R = 6371 km. This is exact on a sphere; on the ellipsoid it is accurate to about 0.5% (Vincenty or Karney’s algorithms are exact).
  • Planar polygon area: the shoelace formula, valid only in an equal-area projection.
  • Spherical area of a lon/lat cell: R²·Δλ·(sin φ₂ − sin φ₁).
  • Point in polygon: cast a ray and count edge crossings.

Raster operations

Band arithmetic such as NDVI = (NIR − Red)/(NIR + Red) (vegetation is about 0.3–0.9, water is below 0). Reprojection and resampling: use nearest or mode for categorical rasters, and bilinear, cubic or average for continuous ones. Zonal statistics summarise a raster inside each vector polygon.

🐍 Exercise 1: geotransforms, projections and geometry
Map pixels to coordinates and back with an affine geotransform; implement Web Mercator and its inverse; compute haversine distances; compute planar (shoelace) and spherical polygon areas; test points in polygons; parse GeoJSON polygons and multipolygons; compute NDVI with safe division.
📝 Quick check (Level 2)
0/3 answered
  1. 1. Centre of pixel (10, 20) with x₀ = 500 000, Δx = 30?
  2. 2. NDVI of NIR 0.5, Red 0.1?
  3. 3. Resampling a land-cover class map needs…

Level 3: Advanced

★★★★☆ Advanced⏱ 30 minGraduate level, with full derivations and proofs.

Practical rules

  • Store and serve rasters as Cloud-Optimized GeoTIFF (internal tiling plus overviews), so clients read only the windows and zoom levels they need over HTTP range requests. Analysis-ready data cubes use Zarr (C7.2), and catalogues of scenes are described with STAC.
  • Pick the CRS for the task: UTM or a national grid for local metric work, an equal-area projection for areas, geodesics for long distances, and Web Mercator only for display.
  • Watch axis order: EPSG:4326 is officially latitude, longitude; GeoJSON and most software use longitude, latitude.
  • Resample deliberately: downsampling class maps with mode erases small classes; keeping fraction layers preserves areas.
  • Vector at scale: GeoParquet and FlatGeobuf, with spatial indexes (R-tree, H3, S2) for joins.
📝 Quick check (Level 3)
0/3 answered
  1. 1. A COG lets a client…
  2. 2. GeoJSON coordinate order?
  3. 3. STAC describes…

Level 4: Expert

★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.

Projections and resampling, measured

Exercise 1. On a 30 m UTM-like grid, pixel (10, 20) has its centre at (500 315, 4 199 385); a rotated geotransform round-trips exactly. Web Mercator maps (180°, 85.051°) to ±20 037 508 m. London Heathrow to New York JFK is about 5 550 km by haversine. An L-shaped polygon has shoelace area 7 and correct inside and outside tests. A 1° × 1° cell covers 12 364 km² at the equator and about half that at 60°N. GeoJSON multipolygons unpack into separate rings.

Exercise 2A: area of a 1° × 1° cell, measured three ways.

Latitude True area Web Mercator / true “Degrees as flat” / true
0° 12 364 km² 1.00 1.00
30° 10 653 km² 1.35 1.16
45° 8 666 km² 2.04 1.43
60° 6 088 km² 4.13 2.04
70° 4 127 km² 9.00 3.00
80° 2 041 km² 36.8 6.07

Mercator inflates area by sec²φ (within 2% at the cell centre); treating degrees as a flat grid inflates by secφ. Both errors are already large at European latitudes.

Exercise 2B: downsampling a 1000 × 1000 land-cover map at 10 m (forest 42.6%, crop 52.1%, urban blocks 1.7%, water 3.6% in lakes and three 2-pixel-wide rivers; 30 connected water bodies). Errors are relative changes in class area.

Factor Method Urban Water Forest / crop Water pieces
5× (50 m) nearest −1.3% +0.9% ≤ 0.1% 177
mode −14.7% −15.3% +0.8 / +0.9% 32
fraction layers 0 0 0 20
10× (100 m) nearest −6.6% −2.2% ≤ 0.2% 66
mode −50.3% −19.9% +1.8 / +1.5% 21
fraction layers 0 0 0 19
25× (250 m) nearest +16% +1.9% ≤ 0.6% 26
mode −100% −29.7% +3.2 / +2.6% 15
fraction layers 0 0 0 16

Nearest-neighbour sampling is unbiased for area on average but noisy for small classes, and it shatters thin rivers into pieces (177 at 5×). Mode (majority) filtering is smooth but systematically deletes minority classes: every urban block vanishes at 250 m, and rivers disappear so only lakes remain. Storing a fraction layer per class preserves areas exactly, and its “any water” mask keeps rivers connected, at the cost of one float band per class. (Here “water pieces” counts 8-connected components; coarse cells merge nearby lakes, so it can drop below 30 without loss.)

🐍 Exercise 2 (research): projections, areas and resampling
Compare true spherical, Web Mercator and naive-degree areas of 1° cells at six latitudes; build a synthetic 10 m land-cover map with urban blocks, lakes and thin rivers; downsample it 5×, 10× and 25× with nearest neighbour, mode and per-class fraction layers; measure class-area errors and how many water bodies each result contains.

Geospatial data in AI, robotics and aerospace

  • Earth observation: Sentinel-2 and Landsat COGs indexed by STAC; geospatial foundation models (Prithvi, SatMAE) are trained on tiled imagery.
  • Autonomy: HD maps, occupancy grids and drone photogrammetry, with local metric frames anchored to a CRS.
  • Aerospace: ground tracks, sensor footprints and coverage analysis, landing-site hazard maps from DEMs, and airspace polygons.
  • Disaster response: flood and fire extents from SAR and optical rasters, intersected with vector infrastructure.

References

  1. J. P. Snyder (1987). Map Projections: A Working Manual. USGS Professional Paper 1395.
  2. C. F. F. Karney (2013). “Algorithms for geodesics.” Journal of Geodesy 87, 43–55.
  3. R. G. Chamberlain, W. H. Duquette (2007). Some Algorithms for Polygons on a Sphere. JPL Publication 07-03.
  4. H. Butler et al. (2016). The GeoJSON Format. RFC 7946.
  5. OGC (2023). Cloud Optimized GeoTIFF Standard; GDAL documentation (gdal.org); STAC specification (stacspec.org).
  6. J. W. Rouse et al. (1974). “Monitoring vegetation systems in the Great Plains with ERTS.” NASA SP-351.