geotiff.js icon indicating copy to clipboard operation
geotiff.js copied to clipboard

How to get projection of the TIF file

Open marjorieRobert opened this issue 5 years ago • 3 comments

I'm using geotiff.js to visualize a geotiff file on a Openlayers'map. Here is my code : `const tiff = await GeoTIFF.fromBlob(file); const image = await tiff.getImage(); const data = await image.readRasters();

const geotiffLayer = new ol.layer.Image();

const rawBox = image.getBoundingBox(); const box = [rawBox[0],rawBox[1] - (rawBox[3] - rawBox[1]), rawBox[2], rawBox[1]]; const bands = await image.readRasters();

let the_canvas = document.createElement('canvas'); const plot = new plotty.plot({ canvas: the_canvas, data: bands[0], width: image.getWidth(), height: image.getHeight(), domain: [0,256], colorScale: 'earth' }); plot.render();

var imgSource = new ol.source.ImageStatic({ url: the_canvas.toDataURL("image/png"), imageExtent: box, imageSize : [image.getWidth(), image.getHeight()], projection: 'EPSG:2154' //here, I would like to get the projection of the geotiff })`

When I create the source of the layer, I've to put the projection of the geotiff file. Can you say me how can I get this projection? I've read the docs but didn't find it. Thanks

marjorieRobert avatar Mar 13 '20 10:03 marjorieRobert

Hi @marjorieRobert

You are right, this information is currently not easily available. The GeoTIFFImage class has the getGeoKeys function which provides all parsed geo keys as per the GeoTIFF spec. It is possible, however, to get EPSG codes for some cases, e.g like we did in COG-Explorer: https://github.com/geotiffjs/cog-explorer/blob/master/src/components/mapview.jsx#L196

I always planned to implement some facilities to get the projection information of an image in proj, WKT or EPSG code format, but I never got around to do that as it is very complex, especially for corner cases.

I hope I could help you, and thanks for raising this issue.

constantinius avatar Mar 13 '20 11:03 constantinius

Has this been fixed in geotiff.js now?

howff avatar Nov 25 '21 20:11 howff

@howff There is no converter to proj format or WKT yet. But you can still use the solution described in the mentioned link if you have a specified CRS.

constantinius avatar Nov 29 '21 16:11 constantinius