bug: intersect method of gridintersect class not working
I am trying to determine which model cells in a single layer intesect a single multi-polygon geometry object. This is my code:
from flopy.utils import GridIntersect ix = GridIntersect(mg, method='structured') intersects = ix.intersect(extent.geometry[0])
It's been hours and this is still running for a fairly small, single-layer structured grid. What is wrong with the method? Why is it sooo slow?
@aestrad-intera hard to say without seeing your grid. any way you could share it? you might try intersecting shapes separately instead of the multipolygon all at once. as stated in the GridIntersect docstring that can be faster if your multipolygon is big.
do you see any performance difference without method='structured'?
@aestrad-intera, seconding what @wpbonelli has mentioned. Try using the explode function on your multipolygon to create individual polygons and use those to see if there is improvement.
I'd also recommend changing the method parameter to "vertex"
I tried both suggestions and this is still not working, it is running forever. Any thoughts as to why this is so slow?
On Thu, Sep 18, 2025 at 1:05 PM Joshua Larsen @.***> wrote:
jlarsen-usgs left a comment (modflowpy/flopy#2603) https://github.com/modflowpy/flopy/issues/2603#issuecomment-3308874547
@aestrad-intera https://github.com/aestrad-intera, seconding what @wpbonelli https://github.com/wpbonelli has mentioned. Try using the explode function on your multipolygon to create individual polygons and use those to see if there is improvement.
I'd also recommend changing the method parameter to "vertex"
— Reply to this email directly, view it on GitHub https://github.com/modflowpy/flopy/issues/2603#issuecomment-3308874547, or unsubscribe https://github.com/notifications/unsubscribe-auth/A52MYOP6GPZFVKGYKBFZAS33TLYAFAVCNFSM6AAAAACG4MN3E6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTGMBYHA3TINJUG4 . You are receiving this because you were mentioned.Message ID: @.***>
Can you zip and send an example over. It's not really possible to debug this any further without a minimal working example.
Minimal example includes: Shapefile/geometry that you are intersecting DIS file
As Joshua mentioned, I can take a look if you can provide us with a grid and a shapefile. I can use the opportunity to remove the deprecated methods and clean up the GridIntersect class.
Note that in the current version of flopy method="structured" is essentially deprecated and method="vertex"` is preferred.
If you are on an old version of flopy, you could try passing method="vertex" and see if that speeds up the operation? In older versions of flopy the method was derived from the modelgrid object. In the latest versions of flopy, the method is always set to "vertex" if I'm not mistaken.
may be addressed in #2646