Raster & rasterio
Reading, sampling and converting raster data in Python.
A raster is an array plus an affine transform. The array has rows and columns; the transform is the only thing that makes them a place. Nearly every raster bug worth the name is those two disagreeing — a window read without its transform updated, a reprojection that changed the CRS but not the grid, a resample that moved the origin by half a cell.
The second recurring theme is dtype and NoData. An integer array silently truncates a float calculation; a NoData value that collides with real data hides it; and a viewer that stretches to the full range shows you black where the file is fine. None of these raise.
Below: the concepts cover the data model, resampling and what each operation computes; the how-to guides read, window, sample, reproject, mosaic and convert; and the fixes are the outputs that come back black, empty, shifted or the wrong size.
🧭 Start with the concepts
The ideas the how-to guides below assume you already have.
- Vector vs Raster Data in Python GIS: Key Differences
- Introduction to Rasterio: Reading Raster Data in Python
- The Raster Data Model Explained: Bands, dtype, NoData and the Transform
- Raster Resampling Explained: Nearest, Bilinear and When Each Is Wrong
- STAC Explained: How Satellite Imagery Catalogues Work
- Digital Elevation Models Explained: DEM, DSM and DTM
Show every concept in this topic
- Slope and Aspect Explained: How They Are Computed from a Grid
- Cloud-Optimised GeoTIFF Explained: Tiles, Overviews and Range Requests
- Regridding Explained: Bilinear, Conservative and Nearest for Gridded Data
- Site Suitability Explained: Constraints, Factors and Weights
- Flow Direction Explained: D8, D-Infinity and MFD Compared
- How DEM Resolution and Source Change a Drainage Network
- Bathymetry explained: depths, datums and grids
- Categorical Rasters Explained
⚙️ Then do the task
Step-by-step walkthroughs with code you can copy and adapt.
- How to Extract Raster Values at Point Locations with Rasterio
- How to Convert a Raster to a Vector in Python
- How to Batch Process Rasters with Rasterio in Python
- How to Reproject a Raster in Python with Rasterio
- How to Clip a Raster to a Polygon in Python
- How to Calculate Zonal Statistics in Python
Show every how-to guide in this topic
- How to Rasterize a Vector Layer in Python
- How to Merge and Mosaic Rasters in Python with Rasterio
- How to Search and Download Satellite Imagery with STAC in Python
- How to Calculate Slope and Aspect from a DEM in Python
- How to Generate Contour Lines from a DEM in Python
- How to Extract an Elevation Profile Along a Line in Python
- How to Fill Sinks and Derive Flow Direction from a DEM
- How to Calculate a Viewshed in Python
- How to Load Sentinel-2 Bands into Python as an Analysis-Ready Array
- How to Resample Satellite Bands to a Common Grid
- How to Calculate NDVI from Sentinel-2 in Python
- How to Mask Clouds in Sentinel-2 Imagery with Python
- How to Build a Cloud-Free Composite from Many Satellite Scenes
- How to Extract a Vegetation Index Time Series for a Polygon
- How to Detect Change Between Two Satellite Images in Python
- How to Rasterise a Point Cloud to a Grid in Python
- How to Read a COG from a URL Without Downloading the Whole File
- How to Write a Cloud-Optimised GeoTIFF in Python
- How to Sample Training Points from Rasters and Polygons
- How to Predict a Continuous Surface with Random Forest
- How to Turn Model Predictions Back into a Raster
- How to Interpolate Points to a Grid with IDW in Python
- How to Choose a Cell Size for an Interpolated Surface
- How to Select a Time Range and Location from an xarray Dataset
- How to Clip a NetCDF Grid to a Polygon in Python
- How to Convert NetCDF to GeoTIFF in Python
- How to Extract a Time Series per Polygon from a NetCDF Grid
- How to Redistribute Population with Dasymetric Mapping
- How to Run a Weighted Site Suitability Analysis in Python
- How to Condition a DEM for Hydrology: Breaching or Filling
- How to Calculate Flow Accumulation from a DEM in Python
- How to Delineate a Watershed from a Pour Point in Python
- How to Calculate Height Above Nearest Drainage (HAND) in Python
- How to Burn a Known River Network into a DEM
- How to embed provenance tags in a GeoTIFF
- How to estimate rooftop solar potential in Python
- How to compute sky view factor from a surface model
- How to load and plot a bathymetry grid in Python
- How to extract a coastline from a raster in Python
- How to read Sentinel-1 RTC data in Python
- How to convert SAR backscatter to decibels, and average it correctly
- How to filter speckle in Sentinel-1 images
- How to combine hazard, exposure and vulnerability into a risk score
- How to Build a Siting Exclusion Mask in Python
- How to Measure Distance to the Grid for Renewable Siting
- How to Delineate an Urban Extent from GHSL in Python
- How to Read Hansen Global Forest Change Data in Python
- How to Calculate Forest Loss by Year for a Region in Python
- How to Summarise Land Surface Temperature by Neighbourhood in Python
- How to Georeference a Scanned Map with GDAL in Python
- How to Compare Georeferencing Transformations in Python
- How to Georeference an Early County Map in Python
- How to Mosaic Historical Map Sheets in Python
- How to Digitise Features from an Old Map in Python
- How to Grid Radar Data from Polar Sweeps to a Raster in Python
- How to Map Storm-Total Rainfall in Python
- How to Build a Land Cover Change Matrix in Python
- How to Summarise Land Cover by Polygon in Python
- How to Reclassify a Land Cover Raster in Python
- How to Measure Land Cover Around Points in Python
- How to Analyse a Land Cover Time Series in Python
- How to Convert a Land Cover Raster to Polygons in Python
- How to Map Population Change Since 1975 with GHSL in Python
- How to Sum a Population Grid by Municipality in Python
- How to Resample a Population Grid to Another Resolution in Python
- How to Compare Population Grids Cell by Cell in Python
- How to Detect Ocean Temperature Fronts in Python
🔧 When it breaks
The errors this topic produces, with the cause explained rather than just the command.
- RasterioIOError: Not Recognized as a Supported File Format (How to Fix)
- Rasterio Returns the Wrong Values: NoData, Scaling and dtype Fixes
- Raster and Vector Do Not Line Up in Python: How to Fix It
- Rasterio Output GeoTIFF Is Black or Empty: How to Fix It
- Satellite Bands Have Different Shapes or Do Not Align
- NDVI Values Are Above 1 or Below −1: How to Fix It
Show every fix in this topic
- My Composite Has Holes, Stripes or Grey Patches
- My Prediction Raster Is Striped, Blocky or Full of NoData
- Fixing a Suitability Map That Comes Out All One Value or All NoData
- Fixing Flow Accumulation That Is All Zeros, NoData or Stops at the Edge
- Bathymetry depths are positive in one file and negative in another
- A SAR image looks noisy after processing
- SAR values come out negative, huge or averaged wrongly
- SAR scenes from different dates do not line up
- A hazard raster's nodata is read as zero
- LST Values on the Wrong Scale
- Warped Map Is Folded or Stretched
- Georeferenced Map Has a Black Border or Hides Other Layers
- Why Does My Resampled Land Cover Have Classes That Should Not Be There?
- Why Are My Land Cover Percentages Wrong?
- Why Is My Land Cover Change Map Full of Speckle?
- Fixing Population Totals That Add Up to More Than the Whole
Learning paths through this topic
A curated route rather than a list — the guides in the order that builds on itself.
- Finding & Fetching Data
- Terrain & Elevation
- Raster Analysis
- Batch Processing
- Satellite Imagery
- LiDAR & Point Clouds
- Cloud-Native GIS
- Spatial Machine Learning
- Interpolation & Surfaces
- Gridded & Climate Data
- Census & Demographics
- Location & Accessibility
- Hydrology & Watersheds
- Metadata, Licensing & Provenance
- 3D & Buildings
- Coastal & Marine
- Radar & SAR Imagery
- Natural Hazards & Risk
- Renewable Energy Siting
- Urban Morphology
- Forest Monitoring
- Urban Heat Mapping
Related topics
Subjects that keep coming up alongside this one, most overlap first.