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

GeoTIFF layers do not support TIFFs with GeoTransform/rotation #15294

Open
loganwilliams opened this issue Nov 2, 2023 · 11 comments · May be fixed by #15402
Open

GeoTIFF layers do not support TIFFs with GeoTransform/rotation #15294

loganwilliams opened this issue Nov 2, 2023 · 11 comments · May be fixed by #15402
Labels

Comments

@loganwilliams
Copy link

loganwilliams commented Nov 2, 2023

Describe the bug
When trying to add a certain GeoTIFF to an OpenLayers map, it renders in an incorrect location. The GeoTIFF in question is https://unnerving-monsoon.ams3.cdn.digitaloceanspaces.com/Georgia/2023-10-30-06-47-55_UMBRA-04.tif. This is not reproduced in QGIS or other COG tools.

To Reproduce
Steps to reproduce the behavior:

  1. Go to https://www.cogeo.org/map/ and use the URL above. The TIFF renders correctly, using Marblecutter.
  2. Go to https://geotiffjs.github.io/cog-explorer/ and use the URL above. The TIFF renders in an incorrect location, using OpenLayers.

It can also be reproduced by adding the following source to an OpenLayers map:

const source = new GeoTIFF({
  normalize: true,
  bands: [1, 1, 1],
  sources: [
    {
      url: 'https://unnerving-monsoon.ams3.cdn.digitaloceanspaces.com/Georgia/2023-10-30-06-47-55_UMBRA-04.tif',
      bands: [1, 1, 1],
      max: 300,
    },
  ],
});

Expected behavior
The projection and extent is read and interpreted correctly.

@loganwilliams loganwilliams changed the title Cloud optimized GeoTIFF renders in inaccurate location Cloud optimized GeoTIFF renders in incorrect location Nov 2, 2023
@loganwilliams
Copy link
Author

After looking into this some more, I think it might be a bug or unsupported feature in geotiff.js. Any insights appreciated.

@mike-000
Copy link
Contributor

mike-000 commented Nov 2, 2023

Also the image is rotated 90 degrees compared with the correctly placed one.

@loganwilliams
Copy link
Author

Possibly related to this issue from over a year ago: geotiffjs/geotiff.js#313

@ahocevar
Copy link
Member

ahocevar commented Nov 3, 2023

Possibly related to this issue from over a year ago: geotiffjs/geotiff.js#313

I don't think that's the problem. If the GeoTIFF image in question uses a projection with an axis order different than enu, and is encoded with that flipped axis order, the problem is that OpenLayers always assumes x/y axis order. To display such a GeoTIFF properly, an extra raster reprojection step would be necessary, with a transform that just swaps x and y.

@mike-000
Copy link
Contributor

mike-000 commented Nov 3, 2023

@ahocevar The GeoTIFF is misplaced in the reported UTM projection but reasonably close to the expected position, rotated and slightly smaller than expected. Swapping axes would make it much more displaced.

@mike-000
Copy link
Contributor

mike-000 commented Nov 3, 2023

After checking the two outputs more thoroughly the top left corner as seen in OpenLayers is in the correct position - the image is rotated slightly less then 90 degrees around that point (which should be at top right when corrected) and is also downscaled. It does seem related to geotiffjs/geotiff.js#313

@loganwilliams loganwilliams changed the title Cloud optimized GeoTIFF renders in incorrect location GeoTIFF layers do not support TIFFs with GeoTransform/rotation Nov 8, 2023
@loganwilliams
Copy link
Author

Fixing the calculation of the resolution in Geotiff.js (I'll file a PR for Geotiff.js soon) corrected the error in size, but it is still rendered in an incorrect position and rotation. I think that this problem is on the OpenLayers side, which would need to make use of the transformation properties of the TIFF in the rendering of the image.

@loganwilliams
Copy link
Author

The changes to geotiff.js are in this PR: geotiffjs/geotiff.js#403

@mike-000
Copy link
Contributor

Your example link is no longer working. Are you are to recreate it?

To support rotation I think the tilegrid would need to be considered to be in a custom rotated or skewed projection derived from the reported projection similar to the images in #12601. If the reported projection needs a proj4 lookup as in https://openlayers.org/en/latest/examples/cog-projection.html some changes to proj4 registration process would be needed as transforms between the rotated projection and any other possible view projections could not be defined until then.

@carmenmarquez
Copy link

It happens the same to me #15370

@mike-000
Copy link
Contributor

mike-000 commented Dec 1, 2023

A fix is definitely possible, there is some discussion about and links to Umbra COGs in stac-utils/stac-layer#61. While geotiffjs/geotiff.js#403 will fix the scale issue, it is necessary to consider the tile grid to be in a rotated projection for it to be positioned correctly. A recent change to geotiff.js geotiffjs/geotiff.js#361 does the opposite of that, and it now returning the larger bounding box which encloses the rotated tile grid in an unrotated projection, which is of no use to OpenLayers (and probably of limited use to Leaflet) so OpenLayers will need to apply the old method directly. Currently to work correctly the unrotated projection must be defined before the rotated one, and there seems to be a problem with a reverse transform, so this example simply reprojects the base layer to the COG's rotated projection
https://codesandbox.io/s/cog-forked-dl795h?file=/main.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants