Skip to content

Commit 5e38113

Browse files
committed
feat:geo-tag-registry geo tag resitry preliminary commit
1 parent 465c5c5 commit 5e38113

File tree

3 files changed

+264
-136
lines changed

3 files changed

+264
-136
lines changed

src/geo/affine.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,21 @@ impl AffineTransform {
4040
self.5
4141
}
4242

43-
/// Construct a new Affine Transform from the IFD
44-
pub fn from_ifd(ifd: &ImageFileDirectory) -> Option<Self> {
45-
if let (Some(model_pixel_scale), Some(model_tiepoint)) =
46-
(&ifd.model_pixel_scale, &ifd.model_tiepoint)
47-
{
48-
Some(Self::new(
49-
model_pixel_scale[0],
50-
0.0,
51-
model_tiepoint[3],
52-
0.0,
53-
-model_pixel_scale[1],
54-
model_tiepoint[4],
55-
))
56-
} else {
57-
None
58-
}
59-
}
43+
// /// Construct a new Affine Transform from the IFD
44+
// pub fn from_ifd(ifd: &ImageFileDirectory) -> Option<Self> {
45+
// if let (Some(model_pixel_scale), Some(model_tiepoint)) =
46+
// (&ifd.model_pixel_scale, &ifd.model_tiepoint)
47+
// {
48+
// Some(Self::new(
49+
// model_pixel_scale[0],
50+
// 0.0,
51+
// model_tiepoint[3],
52+
// 0.0,
53+
// -model_pixel_scale[1],
54+
// model_tiepoint[4],
55+
// ))
56+
// } else {
57+
// None
58+
// }
59+
// }
6060
}

src/ifd.rs

