How to show a .tif file with projected coordinate system in geographic system?

55 views (last 30 days)
Hello guys, i'm finishing an essay which i need to plot some trajectories points(in lat lon) on a map to do some further analysis. I've now downloaded a .tif file in projected coordinate system. I used
[A,R] = readgeoraster(filename);
mapshow(A,R)
and get the same coordinate system like this example: https://ww2.mathworks.cn/help/map/ref/readgeoraster.html
But what i really need is lat lon corrdinate system. like the image in example 5 here: https://www.mathworks.com/help/map/creating-map-displays-with-data-in-projected-coordinate-reference-system.html
This example 5 requires a .jpg file with geographic data whose coordinates are already in latitude and longitude, which of course i don't have one. I only have the .tfw file along with the .tif file.
So i used the following funtions to extract the lat and lon from the .tif file:
filename = 'G:\SA\Data\dop20c_33412_5654.tif';
[A,R] = readgeoraster(filename);
info = geotiffinfo(filename);
[AY, AX, Z]= size (A);
height = info.Height;
width = info.Width;
[rows,cols] = meshgrid(1:height,1:width);
[x,y] = pix2map(info.RefMatrix, rows, cols);
[lat,lon] = projinv(info, x,y);
And then i get two arrays named lat, lon (10000x10000) with the required latitude and longtitude infomation. But now how can i use these info to plot a new image with these lat and lon?
Or maybe there are other funtions that don't actually need these steps but directly plot the image the way i wanted?
Thank you so much for your help!
  2 Comments
Zihan Liu
Zihan Liu on 28 Apr 2020
no the one with lat and lon is what i want. I don't have any color lines.
This is what i get after using mapshow(A,R):

Sign in to comment.

Answers (2)

darova
darova on 29 Apr 2020
As i understood you correctly: you want to have grid line/dots on your image
Here is an example
A = zeros(100); % 2d zero matrix
[X1,X2] = meshgrid(10:20:90, 1:4:99); % grid
ind1 = sub2ind(size(A),X1(:),X2(:)); % horizontal
ind2 = sub2ind(size(A),X2(:),X1(:)); % vertical
A(ind1) = 1;
A(ind2) = 1;
imshow(A)
  3 Comments
darova
darova on 29 Apr 2020
Use Xtick and Xticklabel
xx = 0:20:100;
set(gca,'xtick',xx)
set(gca,'ytick',xx)
s1 = strsplit(sprintf('%dW\n',xx));
s2 = strsplit(sprintf('%dN\n',xx));
set(gca,'xticklabel',s1)
set(gca,'yticklabel',s2)
Zihan Liu
Zihan Liu on 29 Apr 2020
Thanks a lot for your ideas, but i'm sorry it's not directly linked to my problem. It's a relative more complicated case.... I think it requires some funtions from Mapping Toolbox.

Sign in to comment.


Geraldine Maria Palacios Torres
Hi Liu
I am facing the same issue. I cannot display the image in its geographical coordinates
I wonder if you figured it out?

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!