Add get origin func to COG#1840
Conversation
There was a problem hiding this comment.
Pull Request Overview
Adds a helper to extract the spatial origin from a COG’s GeoTIFF tags and integrates it into the metadata.
- Introduce
originfield inMetaand call a newget_originfunction inget_meta - Implement
get_originto read either the first ModelTiepointTag or the Transformation matrix - Add corresponding error variant, unit tests, and update dependencies
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| martin/src/cog/source.rs | Added origin field, implemented get_origin, integrated into get_meta, and added tests |
| martin/src/cog/errors.rs | Introduced GetOriginFailed error variant |
| martin/Cargo.toml | Added approx dev-dependency and reordered testcontainers-modules |
Comments suppressed due to low confidence (2)
martin/src/cog/errors.rs:56
- [nitpick] Consider enriching this error message with context, such as indicating whether both tie points and transformation tags were missing or invalid.
#[error("Get origin failed for {0}")]
martin/src/cog/source.rs:593
- Add a unit test for the failure case (e.g., both
tie_pointsandtransformationareNone) to cover the error branch inget_origin.
}
There was a problem hiding this comment.
Pull Request Overview
This PR adds a new function to extract the origin coordinate from a Cloud Optimized GeoTIFF (COG) using either tie points or a transformation matrix as defined in the GeoTIFF specification. Key changes include:
- Adding an origin field to the Meta struct in source.rs.
- Implementing and integrating the get_origin function to calculate the origin based on provided tie points or transformation matrix.
- Adding corresponding tests to verify get_origin behavior.
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| martin/src/cog/source.rs | Adds the origin field to Meta, implements get_origin, and integrates it within get_meta along with tests. |
| martin/src/cog/errors.rs | Adds a GetOriginFailed error variant for failure cases in get_origin. |
| martin/Cargo.toml | Adds approx as a dev-dependency for testing purposes. |
Comments suppressed due to low confidence (1)
martin/src/cog/source.rs:576
- [nitpick] The test parameters are named 'matrix' and 'tie_point', but they are passed to get_origin in reversed order relative to the function signature. Consider renaming the test parameters to match the function parameter order for clarity.
fn can_get_origin(
There was a problem hiding this comment.
Pull Request Overview
Adds support for extracting the geographic origin from a Cloud-Optimized GeoTIFF by introducing a new origin field on Meta and a helper to compute it from GeoTIFF tags.
- Extend
Metawith a 3-elementorigincoordinate and populate it inget_meta. - Implement
get_originto derive the origin from either tie points or a transformation matrix, plus associated error variant and tests. - Add
approxas a dev-dependency for floating-point comparisons in tests.
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| martin/src/cog/source.rs | Added origin field, implemented get_origin, and tests |
| martin/src/cog/errors.rs | Introduced GetOriginFailed error variant |
| martin/Cargo.toml | Added approx under [dev-dependencies] for test assertions |
Comments suppressed due to low confidence (1)
martin/src/cog/source.rs:426
- Add a test case for when both tie_points and transformation are
Noneto exercise theGetOriginFailederror path.
fn get_origin(
for more information, see https://pre-commit.ci
CommanderStorm
left a comment
There was a problem hiding this comment.
If you add some documentation in the form if doc comments what an origin is, I am fine with this.
I honestly don't have a good understanding what an origin is.
| min_zoom: u8, | ||
| max_zoom: u8, | ||
| model: ModelInfo, | ||
| origin: [f64; 3], |
There was a problem hiding this comment.
Could you add doc comments explaining what the origin is?
This would be very handy as origin as 3*f64 is not quite self-explanatory.
There was a problem hiding this comment.
Hmm. I will try. Actually it's the coords: raster_space_to_model_space(0,0,0), I'm not good at this, maybe you have better one?
I add this to:
// The geo coords of pixel(0, 0, 0) ordering in [x, y, z]
origin: [f64; 3],
It's the 2nd PR of #1814 to fix #1820
A func to get the origin coord from COG is added. It's highly inspired by geotiff.js and the content of B.6 of geotiff spec