After I convert pixel coordinates to map coordinates, how do I re-plot it in the new map coordinates?

7 ビュー (過去 30 日間)
Hello,
I have a geotiff image file called kodiak.tif
I did the following to extract the latitude and longitude of the first pixel:
info = geotiffinfo('Kodiak.tif');
[x,y] = pix2map(info.RefMatrix, 1, 1);
[lat,lon] = projinv(info, x,y);
how do I reproject all pixels into latitude and longitude values?
And once i have these latitudes and longitudes, how do I plot these values in matlab instead of pixels for my x and y vectors, for example?
Goal: convert all pixel locations to lat and long such that I can overlay other data points(lat, lon) on top of my map.
thanks so much! First time using matlab toolbox, i usually just bust out GMT.
  1 件のコメント
betty bowles
betty bowles 2016 年 5 月 16 日
row and col are vectors or arrays of matching size. The outputs x and y have the same size as row and col. So instead of setting row = 1, set it to your row vector of values, same with col. Look at function, geoshow() to display.

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

回答 (1 件)

Matt Cohen
Matt Cohen 2015 年 9 月 11 日
Hi Marlon,
I understand that you are interested in converting pixel locations from a GEOTIFF image file to latitude and longitude values and overlaying these data points on a map.
The process you have included in the code snippet should be able to accomplish the task of projecting all pixels to (lat, lon) with just some slight modifications.
I = imread('Kodiak.tif');
info = geotiffinfo('Kodiak.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
[rows,cols] = meshgrid(1:height,1:width);
[x,y] = pix2map(info.RefMatrix, rows, cols);
[lat,lon] = projinv(info,x,y);
geoshow(lat,lon,I);
The following portion of your question is a little unclear to me:
"And once i have these latitudes and longitudes, how do I plot these values in matlab instead of pixels for my x and y vectors?"
You were not explicit about how you would like to "plot" the (lat, lon) data, so I have used the "geoshow" function to display the image with the latitude and longitude data. You were also not explicit about the form of your map or how you are displaying your map. Perhaps you are using the function "mapshow". You should be able to overlay the plot from the code snippet above onto a map plot.
I hope this helps!
Matt

Community Treasure Hunt

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

Start Hunting!

Translated by