1

I have a large set S: List[Polygon] (Shapely Polygons), and a mask: MultiPolygon.
I want to filter out all of the polygons in S that intersect with mask.

I can write: S2 = [p for p in S if not mask.intersects(p)].

However, to speed things up I was wondering if there was a way to do it without the list comprehension and as a single operation so that the internal Shapely/GEOS search may be done more efficiently. Essentially like running a mask.intersection(MultiPolygon(S)) but without the added cost of getting the actual intersections of each sub-polygon (and while maintaining the original input order).
Ideally it would return something like a List[bool] indicating the results per sub-polygon in S.

1 Answer 1

0

[Answering myself after finding the solution - may be of help to others.]

Shapely supports Prepared Geometry Operations where "Shapely geometries can be processed into a state that supports more efficient batches of operations".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.