CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-rasterio

Fast and direct raster I/O for use with Numpy and SciPy

Pending
Overview
Eval results
Files

cli.mddocs/

Command Line Interface

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.

Capabilities

Information Commands

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 formats

Transformation Commands

Commands 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 OUTPUT

Usage 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.tif

Processing Commands

Commands 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] INPUT

Usage 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.tif

Conversion Commands

Commands 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... OUTPUT

Usage 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.tif

Shape Operations

Commands 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 OUTPUT

Usage 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.tif

Overview and Optimization

Commands for creating overviews and optimizing raster datasets.

# Build overview images
rio overview [OPTIONS] INPUT

# Edit dataset metadata  
rio edit-info [OPTIONS] INPUT

Usage 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.tif

Dataset Creation

Commands for creating new raster datasets.

# Create new raster dataset  
rio create [OPTIONS] OUTPUT

# Inspect dataset interactively
rio insp [OPTIONS] INPUT

Usage 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.tif

Utility Commands

General 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 deleted

Global Options

Common 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 threads

Advanced Usage Patterns

Complex 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.json

Output Formats

The 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 --formats

Error Handling

The 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 done

Install with Tessl CLI

npx tessl i tessl/pypi-rasterio

docs

cli.md

crs.md

data-types.md

dataset-io.md

features.md

index.md

processing.md

transformations.md

windowing.md

tile.json