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

RasterLayer reprojection #37

Open
kylebarron opened this issue Sep 15, 2020 · 1 comment
Open

RasterLayer reprojection #37

kylebarron opened this issue Sep 15, 2020 · 1 comment

Comments

@kylebarron
Copy link
Owner

Note: this original "RFC" is only for a single, simple GeoTIFF. A multi-resolution image like a COG is much harder because you have to handle visibility of internal tiles to figure out what to load.

There's a continuum of options between reprojecting every pixel and reprojecting only the corners.

  1. Load geotiff
  2. Find EPSG code from GeoTIFF metadata, see here, otherwise return. From QUESTION: How to get WGS 84 coordinates from GeoTiff? geotiffjs/geotiff.js#176:

[When the source image is not in WGS84], 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.

Therefore, to reproject an arbitrary pixel, given source_crs, dest_crs, pixel_x, pixel_y, image_height, image_width (watch out for flipped-y coordinates in images), you should be able to do something like the pseudocode:

src_crs_x = (pixel_x / width) * (bbox_max_x - bbox_min_x) + bbox_min_x
ditto for y, except for flipped coordinate

proj4(from, to, [src_crs_x, src_crs_y])

Then the next question is how many points to reproject. You can reproject only the corners, but for non-linear transformations, the inner pixels won't be in exactly the right place.

Alternatively you can reproject every image pixel, so that every pixel is in exactly the right position. To do this, you'd modify the existing mesh-creation code. (Since 8.2 when the GlobeView was added, the BitmapLayer creates a mesh and uses the GL.TRIANGLES draw mode.) The simplest way to do this then is to make a uniform mesh where every pixel gets two triangles. Then use those triangles as the inner mesh state.

References:

@kylebarron kylebarron changed the title Example with geotiff.js RasterLayer reprojection Sep 18, 2020
@kylebarron
Copy link
Owner Author

Note you can just use the existing resolution param and that might be good enough for accurate reprojection.

@kylebarron kylebarron mentioned this issue Sep 18, 2020
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

1 participant