ArchGDAL.jl icon indicating copy to clipboard operation
ArchGDAL.jl copied to clipboard

How to extract longitude and latitude from a geoTIFF?

Open sethmb opened this issue 6 years ago • 3 comments

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!

sethmb avatar Nov 23 '18 05:11 sethmb

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

yeesian avatar Nov 23 '18 06:11 yeesian

Thank you very much! The code worked as expected.

sethmb avatar Nov 28 '18 23:11 sethmb

Re-opening. I'll close this issue after we have something on it in the documentation. Thanks for bringing it up!

yeesian avatar Nov 28 '18 23:11 yeesian