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

QUESTION: How to get WGS 84 coordinates from GeoTiff? #176

Closed
jorrit-g opened this issue Sep 11, 2020 · 2 comments
Closed

QUESTION: How to get WGS 84 coordinates from GeoTiff? #176

jorrit-g opened this issue Sep 11, 2020 · 2 comments

Comments

@jorrit-g
Copy link

jorrit-g commented Sep 11, 2020

Hi there,

I'm fairly new to the GIS domain so maybe i'm not understanding some things.

I'm reading a geotiff file with geotiff.js but now i don't see any method to convert a pixel to an actual WGS84 coordinate?

I do see the GeogTOWGS84GeoKey but I have no idea how to use this key to convert tiff pixels to coordinates.

Could anybody shed some light on the floats in GeogTOWGS84GeoKey?

Happy to provide make a PR for a image.toCoordinate() method (if that would be even possible?)

Much appreciated!

@constantinius
Copy link
Member

Hi @jorrit-g

Currently, geotiff.js only provides rudimentary information about the internally used projection and location. This information is stored in some special tags called geo keys. The full list of them can be seen in the specification. Unfortunately the possibilities to encode geospatial referencing are quite diverse, so geotiff.js never included anything more than the most rudimentary form.

Also, geotiff.js will likely never support reprojection of coordinates and rasters, as this is a much more complicated field and out of scope of this project.

For starters, I suggest the following approach:

  • If you know that the used projection is actually WGS84 (or the GeographicTypeGeoKey is 4326) then you can apply some math to project the the X/Y image coordinates to WGS84. The following is to be understood as pseudocode:
const origin = image.getOrigin();
const resolution = image.getResolution();

const lon = origin[0] + x * resolution[0];
const lat = origin[1] + y * resolution[1];
  • When this is not the case, the problem is more tricky, as you first need to transform the image coordinates to the native projection and then reproject to WGS84. This should be doable with proj4js when you have the according projection information. If you are lucky they are simply set in ProjectedCSTypeGeoKey or GeographicTypeGeoKey and you can get the projections WKT representation from epsg.io. See here how it was done in the COG-Explorer.

I hope I could help you with your problem. Let me know if there is still some question unanswered.

@jorrit-g
Copy link
Author

@constantinius thank you for your reply and help! I did have the projection info in my tif under ProjectedCSTypeGeoKey and was able to reproject with proj4js and epsg.io. Thanks again.

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

No branches or pull requests

2 participants