MATLAB Answers

0

How to find points inside a country border

Asked by Thao Linh Tran on 14 Jan 2019
Latest activity Commented on by Thao Linh Tran on 15 Jan 2019
Hi everyone, I have a 2 dimension matrix containing lat, lon of multiple points. I would like to ask whether there is any way in Matlab to define which points are inside the border of a specified country. Any suggestion would be greatly appreciated!

  0 Comments

Sign in to comment.

Products


Release

R2018b

2 Answers

Answer by Akira Agata
on 15 Jan 2019
 Accepted Answer

How abou the following?
(In this script, I have used shape file provided in http://thematicmapping.org/downloads/world_borders.php)
% Load shape file of country border
S = shaperead('TM_WORLD_BORDERS_SIMPL-0.3.shp');
S = struct2table(S);
% Target lat and lon (e.g Tokyo)
lat = 35.7;
lon = 139.7;
% Find which country contains (lat,lon)
idx = cellfun(@(X,Y) inpolygon(lon,lat,X,Y),S.X, S.Y);
% Show the result
disp(S.NAME(idx))
>> disp(S.NAME(idx))
'Japan'

  1 Comment

Great! I got it, many thanks for your help.

Sign in to comment.


Answer by KSSV
on 15 Jan 2019

Read about inpolygon

  1 Comment

Thank you for your suggestion!

Sign in to comment.