ArchGDAL.jl
ArchGDAL.jl copied to clipboard
How to extract longitude and latitude from a geoTIFF?
Hello,
First of all, thank you developers for all the hard work!
I have an image of a traffic density heat map that I have georeferenced and exported as a geoTIFF. I am now trying to extract the longitude and latitude values from that georeferenced image using Julia. I am reasonably new to Julia programming and geodata, so a lot of the documentation is going over my head.
Is this something that ArchGDAL can be used for? If so, how? The documentation available does provide some hints on how to do it but there are no easy to follow examples.
My apologies for the beginner questions.
Cheers!
This is not currently documented. One way of doing it (using utmsmall.tif as an example) is:
import ArchGDAL, GeoInterface
const AG = ArchGDAL
function px2xy(gt, x, y)
xoff, a, b, yoff, d, e = gt
xp = a * (x + 0.5) + b * (y + 0.5) + xoff
yp = d * (x + 0.5) + e * (y + 0.5) + yoff
AG.createpoint(xp, yp)
end
lnglats = AG.registerdrivers() do
AG.read("utmsmall.tif") do ds
geotransform = AG.getgeotransform(ds)
spatialref = AG.importWKT(AG.getproj(ds))
AG.createcoordtrans(spatialref, AG.importEPSG(4326)) do transform
[
GeoInterface.coordinates(
AG.transform!(px2xy(geotransform,i,j), transform)
)
for i in 1:AG.width(ds), j in 1:AG.height(ds)
]
end
end
end
Thank you very much! The code worked as expected.
Re-opening. I'll close this issue after we have something on it in the documentation. Thanks for bringing it up!