Skip to content

Commit

Permalink
feat: Implement GeoKeyDirectory
Browse files Browse the repository at this point in the history
  • Loading branch information
gschulze committed Sep 21, 2024
1 parent 6dcad4b commit 2cdf88b
Show file tree
Hide file tree
Showing 7 changed files with 858 additions and 1 deletion.
120 changes: 120 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ authors = ["Dominik Bucher <dobucher@ethz.ch>"]
repository = "https://github.com/georust/geotiff"

[dependencies]
num_enum = "0.7"
num-traits = "0.2"
tiff = "0.9"
Binary file added resources/merc.tif
Binary file not shown.
37 changes: 37 additions & 0 deletions src/decoder_ext.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use std::io::{Read, Seek};

use tiff::decoder::Decoder;
use tiff::tags::Tag;
use tiff::TiffResult;

use crate::geo_key_directory::GeoKeyDirectory;

pub(super) trait DecoderExt {
fn geo_key_directory(&mut self) -> TiffResult<GeoKeyDirectory>;
}

impl<R: Read + Seek> DecoderExt for Decoder<R> {
fn geo_key_directory(&mut self) -> TiffResult<GeoKeyDirectory> {
let Some(directory_data) = self
.find_tag(Tag::GeoKeyDirectoryTag)?
.map(|v| v.into_u16_vec())
.transpose()?
else {
return Ok(GeoKeyDirectory::default());
};

let double_params_data = self
.find_tag(Tag::GeoDoubleParamsTag)?
.map(|v| v.into_f64_vec())
.transpose()?
.unwrap_or_else(|| Vec::with_capacity(0));

let ascii_params_data = self
.find_tag(Tag::GeoAsciiParamsTag)?
.map(|v| v.into_string())
.transpose()?
.unwrap_or_else(|| String::with_capacity(0));

GeoKeyDirectory::from_tag_data(directory_data, double_params_data, ascii_params_data)
}
}
Loading

0 comments on commit 2cdf88b

Please sign in to comment.