1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//! # 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 when writing.
//! - **Smart NoData Handling**: Correctly handles NoData values and preserves transparency.
//! - **Window Reading**: Read only the data you need - by pixel coordinates, geographic bounds, or vector extent.
//! - **Reprojection**: Robust coordinate transformation with automatic bounds calculation.
//! - **Vector Cropping**: Crop rasters using Shapefile, KML, GeoJSON with optional masking.
//!
//! ## Quick Start
//!
//! ```ignore
//! use rstiff::GeoTiff;
//!
//! // Read a GeoTiff file
//! let tif = GeoTiff::read("input.tif")?;
//! println!("Dimensions: {:?}", tif.data.dim());
//!
//! // Write back (original data type is preserved)
//! tif.write("output.tif")?;
//! ```
//!
//! ## Window Reading (Memory Efficient)
//!
//! ```ignore
//! use rstiff::GeoTiff;
//!
//! // Only read a 256x256 tile - perfect for large files
//! let tile = GeoTiff::read_window("large.tif", 1000, 2000, 256, 256)?;
//!
//! // Read by geographic bounds
//! let roi = GeoTiff::read_bounds("large.tif", (116.0, 39.0, 117.0, 40.0))?;
//!
//! // Read by vector file extent
//! let roi = GeoTiff::read_by_vector("large.tif", "area.kml", true)?;
//! ```
//!
//! ## Metadata Without Loading Pixels
//!
//! ```ignore
//! use rstiff::GeoTiff;
//!
//! let info = GeoTiff::info("large.tif")?;
//! println!("Size: {}x{}", info.width, info.height);
//! println!("Bounds: {:?}", info.bounds());
//!
//! // Coordinate conversion
//! let (x, y) = info.pixel_to_geo(100, 200);
//! let (col, row) = info.geo_to_pixel(116.5, 39.5);
//! ```
//!
//! ## Prerequisites
//!
//! This library requires GDAL to be installed on your system:
//!
//! - **macOS**: `brew install gdal`
//! - **Ubuntu/Debian**: `sudo apt-get install libgdal-dev`
//!
//! ## Documentation
//!
//! Due to GDAL system dependency, docs.rs may fail to build documentation.
//! Generate documentation locally with:
//!
//! ```bash
//! cargo doc --open
//! ```
// Re-exports for easier access
pub use TiffError;
pub use GeoTiff;
pub use RasterInfo;