Skip to content

Commit

Permalink
📝 Copy example usage to crate-level docs as doctest
Browse files Browse the repository at this point in the history
Copy the Rust code from 15b0dbc to src/lib.rs as a doctest. Need to change `crate-type = ["rlib"]` in Cargo.toml so that `cargo test --doc` works, but will configure that in CI later.
  • Loading branch information
weiji14 committed Mar 4, 2024
1 parent 33f4a73 commit 5c412da
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 1 deletion.
17 changes: 17 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ numpy = "0.20.0"
object_store = { version = "0.9.0", features = ["http"] }
pyo3 = { version = "0.20.3", features = ["abi3-py310", "extension-module"] }
tiff = "0.9.1"
tokio = "1.36.0"
tokio = { version = "1.36.0", features = ["rt-multi-thread"] }
url = "2.5.0"

[dev-dependencies]
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ async fn main() {

let arr: Array2<f32> = read_geotiff(stream).unwrap();
assert_eq!(arr.dim(), (549, 549));
assert_eq!(arr[[500, 500]], 0.13482364);
}
```

Expand Down
35 changes: 35 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,41 @@
//! **Note**: For Python users, there are also bindings (via [`pyo3`]) to read GeoTIFF files into
//! `numpy.ndarray` objects (i.e. similar to [`rasterio`](https://github.com/rasterio/rasterio)).
//! This is done via the [`numpy`] crate which enables passing data from Rust to Python.
//!
//! # Examples
//!
//! Read a GeoTIFF file retrieved via the [`object_store`] crate, and pass it into the
//! [`read_geotiff`](./io/geotiff/fn.read_geotiff.html) function.
//!
//! ```rust
//! use std::io::Cursor;
//!
//! use bytes::Bytes;
//! use cog3pio::io::geotiff::read_geotiff;
//! use ndarray::Array2;
//! use object_store::path::Path;
//! use object_store::{parse_url, GetResult, ObjectStore};
//! use tokio;
//! use url::Url;
//!
//! #[tokio::main]
//! async fn main() {
//! let cog_url: &str =
//! "https://github.com/cogeotiff/rio-tiler/raw/6.4.0/tests/fixtures/cog_nodata_nan.tif";
//! let tif_url: Url = Url::parse(cog_url).unwrap();
//! let (store, location): (Box<dyn ObjectStore>, Path) = parse_url(&tif_url).unwrap();
//!
//! let stream: Cursor<Bytes> = {
//! let result: GetResult = store.get(&location).await.unwrap();
//! let bytes: Bytes = result.bytes().await.unwrap();
//! Cursor::new(bytes)
//! };
//!
//! let arr: Array2<f32> = read_geotiff(stream).unwrap();
//! assert_eq!(arr.dim(), (549, 549));
//! assert_eq!(arr[[500, 500]], 0.13482364);
//! }
//! ```

/// Modules for handling Input/Output of GeoTIFF data
pub mod io;
Expand Down

0 comments on commit 5c412da

Please sign in to comment.