Plot Geo-Locations on Worldmap with Matlab
Asked Answered
K

3

6

I am trying to mark a few thousands of geo-locations on the world-map with matlab. I have the latitudes and longitudes of those locations. Is there any good way to do this? Thanks.

Kosiur answered 25/7, 2012 at 17:44 Comment(0)
M
8

Here is an example that doesn't require any toolbox.

First we create a function that converts longitute/latitude locations using the Mercator projection.

function [x,y] = mercatorProjection(lon, lat, width, height)
    x = mod((lon+180)*width/360, width) ;
    y = height/2 - log(tan((lat+90)*pi/360))*width/(2*pi);
end

We create some locations:

% GPS positions (latitude,longitude) of some markers
data = [
    -22.976730, - 43.195080 ;
     55.756950,   37.614975 ;
     33.605381, -  7.631940 ;
     35.670479,  139.740921 ;
     51.506325, -  0.127144 ;
     40.714550, - 74.007124 ;
    -33.869629,  151.206955 ;
    -26.204944,   28.040035 ;
     37.777125, -122.419644 ;
     30.083740,   31.255360 ;
      6.439180,    3.423480
];
labels = {
    'Rio de Janeiro'
    'Moscow'
    'Casablanca'
    'Tokyo'
    'London'
    'New York'
    'Sydney'
    'Johannesburg'
    'San Francisco'
    'Cairo'
    'Lagos'
};

Next we load a map from Wikipedia, apply the projection and overlay the markers:

% world map in Mercator projection
fname = 'https://upload.wikimedia.org/wikipedia/commons/thumb/7/74/Mercator-projection.jpg/773px-Mercator-projection.jpg';
img = imread(fname);
[imgH,imgW,~] = size(img);

% Mercator projection
[x,y] = mercatorProjection(data(:,2), data(:,1), imgW, imgH);

% plot markers on map
imshow(img, 'InitialMag',100, 'Border','tight'), hold on
plot(x,y, 'bo', 'MarkerSize',10, 'LineWidth',3)
text(x, y, labels, 'Color','w', 'VerticalAlign','bottom', 'HorizontalAlign','right')
hold off

output

Mcfadden answered 25/7, 2012 at 21:26 Comment(0)
D
2

Great way to plot the world!

You just have to change the following:

imshow(I, 'InitialMag',100, 'Border','tight'), hold on

into

imshow(img, 'InitialMag',100, 'Border','tight'), hold on
Decennium answered 26/11, 2012 at 22:33 Comment(1)
I believe this is not an answer, it should be an edit to @Mcfadden 's answer.Monge
S
2

Amro's answer worked for me, but I had to do some changes.

I'm using Matlab 7.9 and imshow is part of the Image Processing Toolbox. In order to show the map without using the imshow function, I replaced this line:

imshow(img, 'InitialMag',100, 'Border','tight')

With this one:

image(img)

And it worked.

Sabin answered 3/12, 2013 at 20:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.