Finding points inside a geographic region based on Lat/Lon

26 次查看(过去 30 天)
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
Shawn 2020-8-25
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,:);
  3 个评论
Shawn
Shawn 2020-8-27
When I was searching around for some help, I ran across a something either here in the community or perhaps over in the File Exchange section about a MEX code that was faster than inpolygon. Didn't save the link unfortunately.
But another Matlab speedup trick is to predefine the size of any verctors or matricies in your code. If for example you know your input data set contains N rows, then the output of inpolygon will also contain N elements filled with either logical 1 or logical 0. By predefining the vectors IN and ON in the example code above, it should help speed things up by skipping the need for Matlab to dynamically size the vectors during run time.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by