Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coordinate Transformations #21

Merged
merged 15 commits into from
Nov 21, 2024
Merged

Conversation

gschulze
Copy link
Collaborator

@gschulze gschulze commented Oct 7, 2024

This PR implements all coordinate transformation methods used in GeoTIFF:

  • Tie Point and Pixel Scale
  • Affine Transform
  • Multiple Tie Points (Ground Control Points)

In addition, the implementation considers the raster type (RasterPixelIsArea or RasterPixelIsPoint) to determine the origin of the raster space coordinate system.

The Tie Point and Pixel Scale and Affine Transform methods are relatively straightforward. The Multiple Tie Points transformation roughly works as follows:

  • Create a Delaunay triangulation of the tie points in raster space
  • Apply the resulting triangulation to the tie points in model space
  • When doing coordinate transformations, use the containing triangle of a coordinate to determine the three points to be used for the transformation
  • Determine the relative position of the coordinate within the triangle in the model space coordinate system
  • Use the relative position to linearly interpolate the coordinate within the corresponding triangle in the raster space coordinate system

@weiji14 please have a look.

Cargo.toml Outdated Show resolved Hide resolved
@gschulze gschulze force-pushed the feature/coordinate-transformation branch from 23b7ac0 to 16ddd6b Compare October 8, 2024 03:21
@gschulze gschulze force-pushed the feature/coordinate-transformation branch from 084bcdf to 0e43e48 Compare October 8, 2024 06:49
@gschulze gschulze requested review from kylebarron and weiji14 October 8, 2024 07:59
@gschulze gschulze self-assigned this Oct 8, 2024
Copy link
Member

@weiji14 weiji14 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a couple of quick comments on the organization of the code. I'll try to find some time to do a deeper dive over the weekend!

Cargo.toml Outdated Show resolved Hide resolved
tests/integration.rs Outdated Show resolved Hide resolved
@kylebarron
Copy link
Member

I'm not familiar with how GCPs work, so if @weiji14 has time to review I'll defer to him

Copy link
Member

@weiji14 weiji14 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did an initial look through the changes and looks good so far! Unit tests are solid (you're lucky I did a exchange in Salzvurg, Austria many years ago, so familiar with the geography 😃), and I do appreciate the changes to get_pixel_value to return Some/None.

Leaving a few small comments or now, I'd be keen on a bit more documentation around the public enums/structs if possible (a link to the relevant subsection in the GeoTIFF spec will do). Will squeeze out some time next week to do a deeper review on the affine and Delaunay triangulation math.

src/geo_key_directory.rs Outdated Show resolved Hide resolved
src/coordinate_transform.rs Show resolved Hide resolved
Copy link
Member

@weiji14 weiji14 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I've checked the affine transform code and it looks sound. The Delaunay triangulation logic is a bit over my head, but I trust that it is ok (if not, someone will hopefully notice and file a bug report).

Don't want to hold this back any longer because I'm getting into a busy period, so I'll pre-approve this. I have some questions below around the get_value_at method, but hopefully those are non-issues.

src/lib.rs Show resolved Hide resolved
src/lib.rs Outdated
Comment on lines 144 to 151
let mut coord = match coordinate_transform {
None => *coord,
Some(transform) => transform.transform_to_raster(coord),
};

let raster_offset = self.raster_offset();
coord.x -= raster_offset;
coord.y -= raster_offset;
Copy link
Member

@weiji14 weiji14 Oct 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just want to double-check the logic here because. If I'm not mistaken, the code is:

  1. Transforming model coordinates to raster coordinates via transform_to_raster
  2. Applying an offset of -0.5 (in the case of PixelisPoint) to the raster coordinates?

Is it correct to apply an offset of -0.5 (which should be a model offset) to raster coordinates?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@weiji14 The 0.5 offset refers to half a pixel, which only makes sense in raster space. See https://docs.ogc.org/is/19-008r4/19-008r4.html#_raster_space for reference. This issue also has some nice illustrations: opengeospatial/ogcapi-coverages#92

I added a reference to the corresponding section in the standard in the code.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I remember correctly, I also cross-checked with QGIS regarding handling of the raster type.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok, I got mixed up on raster space (which should be pixels) and model space (which are real world coordinates in metres or other units). I kept thinking raster offset should be in metres and model offset is in pixels, but it should be the other way around. Thanks for providing the links for clarification, and for adding an inline comment to document this in the code!

@gschulze
Copy link
Collaborator Author

Thanks @weiji14 for your comments. I've been busy the last two weeks, but hopefully, I'll find time to address the remaining issues next week.

@gschulze gschulze force-pushed the feature/coordinate-transformation branch from e9cedc0 to 78020cd Compare November 20, 2024 11:22
@gschulze gschulze force-pushed the feature/coordinate-transformation branch from 78020cd to f13418e Compare November 20, 2024 11:27
@gschulze
Copy link
Collaborator Author

@weiji14 Let me know if you want any further changes; otherwise, I will merge this PR.

@weiji14
Copy link
Member

weiji14 commented Nov 20, 2024

Let's go ahead and merge, thanks for adding the extra docs and bug fixes!

@gschulze gschulze merged commit 95172cb into main Nov 21, 2024
2 checks passed
@weiji14 weiji14 deleted the feature/coordinate-transformation branch November 21, 2024 20:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants