How can I get latitude and longitude from a GeoTIFF file?

hi :
I just want to extract the lat and lon information of specifical pixels (or the whole image) from corresponding GeoTIFF file , but I don’t know how to do ???

can u help me ,thanks…

You can use the GeoCoding.

GeoPos gp = geoCoding.getGeoPos(new PixelPos(12,123), null)

or

GeoPos gp = new GeoPos()
geoCoding.getGeoPos(new PixelPos(12,123), gp)

In the second case the gp instance is reused and filled.

dear sir:


thanku very much ,but ,a new problem appears, when I debugging this program I found the geoCoding’s value is null , the GeoTIFF file is one of Landsat8 TIF data from USGS which used in my program, I changed another GeoTIFF to debug, the geoCoding’s value is null still . I don’t know what trouble with it???

:sunny:
thanku very much ,but ,a new problem appears, when I debugging this program I found the geoCoding’s value is null , the GeoTIFF file is one of Landsat8 TIF data from USGS which used in my program, I changed another GeoTIFF to debug, the geoCoding’s value is null still . I don’t know what trouble with it???

Is this surface reflectance data from USGS? This is not yet supported.
One user found a solution to open it. It is explained in this post


Instead of opening the tiff files directly you should use the *MTL.txt file in your code.
Additionally you might want to use the Landsat8GeoTIFF30m format instead of GeoTIFF

dear sir:

thanks for your patience to answer, I checked the problem that was mentioned “How to open Landsat8 surface…”, the latest Landsat8 files dowloaded from USGS don’t have that problem.

I revised my code like this

but the debug result still show geoCoding is null

I can’t understand your “Instead of opening the tiff files directly you should use the *MTL.txt file in your code.” Like this ???


but it can’t work…

Please forgive me if I have little talent and less learning. and Please forgive my poor grammar.

kristen.

。。。。。。。。。。。。。。。。。。。。。。。@marpet

Maybe the single tif files are not geocoded. The normal Landsat8 tif files have a GeoCoding.
Have you tried opening them in some other application like QGIS?

This might not work because you don’t have all necessary libraries on your classpath. Is this possible?
Try:

ProductReader reader = ProductIO.getProductReader("Landsat8GeoTIFF30m");

If the reader is null you are missing something on the classpath.

But let’s concentrate on the first issue first. This is strange. Actually it should work.

I have Landsat On Demand Data with Surface Reflectance and I cannot open it using MLT file. The folder has band images names like “sr_band1” while in MTL file its “B1”…but it xml file its agian like “sr_band1”.

Maybe this post explains it for you:

Its works but only band 1-7 are loaded. but the aerosol and qualty band do not appeared and loaded. Secondly I thick the metadeta is for level, means for the radiant data for ToA, but here the bands are surface reflectance band so I am little bit confuse how the same Metadata of level1 can be used…

That’s because it is not explicitly supported. But as said in the other thread, we have it on the developemnt plan.