How to show a .tif file with projected coordinate system in geographic system?
35 views (last 30 days)
Show older comments
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
Answers (2)
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
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)
Geraldine Maria Palacios Torres
on 28 Oct 2021
Hi Liu
I am facing the same issue. I cannot display the image in its geographical coordinates
I wonder if you figured it out?
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!