Identify polygons enclosing a point in a shapefile
15 views (last 30 days)
Show older comments
Maria Czarina Tierra
on 16 Sep 2020
Commented: Maria Czarina Tierra
on 16 Sep 2020
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.
0 Comments
Accepted Answer
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 intersection points use InterX. https://in.mathworks.com/matlabcentral/fileexchange/22441-curve-intersections
To get the nearest points close to a given point use knnsearch.
Also refer this link: https://in.mathworks.com/matlabcentral/answers/522591-fill-inside-a-polygon-with-a-color
7 Comments
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.
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!