[SciPy-user] efficient "inside polygon" test for an array??

John Hunter jdh2358@gmail....
Mon Feb 4 10:15:09 CST 2008

On Feb 4, 2008 9:56 AM, Eric Emsellem <emsellem@obs.univ-lyon1.fr> wrote:
> Hi
> I have a polygon (defined by 4 vertices) and I wish to have an efficient way of
> selecting the points which are inside this polygon.
> So I would like something like:
> selection = pointsInPolygon(x,y,poly)

Where  points is a sequence of x,y points and verts is a sequence of
x,y vertices of a poygon

  >>> import matplotlib.nxutils as nxutils
  >>> mask = nxutils.points_inside_poly(points, verts)

This is implemented in C using an efficient algorithm so should work
well for you.

> where x and y are numpy arrays and poly the 2xN array defining the vertices of
> the polygons.
> I have the code for single points. But "vectorizing" it make this routine VERY
> slow and not exploitable (I have to do this for MANY polygons and x,y arrays
> which are big).
> Do you have something like that in scipy (or somewhere else)?
> thanks in advance!
> Eric
> _______________________________________________
> SciPy-user mailing list
> SciPy-user@scipy.org
> http://projects.scipy.org/mailman/listinfo/scipy-user

More information about the SciPy-user mailing list