extracting lat/lon from tif file using matlab

34 ビュー (過去 30 日間)
Seyedeh Fardis
Seyedeh Fardis 2023 年 10 月 24 日
コメント済み: Cris LaPierre 2023 年 10 月 25 日
I have a tif file with a map of locations that has data. I want the lat/lon of that locations using matlab.
I ploted that in matlab using this code
[tifImage, R] = geotiffread('NA_CONUS_border.tif');
>> tifImageDouble = double(tifImage);
>> figure;
mapshow(tifImageDouble, R);
title('Georeferenced TIFF Image');
locations with data has [R,G,B]=[1 1 1].
I want to Convert pixel coordinates to geographic coordinates [lat lon].
does anyone have any idea how to do that?
  5 件のコメント
Dyuman Joshi
Dyuman Joshi 2023 年 10 月 24 日
@Seyedeh Fardis Please attach the tif file (as asked earlier as well).
And mention which version of MATLAB you are using.
Seyedeh Fardis
Seyedeh Fardis 2023 年 10 月 24 日
I'm using R2020a .

サインインしてコメントする。

回答 (2 件)

Cris LaPierre
Cris LaPierre 2023 年 10 月 24 日
編集済み: Cris LaPierre 2023 年 10 月 24 日
See this answer, which was updated in 2022.
I will mention that I did have to set the 'OutputType' to get it to work.
unzip("NA_CONUS_border.tif")
% Read image file using readgeoraster
fname = "NA_CONUS_border.tif";
[A,R] = readgeoraster(fname,"OutputType","double");
mapshow(A,R)
% Create grid of X,Y values
[x,y] = worldGrid(R);
% Convert grid of X,Y values to latitude/longitude
[lat,lon] = projinv(R.ProjectedCRS,x,y);
% Extract lat/lon locations of white line
NA_lat = lat(A==1);
NA_lon = lon(A==1);
% Plot extracted latitude/longitude on geographic axes
figure
geoscatter(NA_lat,NA_lon,'.')
geobasemap satellite
title("geographic axes")
  2 件のコメント
Seyedeh Fardis
Seyedeh Fardis 2023 年 10 月 25 日
Thank you for that! does tif file contain data as well? I have a dataset and I want to see which data is for which node. I'm not sure if that data is available is tif file as well. if yes, how I can load then in matlab in ordeer of lat/lon?
Cris LaPierre
Cris LaPierre 2023 年 10 月 25 日
You could check what information is available using geotiffinfo

サインインしてコメントする。


DGM
DGM 2023 年 10 月 24 日
I never really use mapping stuff, so take this with a grain of salt.
fname = 'NA_CONUS_border.tif';
[tifImage, R] = geotiffread(fname);
S = geotiffinfo(fname);
tifImage = double(tifImage); % contains unique values [0 1 2] (a label array??)
mapshow(tifImage, R);
title('Georeferenced TIFF Image');
% get pixels that are exactly 1
% this ignores the fact that pixels >1 will also be white.
% adjust the test accordingly
[row col] = find(tifImage == 1);
% convert to lat/lon
[x y] = pix2map(S.RefMatrix,row,col);
[lat lon] = projinv(S,x,y);
  1 件のコメント
Seyedeh Fardis
Seyedeh Fardis 2023 年 10 月 25 日
Thank you for that! does tif file contain data as well? I have a dataset and I want to see which data is for which node. I'm not sure if that data is available is tif file as well. if yes, how I can load then in matlab in ordeer of lat/lon?

サインインしてコメントする。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by