Point-in-polygon for a large number of points

I’m wondering what might be the most efficient way to determine if a large number of points (O (1 million) are inside or outside the collection (O (10)) of polygons? The latter are not necessarily convex, but there are no holes in them. At the moment I I crop the number of points by comparing their positions with the bounding rectangles, then use this , the method number at the other points, but maybe a faster method?

+5
source share
3 answers

There is an efficient matplotlib function for this: matplotlib.nxutils.points_inside_poly () . The algorithm is documented on this page .

+3
source

Assuming you have axis-oriented bounding boxes, you can sort the list of points by their x coordinate, find places at the list points inside or outside the bounding rectangles with a binary search, and possibly drop a large number of points at once. Repeat for y coordinate. Then continue, as before, from the remaining points. You can triangulate the polygon to speed up the test in the bounding box.

, , (.. , ).

+2

Quadtree " " , .

- O (log n), , . , , " ", "--".

+1

All Articles