필터 지우기
필터 지우기

Refitting points to nearest polygon

조회 수: 3 (최근 30일)
Abhishek Varghese
Abhishek Varghese 2018년 4월 4일
댓글: Steven Lord 2018년 4월 4일
Hey everyone!
Let's say I have a couple of 2D polygons, and a set of coordinates.
I'm trying to count the number of points that fall in each polygon, and I'm already using inpolygon to do this.
However, I notice there are a few points that are not inside the polygons, but are near it. This is likely due to the inaccuracies that rise with observations.
I need to have these points be counted as part of their nearest polygon, but I don't know how to!
Cheers.

채택된 답변

Steven Lord
Steven Lord 2018년 4월 4일
Are you representing your polygons as a polyshape array? polyshape was introduced in release R2017b. If you are, you could try using the buffer-based approach described in Loren's blog combined with the isinterior function.
  댓글 수: 2
Abhishek Varghese
Abhishek Varghese 2018년 4월 4일
Hi Steven, thanks for your answer, I think it's in the right direction. However, an issue would be that the buffer would then include points from neighboring polygons resulting in overlap. I'm just interested in the points that don't 'belong' to any polygon.
Steven Lord
Steven Lord 2018년 4월 4일
I haven't tried this, but this might work. For each of the regions in your polyshape, buffer it and see if the point isinterior.
  • If it's not inside any of the buffered regions, it's not in your collection of polygons.
  • If it's inside exactly one of the buffered regions, it's either inside that region or "close enough".
  • If it's inside two or more of the buffered regions, and you want to know which one it's closest to, nearestvertex may help you, or you can simply shrink the buffer size until it's in only one of the buffered regions.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Elementary Polygons에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by