Identify polygons enclosing a point in a shapefile

15 views (last 30 days)
I have a shapefile containing many polygons that I read in Matlab. Now, I would like to identify which of the polygons in the shapefile interestc/enclose specific points. I have the x and y coordinates of the points. I'm trying to do something like the 'select by location' feature in arcmap.

Accepted Answer

KSSV
KSSV on 16 Sep 2020
Edited: KSSV on 16 Sep 2020
To get the locations/ points lying inside the polygon use inpolygon.
To get the nearest points close to a given point use knnsearch.
  7 Comments
KSSV
KSSV on 16 Sep 2020
load("Sample.mat") ;
plot(lon,lat,'*r')
hold on
x = [Popshp(:).X]' ;
y = [Popshp(:).Y]' ;
L2 = [lon lat] ;
% Get the Intersection polygon
P = zeros([],1);
count = 0 ;
for i = 1:length(Popshp)
L1 = [[Popshp(i).X]' [Popshp(i).Y]'] ;
p = InterX(L1',L2')
if ~isempty(p)
count = count+1 ;
P(count) = i ;
plot(L1(:,1),L1(:,2),'b')
end
end
Download InterX from the link given in the answer.
Maria Czarina Tierra
Maria Czarina Tierra on 16 Sep 2020
This works well, Now I can extract data from the indices of the polygons. Thanks a lot!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!