Skip to content

Commit

Permalink
fix(#958): fix GridIntersect._vtx_grid_to_shape_generator rtree for c…
Browse files Browse the repository at this point in the history
…ells with more than 3 vertices (#959)

Also added a test.
  • Loading branch information
mkennard-aquaveo committed Aug 7, 2020
1 parent c8cde4d commit 2fd9326
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
44 changes: 44 additions & 0 deletions autotest/t065_test_gridintersect.py
Expand Up @@ -59,6 +59,27 @@ def get_rect_grid(angrot=0., xyoffset=0., top=None, botm=None):
return sgr


def get_rect_vertex_grid(angrot=0., xyoffset=0.):
cell2d = [[0, 5.0, 5.0, 4, 0, 1, 4, 3],
[1, 15.0, 5.0, 4, 1, 2, 5, 4],
[2, 5.0, 15.0, 4, 3, 4, 7, 6],
[3, 15.0, 15.0, 4, 4, 5, 8, 7]]
vertices = [[0, 0.0, 0.0],
[1, 10.0, 0.0],
[2, 20.0, 0.0],
[3, 0.0, 10.0],
[4, 10.0, 10.0],
[5, 20.0, 10.0],
[6, 0.0, 20.0],
[7, 10.0, 20.0],
[8, 20.0, 20.0]]
tgr = fgrid.VertexGrid(vertices, cell2d,
botm=np.atleast_2d(np.zeros(len(cell2d))),
top=np.ones(len(cell2d)), xoff=xyoffset,
yoff=xyoffset, angrot=angrot)
return tgr


def plot_structured_grid(sgr):
_, ax = plt.subplots(1, 1, figsize=(8, 8))
sgr.plot(ax=ax)
Expand Down Expand Up @@ -254,6 +275,29 @@ def test_rect_grid_point_on_inner_boundary_shapely(rtree=True):
return result


def test_rect_vertex_grid_point_in_one_cell_shapely(rtree=True):
# avoid test fail when shapely not available
try:
import shapely
except:
return
gr = get_rect_vertex_grid()
ix = GridIntersect(gr, method='vertex', rtree=rtree)
result = ix.intersect_point(Point(4., 4.))
assert len(result) == 1
assert result.cellids[0] == 0
result = ix.intersect_point(Point(4., 6.))
assert len(result) == 1
assert result.cellids[0] == 0
result = ix.intersect_point(Point(6., 6.))
assert len(result) == 1
assert result.cellids[0] == 0
result = ix.intersect_point(Point(6., 4.))
assert len(result) == 1
assert result.cellids[0] == 0
return result


def test_rect_grid_multipoint_in_one_cell_shapely(rtree=True):
# avoid test fail when shapely not available
try:
Expand Down
2 changes: 1 addition & 1 deletion flopy/utils/gridintersect.py
Expand Up @@ -227,7 +227,7 @@ def _vtx_grid_to_shape_generator(self):
elif isinstance(self.mfgrid._cell2d, list):
for icell in range(len(self.mfgrid._cell2d)):
points = []
for iv in self.mfgrid._cell2d[icell][-3:]:
for iv in self.mfgrid._cell2d[icell][4:]:
points.append(
(
self.mfgrid._vertices[iv][1],
Expand Down

0 comments on commit 2fd9326

Please sign in to comment.