Skip to content

feature: faster and better point intersection in GridIntersect #2650

@dbrakenhoff

Description

@dbrakenhoff

Is your feature request related to a problem? Please describe.

GridIntersect.intersect() is slow for points because it has to perform an intersection between the MultiPoint and each of the gridcells within the spatial query that limits the search space. And GridIntersect.intersects() doesn't really return a useful result, since it only returns the addresses of touched cells, and not a link between the input points and their location in the grid.

Describe the solution you'd like
For points it would be more useful if the intersects() method would return an array of len(points) with the address of the grid cell each point intersects with.

import shapely
from flopy.utils.geospatial_utils import GeoSpatialUtil
from flopy.utils import GridIntersect

grid = ... # some grid

x = np.arange(10)
y = np.arange(10)
pts = shapely.points(x, y)

gi = GridIntersect(grid)
gi.intersects(pts)  # --> result with len(npts) with cellids, or nan if outside of grid

Additional context
This change will introduce new behavior for arrays of geometries, which were not really supported before. I'm worried it might make the intersect methods a bit more confusing to navigate since the result depends on the input type...

  • intersects():
    • MultiPoint --> Cellids containing 1 or more points
    • array of points --> cellid per point
  • intersect():
    • MultiPoint --> Points grouped per cell
    • array of points --> cellid per point (aggregation left to the user?)

So I'd welcome any suggestions on how to support the arrays, without making it too confusing? Perhaps a separate array-based method?

This is related to #2649.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions