Skip to main content

Vector and Raster Data

Vector data stores discrete features as point, line, and polygon geometries with attributes. Raster data stores one or more bands on a grid. Neither is inherently more precise. Their meaning depends on how the phenomenon was measured, generalized, sampled, and aligned.

Prerequisites​

Complete coordinate reference systems and projections. You should be able to name the CRS and units of each layer before comparing it with another.

Learning goals​

  • Match vector and raster representations to discrete objects and continuous or gridded measurements.
  • Read raster dimensions, cell size, extent, CRS, bands, and NoData as one contract.
  • Distinguish pixel indices from spatial coordinates and pixel values from areas.
  • Explain resolution, alignment, resampling, and edge limitations.

Two data models, several kinds of support​

The point fixtures represent selected places; the route fixture represents ordered linework; the district fixture represents surfaces. Their coordinates can be irregular and their attributes belong to identifiable features.

The tiny ASCII raster is a 2 × 3 grid in EPSG:32633. Every cell covers 1,000 × 1,000 square metres. A value belongs to that cell's support area under the declared convention; it is not automatically a measurement at the centre. The upper-right cell is NoData, meaning unavailable or outside support—not zero.

Raster metadata is inseparable from the values:

  • ncols, nrows, cell size, and origin determine the grid geometry;
  • the affine transform maps column/row indices to coordinates;
  • the CRS gives those coordinates meaning and units;
  • band definitions state what each value measures;
  • data type, scale, offset, and NoData affect interpretation;
  • pixel-is-area versus pixel-is-point conventions affect edges.

Resolution is cell spacing, not guaranteed real-world detail or accuracy. Resampling to smaller cells creates more pixels, not new observations. Combining rasters requires deliberate alignment, extent, resolution, resampling, and NoData rules.

Worked example​

import json
from pathlib import Path

from pyproj import CRS

fixture = Path("tests/fixtures/geospatial-data-science")
geometry_types = set()
for name in ("places.geojson", "routes.geojson", "districts.geojson"):
document = json.loads((fixture / name).read_text(encoding="utf-8"))
geometry_types.update(feature["geometry"]["type"] for feature in document["features"])

lines = (fixture / "tiny-grid.asc").read_text(encoding="utf-8").splitlines()
header = {key.lower(): float(value) for key, value in (line.split() for line in lines[:6])}
cells = [float(value) for line in lines[6:] for value in line.split()]
nodata = header["nodata_value"]
valid = [value for value in cells if value != nodata]
left, bottom = header["xllcorner"], header["yllcorner"]
right = left + header["ncols"] * header["cellsize"]
top = bottom + header["nrows"] * header["cellsize"]
crs = CRS.from_wkt((fixture / "tiny-grid.prj").read_text(encoding="utf-8"))
print(f"vector_types={sorted(geometry_types)}")
print(f"raster_shape={int(header['nrows'])}x{int(header['ncols'])} valid_cells={len(valid)} nodata_cells={len(cells) - len(valid)}")
print(f"raster_bounds=({int(left)},{int(bottom)},{int(right)},{int(top)}) crs={crs.to_string()}")

Expected output:

vector_types=['LineString', 'Point', 'Polygon']
raster_shape=2x3 valid_cells=5 nodata_cells=1
raster_bounds=(391000,5818000,394000,5820000) crs=EPSG:32633

The raster rows are written top to bottom even though yllcorner describes the lower edge. A real reader exposes a transform so code need not reconstruct row orientation ad hoc; this explicit parser exists only to make the tiny fixture hand-checkable.

Choosing and converting​

Use vectors when identity, boundaries, networks, or feature-specific attributes are primary. Use rasters when the source is inherently gridded, when cellwise map algebra is useful, or when regular tiling enables efficient processing. Conversion changes support: rasterizing a polygon requires cell-inclusion and resolution rules; vectorizing a classified raster can produce staircase boundaries and many small polygons.

Always retain provenance and the original observation scale. A point sample interpolated to a raster is modeled coverage, not direct observation everywhere. A district mean attached to a polygon is an aggregate, not a continuous surface inside it.

Limitations and common mistakes​

  • Comparing layers in different CRSs or cell alignments can shift apparent overlap.
  • NoData, zero, and below-detection values are different states.
  • A nominal 10 m raster may have larger positional or measurement error.
  • Raster dimensions alone do not reveal band semantics, acquisition time, or masks.
  • Converting formats or representations can change precision, geometry type, and missing values.

Practice​

Choose a representation for parcel ownership, daily temperature, bus routes, and satellite reflectance. For each, name its spatial support and one way conversion to the other model could mislead.

Next steps​

Next, select geospatial file formats based on interoperability, CRS metadata, schema, scale, and update needs.

Primary sources​

Checked 2026-10-18: GDAL, vector data model; Rasterio, dataset georeferencing and transform; Rasterio, NoData masks; OGC, Simple Feature Access.