Rasterio: access to geospatial raster data
Geographic information systems use GeoTIFF and other formats to organize and store gridded raster datasets such as satellite imagery and terrain models. Rasterio reads and writes these formats and provides a Python API based on Numpy N-dimensional arrays and GeoJSON.
Here’s an example program that extracts the GeoJSON shapes of a raster’s valid data footprint.
import rasterio
import rasterio.features
import rasterio.warp
with rasterio.open('example.tif') as dataset:
# Read the dataset's valid data mask as a ndarray.
mask = dataset.dataset_mask()
# Extract feature shapes and values from the array.
for geom, val in rasterio.features.shapes(
mask, transform=dataset.transform):
# Transform shapes from the dataset's own coordinate
# reference system to CRS84 (EPSG:4326).
geom = rasterio.warp.transform_geom(
dataset.crs, 'EPSG:4326', geom, precision=6)
# Print GeoJSON shapes to stdout.
print(geom)
The output of the program:
{'type': 'Polygon', 'coordinates': [[(-77.730817, 25.282335), ...]]}
Rasterio supports Python versions 3.6 or higher.
- Introduction
- Installation
- Python Quickstart
- Command Line User Guide
- Advanced Topics
- Using rio-calc
- Color
- Concurrent processing
- GDAL Option Configuration
- Advanced Datasets
- Error Handling
- Vector Features
- Filling nodata areas
- Georeferencing
- Options
- Interoperability
- Masking a raster using a shapefile
- Nodata Masks
- In-Memory Files
- Migrating to Rasterio 1.0
- Overviews
- Plotting
- Profiles and Writing Files
- Reading Datasets
- Reprojection
- Resampling
- Switching from GDAL’s Python bindings
- Tagging datasets and bands
- Transforms
- Virtual Warping
- Virtual Filesystems
- Windowed reading and writing
- Writing Datasets
- Rasterio API Reference
- Contributing
- Frequently Asked Questions
- What does “RasterioIOError: file.ecw not recognized as a supported file format.” mean?
- Where is “ERROR 4: Unable to open EPSG support file gcs.csv” coming from and what does it mean?
- Why can’t rasterio find proj.db (rasterio versions < 1.2.0)?
- Why can’t rasterio find proj.db (rasterio from PyPI versions >= 1.2.0)?