How do I add an image on a map?
25 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
MathWorks Support Team
am 6 Sep. 2019
Bearbeitet: MathWorks Support Team
am 22 Mai 2020
I have a map on a figure. For example:
worldmap([27 28.5],[127.5 129])
How do I add an image at the range:
lat: 28~28.25
lon: 128~128.25
Akzeptierte Antwort
MathWorks Support Team
am 22 Mai 2020
Bearbeitet: MathWorks Support Team
am 22 Mai 2020
First, you need the projection method.
Then you can use the projection method information to convert the (lat,lon) coordinate on the map to (x,y) coordinate on the figure.
Lastly, you can use the (x,y) coordinate information to add the image on the figure.
Please see the follow sample code:
%%create a map
worldmap([27 28.5],[127.5 129])
% get the default projection method
mstruct=gcm
% the map projection method is 'eqdconic'
% check these websites for the project method:
% https://www.mathworks.com/help/map/summary-and-guide-to-projections.html
% https://www.mathworks.com/help/map/eqdconic.html
% By using this projection information, you can convert (lat,lon) to (x,y)
% on the figure
myLat = 28;
myLon = 128;
[x, y] = mfwdtran(mstruct,myLat,myLon);
scatter(x,y,'ro')
hold on
%%image
eLat = 28;
eLong = 128;
sizeDeg = 0.25;
img = imread('peppers.png');
latlim=[eLat eLat+sizeDeg];
lonlim=[eLong eLong+sizeDeg];
% show the frame of the image, you can skip this step
[xlim, ylim] = mfwdtran(mstruct,latlim,lonlim);
plot([xlim(1) xlim(2) xlim(2) xlim(1) xlim(1)],[ylim(1) ylim(1) ylim(2) ylim(2) ylim(1)],'y-')
% show the image
R = maprefcells(xlim,ylim,size(img(:,:,1)));
mapshow(img,R)
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Image Data Workflows finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!