Skip to content

Commit

Permalink
fix(#2152): improve gridintersect geometry creation for vertex grids (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
dbrakenhoff committed Apr 15, 2024
1 parent e023235 commit 57cf82e
Showing 1 changed file with 21 additions and 50 deletions.
71 changes: 21 additions & 50 deletions flopy/utils/gridintersect.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,57 +429,28 @@ def _vtx_grid_to_geoms_cellids(self):
cellids : array_like
array of cellids
"""
shapely_geo = import_optional_dependency("shapely.geometry")

# for cell2d rec-arrays
geoms = []
cellids = []
if isinstance(self.mfgrid._cell2d, np.recarray):
for icell in self.mfgrid._cell2d.icell2d:
points = []
icverts = [
f"icvert_{i}"
for i in range(self.mfgrid._cell2d["ncvert"][icell])
]
for iv in self.mfgrid._cell2d[icverts][icell]:
if self.local:
xy = (
self.mfgrid._vertices.xv[iv],
self.mfgrid._vertices.yv[iv],
)
else:
xy = (
self.mfgrid.verts[iv, 0],
self.mfgrid.verts[iv, 1],
)
points.append(xy)
# close the polygon, if necessary
if points[0] != points[-1]:
points.append(points[0])
geoms.append(shapely_geo.Polygon(points))
cellids.append(icell)
# for cell2d lists
elif isinstance(self.mfgrid._cell2d, list):
for icell in range(len(self.mfgrid._cell2d)):
points = []
for iv in self.mfgrid._cell2d[icell][4:]:
if self.local:
xy = (
self.mfgrid._vertices[iv][1],
self.mfgrid._vertices[iv][2],
)
else:
xy = (
self.mfgrid.verts[iv, 0],
self.mfgrid.verts[iv, 1],
shapely = import_optional_dependency("shapely")
if self.local:
geoms = [
shapely.polygons(
list(
zip(
*self.mfgrid.get_local_coords(
*np.array(
self.mfgrid.get_cell_vertices(node)
).T
)
)
points.append(xy)
# close the polygon, if necessary
if points[0] != points[-1]:
points.append(points[0])
geoms.append(shapely_geo.Polygon(points))
cellids.append(icell)
return np.array(geoms), np.array(cellids)
)
)
for node in range(self.mfgrid.ncpl)
]
else:
geoms = [
shapely.polygons(self.mfgrid.get_cell_vertices(node))
for node in range(self.mfgrid.ncpl)
]
return np.array(geoms), np.arange(self.mfgrid.ncpl)

def _rect_grid_to_shape_list(self):
"""internal method, list of shapely polygons for structured grid cells.
Expand Down

0 comments on commit 57cf82e

Please sign in to comment.