Skip to content Skip to sidebar Skip to footer

Is There Way To Optimize Speed Of Shapely.geometry.shape.contains(a_point) Call?

We are using a shapely library to check that some random point is not in some prohibited areas stored in a shape file. with fiona.open(path) as source: geometry = get_exclusive

Solution 1:

Thank for the @iant point to use a spatial indexes.

My shapefile was a single MultiPoligon with a lot of points, makes .contains() are really slow.

I solved the issue by splitting it into smaller shapes and use Rtree index.

  1. To split shapefile I used QGIS, as it descrived here - https://gis.stackexchange.com/a/23694/65569

  2. The core idea how to use RTree in python is here - https://gis.stackexchange.com/a/144764/65569

In total this gaves me 1000x speed-up for .contains() lookups!

Post a Comment for "Is There Way To Optimize Speed Of Shapely.geometry.shape.contains(a_point) Call?"