Analyze and Visualize Geographic Information with MATLAB

Any data which you refer to in terms of real-world coordinates that are longitude and latitude (projected) or in unprojected map, is called georeferenced data. Georeferenced data is also known as spatial, geographical or geospatial data.

Type of Geo Data

There are two types of geo data vector geo data and raster geo data.

Vector Geo data

It consists of latitude & longitude(pairs) in a sequence or projected (x,y) coordinate pairs. To identify different objects or places or things, there must be break in data otherwise it will be considered as a single entity. For example if I have to locate two neighbour countries on map, there must be a space or a break in data to identify both countries exclusively. Vector data can be edges or coastline or points or polygon. As given below figure

Edges, polygon, Points

Raster Geodata

Data will be in a matrix form, in which each row-and-column element corresponds to a geographical area or geographical information as patch( filled), along with that there will be a reference to locate that matrix or image data on geo coordinate system.

It can be two types

  1. Digital Elevation that is topographical map with geographical reference.
  2. Remotely sensed Images with geographical reference.
Digital Elevation and Remotely Sensed Image Data (I used above images from MATLAB documentation to explain differences)

Geographic Data Import and Export / Standard File Formats in MATLAB

Raster Data:- As given in Mapping Toolbox of MATLAB
Vector Data:- As given in Mapping Toolbox of MATLAB

2D and 3D Map Displays

Before map Display we are to set projection on axes, there are more than 65 projections available in MATLAB

Map Projections

There are three main families

Cylindrical Projections

axesm ('balthsrt', 'Frame', 'on', 'Grid', 'on')
 plotm(coastlat,coastlon)
When you unwrap it will look like rectangular

Conic Projections

axesm ('eqdconic', 'Frame', 'on', 'Grid', 'on');
plotm(coastlat,coastlon)
When you unwrap it will look like semi-circular

Azimuthal Projections

axesm ('gnomonic', 'Frame', 'on', 'Grid', 'on');
 plotm(coastlat,coastlon)
When you unwrap it will look like circular

You can use your custom axis too with axesm by giving latitude and longitude limits. Or you can use worldmap command to get coordinate of a specific country.

worldmap India
India coordinate

2D Map Display

geoshow command is used for projected map and mapshow command is used for unprojected map

worldmap asia
geoshow('landareas.shp','FaceColor',[0.5 1.0 0.5]) 
Asia map
R = geotiffinfo('year1.tif'); 
[A, R] = geotiffread('year1.tif'); %  A is a matrix, R is a Geo reference
geoshow(A,R)
Aerosol Satellite Image

3D Map Display

Define projection

figure
ax = axesm('globe');
ax.Clipping = 'off';
gridm('GLineStyle','-','Gcolor',[.1 .4 .4],'Galtitude',.03)

load coast data and plot it as red

load coastlines
plot3m(coastlat,coastlon,.01,'r')
view(3)
axis off
zoom(1.5)

Create matrix and Geo reference

matrix = ones(180,360);
reference = georefcells([-90 90],[0 360],size(base));

Plot above created raster data

copperColor = [0.4 0.6 0.8];
geoshow(matrix,reference,'FaceColor', [0.4 0.6 0.7] )
camlight headlight
material([.5 .6 .2])

Thematic Maps

Thematic maps are spatial variation of geographic distributions. These distributions may be physical phenomena such as atmosphere or ozone data or human data, such as census, diseases or agriculture data.

Get Image information and plot it

clear
R = geotiffinfo('year1.tif'); 
[A, Rr] = geotiffread('year1.tif');
geoshow(A,Rr)
It is climate data

Get x,y locations of pixels and plot surface

[x,y] = pixcenters(R); 
 h=surf(x,y,A)
view([-30,30])
%% set(h,'EdgeColor','none')
material([.5 .8 .1])
shading interp
% axis equal;
% demcmap(A)
lighting gouraud
view(40,56)
colorbar
Based on color you can identify where values are low and high
After rotation

Data Representation on MAP

You can use MATLAB functions, plotm, mapshow, geoshow, geobubble, or geoplot.

If you want to display data on live map ,you can use wmmarker

Visualization of Geo Data

Below code shows how you can plot different size of circles using geoplot

