stac-utils / stac-layer

Visualize a STAC Item or Collection on a Leaflet Map
Creative Commons Zero v1.0 Universal
47 stars 11 forks source link

Fall back to footprint when COG isn't georeferenced #14

Open m-mohr opened 2 years ago

m-mohr commented 2 years ago

Originates from https://github.com/radiantearth/stac-browser/issues/101 and was written originally by @AsgerPetersen:

The Items in this demo catalog https://skraafotodistribution-stacfastapi.k8s-test-121.septima.dk/ have footprints, but their COGs are not georeferenced as they are not rectified.

It would be nice if the browser would fall back to the footprint in that case.

image

DanielJDufour commented 2 years ago

I dug a little deeper and the issue is that I'm missing a try-catch in georaster which causes the promise to parse the GeoRaster to never complete when this error occurs. Here's a link to the line where I need to add a try/catch: https://github.com/GeoTIFF/georaster/blob/master/src/parseData.js#L83. When I manually throw the error, stac-layer works fine.

I'll fix georaster and this should fix the downstream issues.

m-mohr commented 2 years ago

Sounds great, thanks. I thought this would be a new feature and not a bugfix :-)

DanielJDufour commented 2 years ago

Small update. I tried to fix this in georaster with https://github.com/GeoTIFF/georaster/commit/93d6491394e623c6fe1189c4f2c85cba98288b3a#diff-5369190f55138dab912f4f97bca88335d0f783f50e14cda286672c7e5821963aR83, but it didn't work. The issue is that georaster uses old school promises and not async/await, so I have to update the code not just there, but everywhere else along the promise chain to make sure the error is sent all the way up (not to mention that the promise rejection is inside a web worker, so the error has to be sent as a message to the main thread).

I'm working on a massive upgrade to georaster at the moment (including using async/await), but that probably won't be complete for still a couple months. I've already sank 2 hours into doing a hotfix to georaster, so I'm not optimistic about this path.

That said, I think there is an easier solution. I can just fetch the first 1k bytes and then check if the projection information is in there using geotiff.js or is-cog. If it's not, don't run parseGeoraster. I'll keep you updated.

DanielJDufour commented 2 years ago

This will hopefully be addressed by https://github.com/stac-utils/stac-layer/pull/13 whereby if the georaster doesn't finish parsing after 5 seconds, it will move onto the next load option. I know it's not perfect, but should hopefully be sufficient until the next major release of georaster (hopefully by the end of the year).

m-mohr commented 1 year ago

The original data is not available anymore, is there a successor URL/file we could test with @AsgerPetersen?

AsgerPetersen commented 1 year ago

This is the production version of the STAC api: https://api.dataforsyningen.dk/skraafoto_api/v1.0/?token=6f27c9754e42e3ded6042f804203579b

The API and its data are free and open but requires a user token. I have created a token specifically for this issue, but I cannot guarantee for how long the token will survive. Ping me again if it stops working.

m-mohr commented 1 year ago

@AsgerPetersen Thanks a lot! Would you be okay with us downloading one of the GeoTiffs and (maybe after cropping), putting it with attribution (CC-BY 4.0) on https://github.com/GeoTIFF/test-data so that we avoid the token issue?

AsgerPetersen commented 1 year ago

According to the license link on the items (https://dataforsyningen.dk/Vilkaar) CC-BY 4.0 is allowed. The name of the creator is "Styrelsen for Dataforsyning og Infrastruktur"

m-mohr commented 1 year ago

@AsgerPetersen Thank you!

@DanielJDufour If you think this is a good idea, could you take care of this? I don't think I can push to the test-data repo...