docs.rs failed to build rstiff-0.2.0
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Visit the last successful build:
rstiff-0.1.0
rstiff
A high-precision, type-preserving Rust library for GeoTiff I/O and processing, powered by GDAL.
Features
- High Precision: Loads data into
ndarray::Array3<f64>for accurate scientific computing. - Type-Preserving I/O: Automatically restores the original data type (e.g.,
Byte,UInt16,Float32) when writing. - Smart NoData Handling: Correctly handles
NoDatavalues and preserves transparency in output files. - Window Reading: Read only the data you need - by pixel coordinates, geographic bounds, or vector extent.
- Reprojection: Robust coordinate transformation with automatic calculation of new bounds and pixel resolution.
- Vector Cropping: Crop rasters using vector files (Shapefile, KML, GeoJSON) with optional masking.
- Efficient: Uses optimized GDAL drivers with LZW compression.
Prerequisites
rstiff relies on GDAL bindings. You must have GDAL installed on your system.
macOS (Homebrew)
Ubuntu/Debian
Windows
Download and install GDAL from GISInternals or use conda:
Installation
Add this to your Cargo.toml:
[]
= "0.1"
Or install via cargo:
Quick Start
Basic Read and Write
use GeoTiff;
API Reference
Core Types
| Type | Description |
|---|---|
GeoTiff |
Main struct containing raster data, geotransform, projection, and metadata |
RasterInfo |
Lightweight metadata struct (no pixel data loaded) |
TiffError |
Error type for all operations |
Reading Data
GeoTiff::read() - Read entire file
let tif = read?;
GeoTiff::info() - Get metadata without loading pixels
let info = info?;
println!;
println!;
println!; // (min_x, min_y, max_x, max_y)
println!; // (pixel_width, pixel_height)
GeoTiff::read_window() - Read by pixel coordinates
Only load the pixels you need - perfect for large files:
// Read a 256x256 tile starting at pixel (1000, 2000)
let tile = read_window?;
GeoTiff::read_bounds() - Read by geographic coordinates
// Read data within a geographic bounding box
let roi = read_bounds?;
// path min_x min_y max_x max_y
GeoTiff::read_by_vector() - Read by vector file extent
// Read only the area covered by a KML/Shapefile/GeoJSON
let roi = read_by_vector?;
// raster vector apply_mask
// apply_mask = true -> pixels outside polygon set to NoData
// apply_mask = false -> just clip to bounding box
Coordinate Conversion
Use RasterInfo for coordinate transformations:
let info = info?;
// Pixel to geographic coordinates
let = info.pixel_to_geo; // col, row -> x, y
// Geographic to pixel coordinates
let = info.geo_to_pixel; // x, y -> col, row
// Convert geographic bounds to pixel window
let = info.bounds_to_window?;
Processing
crop() - Crop by pixel coordinates
let cropped = tif.crop?; // x_off, y_off, width, height
crop_by_vector() - Crop by vector file (loads full raster first)
let cropped = tif.crop_by_vector?;
// Use read_by_vector() instead for large files!
reproject() - Reproject to different CRS
// Reproject from WGS84 to UTM Zone 50N
let utm = tif.reproject?; // EPSG code
Writing
tif.write?;
// - Original data type is preserved (Byte, UInt16, Float32, etc.)
// - LZW compression is applied automatically
// - NoData values are handled correctly
Memory Comparison
For a 10GB raster file, window reading dramatically reduces memory usage:
| Method | Memory Usage |
|---|---|
GeoTiff::read() |
~10 GB (loads everything) |
GeoTiff::read_window(..., 256, 256) |
~0.5 MB (loads only needed area) |
GeoTiff::read_by_vector() |
Variable (loads only ROI) |
Examples
Run the included examples:
# Basic read/write
# Reprojection
# Vector cropping (traditional)
# Window reading (memory efficient)
# Vector window reading
Comparison with Python rasterio
| rasterio | rstiff |
|---|---|
rasterio.open() |
GeoTiff::read() |
dataset.read(window=Window(...)) |
GeoTiff::read_window() |
dataset.read() with bounds |
GeoTiff::read_bounds() |
rasterio.mask.mask() |
crop_by_vector() / read_by_vector() |
rasterio.warp.reproject() |
reproject() |
dataset.xy() |
RasterInfo::pixel_to_geo() |
dataset.index() |
RasterInfo::geo_to_pixel() |
dataset.bounds |
RasterInfo::bounds() |
dataset.res |
RasterInfo::res() |
Roadmap
See ROADMAP.md for planned features:
- Resampling (Nearest, Bilinear, Cubic, Lanczos)
- Band statistics (min, max, mean, std, histogram)
- Band math helpers (NDVI, NDWI)
- Memory file support
- Raster merge/mosaic
- Cloud storage support (S3, HTTP)
Acknowledgments
Built on these excellent projects:
License
MIT License - see LICENSE for details.