Skip to content
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ Download the following file for use in the tests.

```shell
aws s3 cp s3://naip-visualization/ny/2022/60cm/rgb/40073/m_4007307_sw_18_060_20220803.tif ./ --request-payer
aws s3 cp s3://prd-tnm/StagedProducts/Elevation/13/TIFF/current/s14w171/USGS_13_s14w171.tif ./ --no-sign-request --region us-west-2
```
1 change: 1 addition & 0 deletions python/DEVELOP.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
uv sync --no-install-package async-tiff
uv run --no-project maturin develop
uv run --no-project mkdocs serve
uv run --no-project pytest --verbose
```
11 changes: 9 additions & 2 deletions src/ifd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,15 @@ impl ImageFileDirectory {
.expect("There should be a chunk for each key.");

let key_id = chunk[0];
let tag_name =
GeoKeyTag::try_from_primitive(key_id).expect("Unknown GeoKeyTag id: {key_id}");
let tag_name = if let Ok(tag_name) = GeoKeyTag::try_from_primitive(key_id) {
tag_name
} else {
// Skip unknown GeoKeyTag ids. Some GeoTIFFs include keys that were proposed
// but not included in the GeoTIFF spec. See
// https://github.com/developmentseed/async-tiff/pull/131 and
// https://github.com/virtual-zarr/virtual-tiff/issues/52
continue;
};

let tag_location = chunk[1];
let count = chunk[2];
Expand Down
25 changes: 25 additions & 0 deletions tests/geo.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use std::env;
use std::sync::Arc;

use async_tiff::metadata::{PrefetchBuffer, TiffMetadataReader};
use async_tiff::reader::{AsyncFileReader, ObjectReader};
use object_store::local::LocalFileSystem;

#[tokio::test]
async fn test_parse_file_with_unknown_geokey() {
let folder = env::current_dir().unwrap();
let path = object_store::path::Path::parse("tests/images/geogtowgs_subset_USGS_13_s14w171.tif")
.unwrap();
let store = Arc::new(LocalFileSystem::new_with_prefix(folder).unwrap());
let reader = Arc::new(ObjectReader::new(store, path)) as Arc<dyn AsyncFileReader>;
let prefetch_reader = PrefetchBuffer::new(reader.clone(), 32 * 1024)
.await
.unwrap();
let mut metadata_reader = TiffMetadataReader::try_open(&prefetch_reader)
.await
.unwrap();
let _ = metadata_reader
.read_all_ifds(&prefetch_reader)
.await
.unwrap();
}
Binary file added tests/images/geogtowgs_subset_USGS_13_s14w171.tif
Binary file not shown.
35 changes: 35 additions & 0 deletions tests/images/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
`geogtowgs_subset_USGS_13_s14w171.tif` was created from "s3://prd-tnm/StagedProducts/Elevation/13/TIFF/current/s14w171/USGS_13_s14w171.tif" using these commands:

```bash
gdal_translate USGS_13_s14w171.tif tiny.tif -srcwin 0 0 1 1 -co COMPRESS=DEFLATE
listgeo USGS_13_s14w171.tif > metadata.txt # Then modify to remove information related to spatial extent
cp tiny.tif geogtowgs_subset_USGS_13_s14w171.tif
geotifcp -g metadata.txt tiny.tif geogtowgs_subset_USGS_13_s14w171.tif
listgeo geogtowgs_subset_USGS_13_s14w171.tif
```

and this workspace definition:

```toml
[project]
name = "gdal-workspace"
version = "0.1.0"
description = "workspace for using gdal via pixi"
readme = "README.md"
requires-python = ">=3.12"
dependencies = []

[tool.pixi.workspace]
channels = ["conda-forge"]
platforms = ["osx-arm64"]

[tool.pixi.pypi-dependencies]
gdal-workspace = { path = ".", editable = true }

[tool.pixi.tasks]

[tool.pixi.dependencies]
gdal = ">=3.11.5,<4"
libgdal = ">=3.11.5,<4"
geotiff = ">=1.7.4,<2"
```
2 changes: 2 additions & 0 deletions tests/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
mod geo;
mod image_tiff;
mod ome_tiff;
29 changes: 26 additions & 3 deletions tests/ome_tiff.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,35 @@
/// Integration tests on OME-TIFF files.
//! Integration tests on OME-TIFF files.

use std::sync::Arc;

use async_tiff::metadata::{PrefetchBuffer, TiffMetadataReader};
use async_tiff::reader::{AsyncFileReader, ObjectReader};
use async_tiff::tiff::tags::PhotometricInterpretation;
use async_tiff::TIFF;
use reqwest::Url;

mod util;
async fn open_remote_tiff(url: &str) -> TIFF {
let parsed_url = Url::parse(url).expect("failed parsing url");
let (store, path) = object_store::parse_url(&parsed_url).unwrap();

let reader = Arc::new(ObjectReader::new(Arc::new(store), path)) as Arc<dyn AsyncFileReader>;
let prefetch_reader = PrefetchBuffer::new(reader.clone(), 32 * 1024)
.await
.unwrap();
let mut metadata_reader = TiffMetadataReader::try_open(&prefetch_reader)
.await
.unwrap();
let ifds = metadata_reader
.read_all_ifds(&prefetch_reader)
.await
.unwrap();
TIFF::new(ifds)
}

#[tokio::test]
async fn test_ome_tiff_single_channel() {
let tiff =
util::open_remote_tiff("https://downloads.openmicroscopy.org/images/OME-TIFF/2016-06/bioformats-artificial/single-channel.ome.tif").await;
open_remote_tiff("https://downloads.openmicroscopy.org/images/OME-TIFF/2016-06/bioformats-artificial/single-channel.ome.tif").await;

assert_eq!(tiff.ifds().len(), 1);
let ifd = &tiff.ifds()[0];
Expand Down
24 changes: 0 additions & 24 deletions tests/util/mod.rs

This file was deleted.