feat(GridIntersect): add optional kwarg to .intersect() to keep all c…#1214
feat(GridIntersect): add optional kwarg to .intersect() to keep all c…#1214mkennard-aquaveo wants to merge 1 commit into
Conversation
…ells with identical vertices Add "keep_stacked_cells" kwarg to GridIntersect.intersect() which is used to prevent removal of cells from the intersection results which have identical vertices as a cell already included in the results. This kwarg is only used when intersecting using shapely, and is needed when dealing with a DISU grid which doesn't have layers. With DIS and DISV, the intersection results include cellids which have the layer number (either LAY, ROW, COL, or LAY, CELL2D) so cells above or below the intersected cell can be easily found just be changing the layer number. But DISU cellids do not include the layer so it is not at all easy to find cells above or below the intersected cell. Thus having this kwarg which keeps all the cells in the results is needed.
Codecov Report
@@ Coverage Diff @@
## develop #1214 +/- ##
=============================================
+ Coverage 74.226% 75.391% +1.164%
=============================================
Files 230 226 -4
Lines 50192 49418 -774
=============================================
+ Hits 37256 37257 +1
+ Misses 12936 12161 -775
|
dbrakenhoff
left a comment
There was a problem hiding this comment.
Thanks for submitting your proposed changes. I added a few comments for you to take a look at.
I think we need to think of a better name for the option, because keep_stacked_cells doesn't quite capture the full behavior. If you set the option to True, points or linestrings on the boundary between two cells will result in 2 intersection results (even if there are no stacked cells). So maybe keep_all_intersections, return_all_intersections, ...? I do think it's a good idea to briefly describe both stacked cells case and the boundary case in the docstring for this option as examples.
Also it would be good to maybe adjust or add one of the tests to ensure that what I describe up here works as expected. There are tests for intersections on boundaries for points and linestrings, maybe we can extend those to check whether the intersection result with the option set to True does yield 2 intersection results instead of 1.
| flag whether to sort cells by id, used to ensure node | ||
| with lowest id is returned, by default True | ||
| keep_stacked_cells : bool, optional | ||
| For shapely only, keeps all intersected cells even if cell vertices are already in the results. |
There was a problem hiding this comment.
keep_stacked_cells doesn't quite capture the full behavior of this option. Even without stacked cells, setting this option to True will e.g. return 2 intersection results for a point or linestring on a boundary between two cells.
also ensure <80 characters per line in docsstring
There was a problem hiding this comment.
I like keep_all_intersections and return_all_intersections. If I had to pick I would chose return_all_intersections.
| shp = gu.shapely | ||
| sort_by_cellid = kwargs.pop("sort_by_cellid", True) | ||
| keepzerolengths = kwargs.pop("keepzerolengths", False) | ||
| keep_stacked_cells = kwargs.pop("keep_stacked_cells", False) |
There was a problem hiding this comment.
Do we want to keep this syntax with **kwargs, or should we add the keyword arguments to the intersect method explicitly? (Even if they're sometimes not used, depending on the GridIntersect settings).
There was a problem hiding this comment.
I would vote for an actual argument rather than a **kwargs. I would leave **kwargs that are passed on to lower level functions like matplotlib.
| boolean method to keep zero length intersections for | ||
| linestring intersection | ||
| keep_stacked_cells : bool | ||
| For shapely only, keeps all intersected cells even if cell vertices are already in the results. |
|
Good comments, @dbrakenhoff! The use case so far has focused on the DISU keeping of stacked cells, but this has a substantial impact on the regular intersection behavior that we should probably think about more closely. Couple quick thoughts here:
|
|
I now realize that I didn't understand all the ramifications of my proposed change. I'm going to need to spend some more time on this and figure out what we really want. |
|
After some discussion here at Aquavaeo we think that this change isn't really going to help us with what we want to do with DISU intersections. I think I'd just like to just close this pull request. |
…ells with identical vertices
Add "keep_stacked_cells" kwarg to GridIntersect.intersect() which is used to prevent removal of
cells from the intersection results which have identical vertices as a cell already included in
the results. This kwarg is only used when intersecting using shapely, and is needed when dealing
with a DISU grid which doesn't have layers. With DIS and DISV, the intersection results include
cellids which have the layer number (either LAY, ROW, COL, or LAY, CELL2D) so cells above or
below the intersected cell can be easily found just be changing the layer number. But DISU
cellids do not include the layer so it is not at all easy to find cells above or below the
intersected cell. Thus having this kwarg which keeps all the cells in the results is needed.