Lines changed: 15 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,6 @@ pub struct ImageFileDirectory {
137137

138138
pub(crate) extra_tags: ExtraTagsRegistry,
139139

140-
// Geospatial tags
141-
pub(crate) geo_key_directory: Option<GeoKeyDirectory>,
142-
pub(crate) model_pixel_scale: Option<Vec<f64>>,
143-
pub(crate) model_tiepoint: Option<Vec<f64>>,
144-
145140
// GDAL tags
146141
// no_data
147142
// gdal_metadata
@@ -188,11 +183,6 @@ impl ImageFileDirectory {
188183
let mut sample_format = None;
189184
let mut jpeg_tables = None;
190185
let mut copyright = None;
191-
let mut geo_key_directory_data = None;
192-
let mut model_pixel_scale = None;
193-
let mut model_tiepoint = None;
194-
let mut geo_ascii_params: Option<String> = None;
195-
let mut geo_double_params: Option<Vec<f64>> = None;
196186

197187
let mut other_tags = HashMap::new();
198188

@@ -257,13 +247,6 @@ impl ImageFileDirectory {
257247
Tag::JPEGTables => jpeg_tables = Some(value.into_u8_vec()?.into()),
258248
Tag::Copyright => copyright = Some(value.into_string()?),
259249

260-
// Geospatial tags
261-
// http://geotiff.maptools.org/spec/geotiff2.4.html
262-
Tag::GeoKeyDirectoryTag => geo_key_directory_data = Some(value.into_u16_vec()?),
263-
Tag::ModelPixelScaleTag => model_pixel_scale = Some(value.into_f64_vec()?),
264-
Tag::ModelTiepointTag => model_tiepoint = Some(value.into_f64_vec()?),
265-
Tag::GeoAsciiParamsTag => geo_ascii_params = Some(value.into_string()?),
266-
Tag::GeoDoubleParamsTag => geo_double_params = Some(value.into_f64_vec()?),
267250
// Tag::GdalNodata
268251
// Tags for which the tiff crate doesn't have a hard-coded enum variant
269252
Tag::Unknown(DOCUMENT_NAME) => document_name = Some(value.into_string()?),
@@ -274,81 +257,6 @@ impl ImageFileDirectory {
274257
Ok::<_, TiffError>(())
275258
})?;
276259

277-
let mut geo_key_directory = None;
278-
279-
// We need to actually parse the GeoKeyDirectory after parsing all other tags because the
280-
// GeoKeyDirectory relies on `GeoAsciiParamsTag` having been parsed.
281-
if let Some(data) = geo_key_directory_data {
282-
let mut chunks = data.chunks(4);
283-
284-
let header = chunks
285-
.next()
286-
.expect("If the geo key directory exists, a header should exist.");
287-
let key_directory_version = header[0];
288-
assert_eq!(key_directory_version, 1);
289-
290-
let key_revision = header[1];
291-
assert_eq!(key_revision, 1);
292-
293-
let _key_minor_revision = header[2];
294-
let number_of_keys = header[3];
295-
296-
let mut tags = HashMap::with_capacity(number_of_keys as usize);
297-
for _ in 0..number_of_keys {
298-
let chunk = chunks
299-
.next()
300-
.expect("There should be a chunk for each key.");
301-
302-
let key_id = chunk[0];
303-
let tag_name =
304-
GeoKeyTag::try_from_primitive(key_id).expect("Unknown GeoKeyTag id: {key_id}");
305-
306-
let tag_location = chunk[1];
307-
let count = chunk[2];
308-
let value_offset = chunk[3];
309-
310-
if tag_location == 0 {
311-
tags.insert(tag_name, Value::Short(value_offset));
312-
} else if Tag::from_u16_exhaustive(tag_location) == Tag::GeoAsciiParamsTag {
313-
// If the tag_location points to the value of Tag::GeoAsciiParamsTag, then we
314-
// need to extract a subslice from GeoAsciiParamsTag
315-
316-
let geo_ascii_params = geo_ascii_params
317-
.as_ref()
318-
.expect("GeoAsciiParamsTag exists but geo_ascii_params does not.");
319-
let value_offset = value_offset as usize;
320-
let mut s = &geo_ascii_params[value_offset..value_offset + count as usize];
321-
322-
// It seems that this string subslice might always include the final |
323-
// character?
324-
if s.ends_with('|') {
325-
s = &s[0..s.len() - 1];
326-
}
327-
328-
tags.insert(tag_name, Value::Ascii(s.to_string()));
329-
} else if Tag::from_u16_exhaustive(tag_location) == Tag::GeoDoubleParamsTag {
330-
// If the tag_location points to the value of Tag::GeoDoubleParamsTag, then we
331-
// need to extract a subslice from GeoDoubleParamsTag
332-
333-
let geo_double_params = geo_double_params
334-
.as_ref()
335-
.expect("GeoDoubleParamsTag exists but geo_double_params does not.");
336-
let value_offset = value_offset as usize;
337-
let value = if count == 1 {
338-
Value::Double(geo_double_params[value_offset])
339-
} else {
340-
let x = geo_double_params[value_offset..value_offset + count as usize]
341-
.iter()
342-
.map(|val| Value::Double(*val))
343-
.collect();
344-
Value::List(x)
345-
};
346-
tags.insert(tag_name, value);
347-
}
348-
}
349-
geo_key_directory = Some(GeoKeyDirectory::from_tags(tags)?);
350-
}
351-
352260
let samples_per_pixel = samples_per_pixel.expect("samples_per_pixel not found");
353261
let planar_configuration = if let Some(planar_configuration) = planar_configuration {
354262
planar_configuration
@@ -400,9 +308,6 @@ impl ImageFileDirectory {
400308
.unwrap_or(vec![SampleFormat::Uint; samples_per_pixel as _]),
401309
copyright,
402310
jpeg_tables,
403-
geo_key_directory,
404-
model_pixel_scale,
405-
model_tiepoint,
406311
extra_tags: extra_tags_registry,
407312
other_tags,
408313
})
@@ -622,23 +527,23 @@ impl ImageFileDirectory {
622527
self.copyright.as_deref()
623528
}
624529

625-
/// Geospatial tags
626-
/// <https://web.archive.org/web/20240329145313/https://www.awaresystems.be/imaging/tiff/tifftags/geokeydirectorytag.html>
627-
pub fn geo_key_directory(&self) -> Option<&GeoKeyDirectory> {
628-
self.geo_key_directory.as_ref()
629-
}
530+
// /// Geospatial tags
531+
// /// <https://web.archive.org/web/20240329145313/https://www.awaresystems.be/imaging/tiff/tifftags/geokeydirectorytag.html>
532+
// pub fn geo_key_directory(&self) -> Option<&GeoKeyDirectory> {
533+
// self.geo_key_directory.as_ref()
534+
// }
630535

631-
/// Used in interchangeable GeoTIFF files.
632-
/// <https://web.archive.org/web/20240329145238/https://www.awaresystems.be/imaging/tiff/tifftags/modelpixelscaletag.html>
633-
pub fn model_pixel_scale(&self) -> Option<&[f64]> {
634-
self.model_pixel_scale.as_deref()
635-
}
536+
// /// Used in interchangeable GeoTIFF files.
537+
// /// <https://web.archive.org/web/20240329145238/https://www.awaresystems.be/imaging/tiff/tifftags/modelpixelscaletag.html>
538+
// pub fn model_pixel_scale(&self) -> Option<&[f64]> {
539+
// self.model_pixel_scale.as_deref()
540+
// }
636541

637-
/// Used in interchangeable GeoTIFF files.
638-
/// <https://web.archive.org/web/20240329145303/https://www.awaresystems.be/imaging/tiff/tifftags/modeltiepointtag.html>
639-
pub fn model_tiepoint(&self) -> Option<&[f64]> {
640-
self.model_tiepoint.as_deref()
641-
}
542+
// /// Used in interchangeable GeoTIFF files.
543+
// /// <https://web.archive.org/web/20240329145303/https://www.awaresystems.be/imaging/tiff/tifftags/modeltiepointtag.html>
544+
// pub fn model_tiepoint(&self) -> Option<&[f64]> {
545+
// self.model_tiepoint.as_deref()
546+
// }
642547

643548
/// Tags for which the tiff crate doesn't have a hard-coded enum variant.
644549
pub fn other_tags(&self) -> &HashMap<Tag, Value> {

0 commit comments

Comments
 (0)