# Finding points inside a geographic region based on Lat/Lon

29 views (last 30 days)
Jorge Young on 25 Aug 2020
Commented: Jorge Young on 27 Aug 2020
For starters, I am a VERY novice MATLAB user.
Is it possible to use a given set of Lat/Lon points and determine if a seperate set falls within that region?
For example I would like to know if Point A falls within a polygon made by points B C D E.
Point A = 33.637 -84.428
Point B = 33.658 -84.439
Point C = 33.658 -84.639
Point D = 33.641 -84.639
Point E = 33.641 -84.439
Thank you in advance for the help.

Shawn on 25 Aug 2020
Jorge,
Your problem is very similar to one I just solved myself thanks to the help on this forum.
In the code below, Blat is a vector of border latitudes and Blon is a vector of border longitudes. For your example, Blat would be a 1x5 vector containing the latitudes of your 5 points. In my code below, the matrix prom_world contains a large set of points with latitudes in column 1 and longitude in column 2.
The Matlab function inpolygon determines what elements of prom_world lie within or on the polygon defined by Blat and Blon. A logical 1 is returned if the point is in or on the boundary and a logical 0 is returned if the point is outside the boundary.
If you want to extract a matrix of point that are in or on the boundary, compute the vector of indicies of INON which are non-zero and then use that info to pull the data out as shown.
The Matlab help for inpolygon probably explains this better than I have.
% Find points IN or ON the boundary
[IN ON] = inpolygon(prom_world(:,1),prom_world(:,2),Blat,Blon);
%
% Combine IN and ON
INON = IN | ON;
%
% Find indicies of non-zero INON
idx = find(INON(:));
%
% Extract data from prom_world
Prominence = prom_world(idx,:);
Jorge Young on 27 Aug 2020
thanks again for your help with this.