Geotiffread & getting latlon info
Mostra commenti meno recenti
Hello,
I am using EO-1 Hyperion data (hyperspectral) as a geotiff image data of Agatti Islands, Lakshadweep, India. I used geotiffread to read the image data.. using [img, RfrncMtrx, BndgBx]=geotiffread(phileName{:}); When I want to convert from the row/col to lat/lon by using pix2latlon, I get the numbers in map-scale. (Actually the values in the reference matrix are also huge!!!???). The BndgBx=[179100, 1155270; 206430, 1244100]..
Kindly let me know where I am going wrong?
Cheers
Raghu
3 Commenti
Luca Brocca
il 23 Mar 2017
Modificato: Walter Roberson
il 26 Mar 2018
info = geotiffinfo(namefile);
[x,y]=pixcenters(info);
Hyunglok Kim
il 19 Ott 2017
Luka's answer is the best.
Nirajan Luintel
il 4 Apr 2018
I used to calculate from boundary box. Its a lot easier. Thanks a lot
Risposta accettata
Più risposte (3)
Reema Alhassan
il 4 Giu 2018
1 voto
hello, when I'm using projinv(info, y,x); function I'm getting an error says the GeoTIFF structure PROJ can't be used with the functions PROJFWD or PROJINV if you could help me please ..
thank you
7 Commenti
Emily T. Griffiths
il 10 Ago 2020
I got to the bottom of this post, only to have the same question as Reema...
Sophia Barth
il 20 Ago 2020
Had anyone found a solution for this problem yet? Thanks in advance.
Walter Roberson
il 20 Ago 2020
Which release are you using?
What happens if you test with
info = geotiffinfo('boston.tif');
[x,y] = pix2map(info.RefMatrix, 1, 1);
[lat,lon] = projinv(info, x,y)
Sophia Barth
il 20 Ago 2020
Thanks for the prompt reply, I use R2020a.
I exported my image from Google Earth Engine and its in a projected coordinate system ('ModelTypeProjected').
When I use this code for my image the following comes up:
Error using proj2gtif (line 17)
The GeoTIFF structure PROJ cannot be used with functions PROJFWD or PROJINV.
Error in projaccess (line 40)
gtif = proj2gtif(proj);
Error in projinv (line 73)
[lat, lon] = projaccess('inv', proj, x, y);
Error in mathworksanswer (line 6)
[lat,lon] = projinv(info, x,y)
Walter Roberson
il 20 Ago 2020
Can you post code to fetch the data so we can be sure we are working with the same structure?
Sophia Barth
il 21 Ago 2020
This is the code i used to export the image:
If you have an account for Google Earth Engine it should work when you click on the link. If the link somehow doesnt work this is the code:
/**
* Function to mask clouds using the Sentinel-2 QA band
* @param {ee.Image} image Sentinel-2 image
* @return {ee.Image} cloud masked Sentinel-2 image
*/
function maskS2clouds(image) {
var qa = image.select('QA60');
// Bits 10 and 11 are clouds and cirrus, respectively.
var cloudBitMask = 1 << 10;
var cirrusBitMask = 1 << 11;
// Both flags should be set to zero, indicating clear conditions.
var mask = qa.bitwiseAnd(cloudBitMask).eq(0)
.and(qa.bitwiseAnd(cirrusBitMask).eq(0));
return image.updateMask(mask).divide(10000);
}
//Filter images
var dataset = ee.ImageCollection('COPERNICUS/S2')
.filterBounds(geometry5)
//.filterDate('2016-07-23','2016-07-27')
.filterDate('2020-07-01','2020-07-30')
.filterMetadata('CLOUDY_PIXEL_PERCENTAGE','less_than',20)
.map(maskS2clouds)
.median()
.select(['B12','B8','B4'])
//visualization parameter
var SWIRVis = {
min: 0.0,
max: 0.3,
bands: ['B12', 'B8', 'B4'],
};
//output image, add to map
var final_image = dataset.clip(geometry5)
Map.addLayer(final_image,SWIRVis,'Image2016-06');
//Map.addLayer(final_image,VisParam,'image201607_1_fire');
//Export the image, specifying scale and region
Export.image.toDrive({
image: final_image,
description: 'image202007_swir_small',
scale: 20,
crs: 'EPSG:3857',
region: geometry5
});
I hope that helps, thanks again!
Sophia Barth
il 21 Ago 2020
As a next step I dowloaded the image from Googe Drive and used the follwoing code as you suggested:
info = geotiffinfo('image202007_swir_small.tif');
[x,y] = pix2map(info.RefMatrix, 1, 1);
[lat,lon] = projinv(info, x,y)
Ran Zask
il 24 Mar 2018
0 voti
I think it should be [lat,lon] = projinv(info, x,y);
1 Commento
Qishun Ran
il 19 Giu 2019
I think you are right, it should be [lat,lon] = projinv(info, x,y); and
it should be [rows,cols] = meshgrid(1:width,1:height);
Andres Rey Sanchez
il 26 Lug 2021
Some corrections are needed to the answers above. To get the correct matrices of coordinates (lat, lon) from your geotiff the code should be:
info = geotiffinfo('boston.tif');
height = info.Height; % Integer indicating the height of the image in pixels
width = info.Width; % Integer indicating the width of the image in pixels
[cols,rows] = meshgrid(1:width,1:height);
[x,y] = pix2map(info.RefMatrix, rows, cols);
[lat,lon] = projinv(info, x,y);
Categorie
Scopri di più su Coordinate Reference Systems in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!