load coastlines.mat
a=1:numel(coastlat);
aa=rescale(a(1:length(coastlon)),1,20);
%geobasemap(colorterrain')
for i=1:100:length(coastlat)
geoplot(coastlat(i),coastlon(i),'o','MarkerSize',aa(i),'MarkerFaceColor','red')
hold on
text(coastlat(i),coastlon(i),string(aa(i')))
end
hold off
geobasemap('colorterrain')

It is geoplot, you can try geobubble

Analysis and Visualization of Temperature Data

My data looks like as given below

Total places are 545

Read Table

TempData=readtable("TempDataofIndia.xlsx");
sum(ismissing(TempData.Temp))
temp=TempData.Temp;

Fill Missing Temperature Data

You can use live script capability to fill missing data, to know click here for my previous post.

% Fill missing data
[CLeanedTemp,missingIndices] = fillmissing(temp,'spline');

% Display results
clf
plot(CLeanedTemp,'Color',[0 114 189]/255,'LineWidth',1.5,...
    'DisplayName','Cleaned data')
hold on

% Plot filled missing entries
plot(find(missingIndices),CLeanedTemp(missingIndices),'.','MarkerSize',12,...
    'Color',[217 83 25]/255,'DisplayName','Filled missing entries')
title(['Number of filled missing entries: ' num2str(nnz(missingIndices))])

hold off
legend
clear missingIndices
close all

Read Latitude and Longitude from table

Lat=TempData.Lat;
Lon=TempData.Lon;

Show India Map

To show states in different colors makesymbolspec function is used.

ax = worldmap('INDIA');
load coastlines
geoshow(ax, coastlat, coastlon,...
'DisplayType', 'polygon', 'FaceColor', [.45 .60 .30])
states = shaperead('INDIA', 'UseGeoCoords', true);
faceColors = makesymbolspec('Patch',...
    {'INDEX', [1 numel(states)], 'FaceColor', ...
    polcmap(numel(states))}); % NOTE - colors are random
geoshow(ax, states, 'DisplayType', 'polygon', ...
  'SymbolSpec', faceColors)
India Map

Show Places on Map As points

To display text data on map you can use textm, but in this case non-geographic text function is used.

geoshow(Lat, Lon,...
    'DisplayType', 'point',...
    'Marker', 'o',...
    'MarkerEdgeColor', 'r',...
    'MarkerFaceColor', 'r',...
    'MarkerSize', 3)

h1=text(-1.5120*10^6,4.7747*10^6,'District');
h2=text(-1.4969*10^6,4.6164*10^6,'Click on red point to know temperature');
All places are shown as red

Create Interactive app:- Click to know Temperature

while 1
    
    [selected_lat,selected_lon] = inputm(1)
   
    
    if isempty(selected_lat)
        break % User typed ENTER
    end
    d = distance(Lat, Lon, selected_lat, selected_lon);
    k = find(d == min(d(:)),1);

    geoshow(Lat(k), Lon(k), ...
        'DisplayType', 'point', ...
        'Marker', 'o', ...
        'MarkerEdgeColor', 'k', ...
        'MarkerFaceColor', 'y', ...
        'MarkerSize', 3)
    h1.String = {[TempData.District{k}]};
    h2.String = num2str([CLeanedTemp(k)],'%10.2f');
         
end
When you click on red dot, it will display place and respective temperature

Webmap

You can display data on live map using webmap

wmmarker(Lat(100:120),Lon(100:120),'FeatureName',string(CLeanedTemp(100:120))) % plot temp 100 to 120 idx
Display data on Webmap

Click here for recorded webinar to learn analysis and visulization of geodata

15 thoughts on “Analyze and Visualize Geographic Information with MATLAB”

  1. Hi! I simply would like to give you a big thumbs up for your excellent info you have right here on this post. I am coming back to your blog for more soon.

  2. Hello! I’m at work browsing your blog from my
    phone! Just wanted to say I love reading through your blog and look forward to all your posts!

    Keep up the superb work!

  3. Hi there to every one, it’s really a pleasant for me to go to see this website, it contains important
    Information.

  4. whoah this blog is wonderful i really like reading your articles.

    Stay up the good work! You know, a lot of people are looking round for this information, you can help them
    greatly.

  5. Hello there! This is my first comment here so I just wanted to give a quick shout
    out and say I really enjoy reading through your posts. Can you
    recommend any other blogs/websites/forums that cover the same topics?
    Thank you so much!

  6. Asking questions are genuinely fastidious thing in case you are not understanding
    anything completely, except this article provides pleasant understanding yet.

Leave a Reply

Your email address will not be published.