
How do I add an image on a map?
3 views (last 30 days)
Show older comments
MathWorks Support Team
on 6 Sep 2019
Edited: MathWorks Support Team
on 22 May 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
Accepted Answer
MathWorks Support Team
on 22 May 2020
Edited: MathWorks Support Team
on 22 May 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 Comments
More Answers (0)
See Also
Categories
Find more on Basic Display in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!