Fast and direct raster I/O for use with Numpy and SciPy
—
Complete command-line interface with 23+ subcommands for raster operations including format conversion, reprojection, masking, analysis, and data exploration. The rio command provides comprehensive raster processing capabilities from the command line.
Commands for examining raster dataset properties and metadata.
# Display comprehensive dataset information
rio info [OPTIONS] INPUT
# Print geographic bounds of dataset
rio bounds [OPTIONS] INPUT
# Show dataset block structure
rio blocks [OPTIONS] INPUT
# Print ground control points
rio gcps [OPTIONS] INPUT
# Show GDAL environment information
rio env [OPTIONS]Usage examples:
# Get detailed dataset information
rio info landsat_scene.tif
rio info --indent 2 landsat_scene.tif # Pretty-printed JSON
rio info --count landsat_scene.tif # Include pixel counts
# Get geographic bounds
rio bounds landsat_scene.tif
rio bounds --dst-crs EPSG:3857 landsat_scene.tif # Transform bounds to different CRS
# Examine internal block structure
rio blocks landsat_scene.tif
rio blocks --bidx 1 landsat_scene.tif # Specific band only
# Check ground control points
rio gcps landsat_scene.tif
# Display environment information
rio env
rio env --formats # Show supported formatsCommands for coordinate and spatial transformations.
# Transform coordinates between CRS
rio transform [OPTIONS] INPUT
# Warp raster to new CRS or resolution
rio warp [OPTIONS] INPUT OUTPUT
# Reproject raster dataset
rio reproject [OPTIONS] INPUT OUTPUTUsage examples:
# Transform point coordinates
echo "-120.5 35.2" | rio transform --dst-crs EPSG:3857 input.tif
# Transform with different precision
echo "-120.5 35.2" | rio transform --precision 2 --dst-crs EPSG:3857 input.tif
# Warp to new projection
rio warp --dst-crs EPSG:3857 --resampling bilinear input.tif output_mercator.tif
# Warp with custom resolution
rio warp --dst-crs EPSG:3857 --res 30 input.tif output_30m.tif
# Warp with specific bounds
rio warp --bounds -13580000 4200000 -13570000 4210000 input.tif cropped.tif
# Reproject with compression
rio reproject --dst-crs EPSG:4326 --compress lzw input.tif output_wgs84.tifCommands for raster processing and analysis operations.
# Merge multiple rasters into mosaic
rio merge [OPTIONS] INPUT... OUTPUT
# Apply vector mask to raster
rio mask [OPTIONS] INPUT FEATURES OUTPUT
# Clip raster to geometry bounds
rio clip [OPTIONS] INPUT FEATURES OUTPUT
# Raster calculator operations
rio calc [OPTIONS] COMMAND INPUT... OUTPUT
# Sample raster values at coordinates
rio sample [OPTIONS] INPUTUsage examples:
# Merge multiple GeoTIFF files
rio merge tile1.tif tile2.tif tile3.tif mosaic.tif
rio merge --bounds -180 -90 180 90 tiles/*.tif world_mosaic.tif
# Apply shapefile mask
rio mask --crop landsat_scene.tif study_area.shp masked_scene.tif
rio mask --invert landsat_scene.tif water_bodies.shp land_only.tif
# Clip to vector bounds
rio clip landsat_scene.tif study_area.shp clipped_scene.tif
# Calculator operations
rio calc "(+ (read 1) (read 2))" band1.tif band2.tif sum.tif
rio calc "(* (read 1) 2)" input.tif doubled.tif
rio calc "(where (> (read 1) 100) 1 0)" input.tif binary.tif
# Sample values at points
echo "-120.5 35.2" | rio sample input.tif
echo "-120.5 35.2\n-119.8 35.9" | rio sample --bidx 1,2,3 rgb_image.tifCommands for format conversion and data translation.
# Convert between raster formats
rio convert [OPTIONS] INPUT OUTPUT
# Translate datasets (GDAL wrapper)
rio translate [OPTIONS] INPUT OUTPUT
# Stack bands from multiple files
rio stack [OPTIONS] INPUT... OUTPUTUsage examples:
# Convert format
rio convert input.tif output.jpg
rio convert --format PNG input.tif output.png
# Translate with options
rio translate --compress lzw --tiled input.tif output.tif
rio translate --dtype uint8 --scale-ratio 0.1 float_input.tif scaled_output.tif
# Stack bands into single file
rio stack red.tif green.tif blue.tif rgb_composite.tif
rio stack --bidx 1 *.tif stacked_band1.tifCommands for extracting and working with vector shapes from raster data.
# Extract polygon shapes from raster
rio shapes [OPTIONS] INPUT
# Rasterize vector features
rio rasterize [OPTIONS] FEATURES INPUT OUTPUTUsage examples:
# Extract shapes to GeoJSON
rio shapes landcover.tif > landcover_polygons.geojson
rio shapes --mask nodata_mask.tif --precision 6 landcover.tif > shapes.geojson
# Rasterize shapefile
rio rasterize --like template.tif polygons.shp rasterized.tif
rio rasterize --dimensions 1000 1000 --res 0.001 points.shp density.tif
rio rasterize --burn 1 --all-touched lines.shp line_raster.tifCommands for creating overviews and optimizing raster datasets.
# Build overview images
rio overview [OPTIONS] INPUT
# Edit dataset metadata
rio edit-info [OPTIONS] INPUTUsage examples:
# Build overviews with default settings
rio overview build input.tif
# Build overviews with specific resampling
rio overview build --resampling average input.tif
# Build overviews with custom factors
rio overview build --factors 2,4,8,16 input.tif
# List existing overviews
rio overview list input.tif
# Edit dataset information
rio edit-info --crs EPSG:4326 input.tif
rio edit-info --nodata -9999 input.tif
rio edit-info --tag "DESCRIPTION=Processed satellite imagery" input.tifCommands for creating new raster datasets.
# Create new raster dataset
rio create [OPTIONS] OUTPUT
# Inspect dataset interactively
rio insp [OPTIONS] INPUTUsage examples:
# Create new empty raster
rio create --driver GTiff --width 1000 --height 1000 --count 3 --dtype uint8 --crs EPSG:4326 new_raster.tif
# Inspect dataset in interactive mode
rio insp landsat_scene.tifGeneral utility commands for file management and operations.
# Remove raster files and associated files
rio rm [OPTIONS] INPUT...Usage examples:
# Remove single file and auxiliaries
rio rm dataset.tif
# Remove multiple files
rio rm tile*.tif
# Remove with confirmation
rio rm --dry-run large_dataset.tif # Show what would be deletedCommon options available across multiple commands:
# Global options (available for most commands)
--verbose, -v # Increase verbosity
--quiet, -q # Suppress output
--format DRIVER # Output format driver
--co NAME=VALUE # Creation options
--compress METHOD # Compression method
--dtype TYPE # Data type
--nodata VALUE # NoData value
--crs CRS # Coordinate reference system
--resampling METHOD # Resampling algorithm
--threads N # Number of processing threadsComplex workflows combining multiple commands:
# Processing pipeline example
# 1. Get dataset info
rio info --count input.tif
# 2. Warp to standard projection
rio warp --dst-crs EPSG:3857 --compress lzw input.tif warped.tif
# 3. Apply mask and crop
rio mask --crop warped.tif study_area.shp masked.tif
# 4. Calculate vegetation index
rio calc "(/ (- (read 4) (read 3)) (+ (read 4) (read 3)))" masked.tif ndvi.tif
# 5. Extract high NDVI areas
rio calc "(where (> (read 1) 0.5) (read 1) 0)" ndvi.tif high_ndvi.tif
# 6. Convert to shapes
rio shapes --mask high_ndvi.tif high_ndvi.tif > vegetation_polygons.geojson
# Batch processing with shell scripting
for file in *.tif; do
output="${file%.tif}_processed.tif"
rio warp --dst-crs EPSG:4326 --compress lzw "$file" "$output"
done
# Piping coordinates for sampling
cat coordinates.txt | rio sample --bidx 1,2,3 landsat.tif > sampled_values.txt
# Using with other tools
rio bounds *.tif | jq -s 'map(select(.bounds)) | .[].bounds' > all_bounds.jsonThe CLI supports numerous output formats through GDAL drivers:
# Common format examples
rio convert input.tif output.jpg # JPEG
rio convert input.tif output.png # PNG
rio convert input.tif output.nc # NetCDF
rio convert --format COG input.tif output.tif # Cloud Optimized GeoTIFF
rio convert --format GTiff --co TILED=YES input.tif tiled.tif # Tiled GeoTIFF
# List available formats
rio env --formatsThe CLI provides detailed error messages and return codes:
# Check command success
rio info nonexistent.tif
echo $? # Returns non-zero exit code on error
# Verbose error information
rio --verbose warp invalid_crs.tif output.tif
# Dry run mode (where available)
rio overview build --dry-run input.tif # Show what would be doneInstall with Tessl CLI
npx tessl i tessl/pypi-rasterio