# inpolygon counting points within holes

4 visualizaciones (últimos 30 días)
Alan el 31 de Jul. de 2024
Comentada: Alan el 31 de Jul. de 2024
Hello,
I am attempting to find whether points fall within areas on a map. I've decided to do this using inpolygon. I've been having trouble with areas with holes and I have no idea why. Here is an example:
test2=polyshape(test)
test2 =
polyshape with properties: Vertices: [159x2 double] NumRegions: 1 NumHoles: 1
plot(test2)
As we can see from this shape, the point (-75.6,40.51) falls within the hole of this shape. Therefore, inpolygon should return 0. Let's test this:
inpolygon(-75.6,40.51,test(:,1),test(:,2))
ans = logical
1
I really don't understand why this is happening, as my example here is almost identical to the example given in the literature for inpolygon, just on a larger scale. I thought it had something to do with the NaNs I inserted to split between the coordinates of the hole and the actual shape, but the example in the literature does the same thing, so I don't think its that. I'm not sure what else it could be, so could someone please help me out?
Thanks
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

Aditya el 31 de Jul. de 2024
Hi Alan,
It seems that the data "test" contains NaN values somewhere which is creating the issue.
you could either use:
isInside = isinterior(test2, -75.6, 40.51);
or you can modify your code to use test2 directly:
inpolygon(-75.6,40.51,test2.Vertices(:,1),test2.Vertices(:,2))
Refer to the below MATLAB documentation to read more about "isinterior" function:
##### 1 comentarioMostrar -1 comentarios más antiguosOcultar -1 comentarios más antiguos
Alan el 31 de Jul. de 2024
The NaN aren't causing the issue here, as the 2nd to last example given in this link show the NaNs working with holes. However, I didn't realize that isinterior works with polyshapes, so this fixed my issue, thanks

Iniciar sesión para comentar.

### Categorías

Más información sobre Elementary Polygons en Help Center y File Exchange.

### Community Treasure Hunt

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

Start Hunting!

Translated by