Skip to content
2 changes: 1 addition & 1 deletion autotest/test_binaryfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ def test_load_binary_head_file(example_data_path):

def test_plot_binary_head_file(example_data_path):
hf = HeadFile(example_data_path / "freyberg" / "freyberg.githds")
hf.mg.set_coord_info(xoff=1000.0, yoff=200.0, angrot=15.0)
hf.modelgrid.set_coord_info(xoff=1000.0, yoff=200.0, angrot=15.0)

assert isinstance(hf.plot(), Axes)
plt.close()
Expand Down
2 changes: 1 addition & 1 deletion autotest/test_formattedfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def test_headfile_build_index(example_data_path):
def test_formattedfile_reference(example_data_path):
h = FormattedHeadFile(example_data_path / "mf2005_test" / "test1tr.githds")
assert isinstance(h, FormattedHeadFile)
h.mg.set_coord_info(xoff=1000.0, yoff=200.0, angrot=15.0)
h.modelgrid.set_coord_info(xoff=1000.0, yoff=200.0, angrot=15.0)

assert isinstance(h.plot(masked_values=[6999.000]), Axes)
plt.close()
Expand Down
10 changes: 5 additions & 5 deletions autotest/test_geospatial_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ def test_polygon_collection(polygon, poly_w_hole, multipolygon):
points = gc1.points
geojson = gc1.geojson
fp_geo = gc1.flopy_geometry
gdf = gc1.geo_dataframe
gdf = gc1.geodataframe

collections = [shp, shply, points, geojson, fp_geo, gdf]
for col in collections:
Expand Down Expand Up @@ -408,7 +408,7 @@ def test_point_collection(point, multipoint):
points = gc1.points
geojson = gc1.geojson
fp_geo = gc1.flopy_geometry
gdf = gc1.geo_dataframe
gdf = gc1.geodataframe

collections = [shp, shply, points, geojson, fp_geo, gdf]
for col in collections:
Expand Down Expand Up @@ -436,7 +436,7 @@ def test_linestring_collection(linestring, multilinestring):
points = gc1.points
geojson = gc1.geojson
fp_geo = gc1.flopy_geometry
gdf = gc1.geo_dataframe
gdf = gc1.geodataframe

collections = [shp, shply, points, geojson, fp_geo, gdf]
for col in collections:
Expand Down Expand Up @@ -481,7 +481,7 @@ def test_mixed_collection(
points = gc1.points
geojson = gc1.geojson
fp_geo = gc1.flopy_geometry
gdf = gc1.geo_dataframe
gdf = gc1.geodataframe

collections = [shp, shply, lshply, points, geojson, fp_geo, gdf]
for col in collections:
Expand Down Expand Up @@ -525,7 +525,7 @@ def test_geopandas_dtypes(
col = Collection(col)

gc1 = GeoSpatialCollection(col)
gdf = gc1.geo_dataframe
gdf = gc1.geodataframe

collections = [gdf, gdf.geometry, gdf.geometry.values]
for col in collections:
Expand Down
6 changes: 3 additions & 3 deletions autotest/test_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -1585,14 +1585,14 @@ def test_unstructured_convert(unstructured_grid):


@requires_pkg("geopandas")
def test_geo_dataframe(structured_grid, vertex_grid, unstructured_grid):
def test_geodataframe(structured_grid, vertex_grid, unstructured_grid):
geopandas = import_optional_dependency("geopandas")
grids = (structured_grid, vertex_grid, unstructured_grid)

for grid in grids:
gdf = grid.geo_dataframe
gdf = grid.to_geodataframe()
if not isinstance(gdf, geopandas.GeoDataFrame):
raise TypeError("geo_dataframe not returning GeoDataFrame object")
raise TypeError("geodataframe not returning GeoDataFrame object")

geoms = gdf.geometry.values
for node, geom in enumerate(geoms):
Expand Down
21 changes: 7 additions & 14 deletions autotest/test_modpathfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,9 @@ def test_get_destination_endpoint_data(

@pytest.mark.parametrize("longfieldname", [True, False])
@requires_exe("mf6", "mp7")
@requires_pkg("pyshp", "shapely", name_map={"pyshp": "shapefile"})
@requires_pkg("geopandas", "shapely")
def test_write_shapefile(function_tmpdir, mp7_small, longfieldname):
from shapefile import Reader
import geopandas as gpd

# setup and run model, then copy outputs to function_tmpdir
sim, forward_model_name, _, _, _ = mp7_small
Expand All @@ -330,13 +330,7 @@ def test_write_shapefile(function_tmpdir, mp7_small, longfieldname):
# define shapefile path
shp_file = ws / "pathlines.shp"

# add a column to the pathline recarray
fieldname = "newfield" + ("longname" if longfieldname else "")
fieldval = "x"
pathlines = [
rfn.append_fields(pl, fieldname, list(repeat(fieldval, len(pl))), dtypes="|U1")
for pl in pathlines
]
pline_names = [name[:10] for name in pathlines[0].dtype.names]

# write the pathline recarray to shapefile
pathline_file.write_shapefile(
Expand All @@ -350,8 +344,7 @@ def test_write_shapefile(function_tmpdir, mp7_small, longfieldname):
assert shp_file.is_file()

# load shapefile
with Reader(shp_file) as reader:
fieldnames = [f[0] for f in reader.fields[1:]]
fieldname = "newfiname_" if longfieldname else fieldname
assert fieldname in fieldnames
assert all(r[fieldname] == fieldval for r in reader.iterRecords())
gdf = gpd.read_file(shp_file)
fieldnames = list(gdf)
for fname in pline_names:
assert fname in fieldnames
9 changes: 4 additions & 5 deletions flopy/discretization/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ def xyzvertices(self):
def cross_section_vertices(self):
return self.xyzvertices[0], self.xyzvertices[1]

def geo_dataframe(self, features, featuretype="Polygon"):
def to_geodataframe(self, features, featuretype="Polygon"):
"""
Method returns a geopandas GeoDataFrame of the Grid

Expand All @@ -606,23 +606,22 @@ def geo_dataframe(self, features, featuretype="Polygon"):
gc = GeoSpatialCollection(
features, shapetype=[featuretype for _ in range(len(features))]
)
gdf = gc.geo_dataframe
gdf = gc.geodataframe
gdf["node"] = gdf.index + 1
if self.crs is not None:
gdf = gdf.set_crs(crs=self.crs)

return gdf

@property
def grid_line_geo_dataframe(self):
def grid_line_geodataframe(self):
"""
Method to get a GeoDataFrame of grid lines

Returns
-------
GeoDataFrame
"""
gdf = self.geo_dataframe(self.grid_lines, featuretype="LineString")
gdf = self.to_geodataframe(self.grid_lines, featuretype="LineString")
gdf = gdf.rename(columns={"node": "number"})
return gdf

Expand Down
22 changes: 19 additions & 3 deletions flopy/discretization/structuredgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -759,8 +759,7 @@ def map_polygons(self):

return self._polygons

@property
def geo_dataframe(self):
def to_geodataframe(self):
"""
Returns a geopandas GeoDataFrame of the model grid

Expand All @@ -769,11 +768,28 @@ def geo_dataframe(self):
GeoDataFrame
"""
polys = [[list(zip(*i))] for i in zip(*self.cross_section_vertices)]
gdf = super().geo_dataframe(polys)
gdf = super().to_geodataframe(polys)
gdf["row"] = sorted(list(range(1, self.nrow + 1)) * self.ncol)
gdf["col"] = list(range(1, self.ncol + 1)) * self.nrow
return gdf

@property
def geo_dataframe(self):
"""
Returns a geopandas GeoDataFrame of the model grid

Returns
-------
GeoDataFrame
"""
import warnings

warnings.warn(
"geo_dataframe has been deprecated, use to_geodataframe() instead",
DeprecationWarning,
)
return self.to_geodataframe()

def convert_grid(self, factor):
"""
Method to scale the model grid based on user supplied scale factors
Expand Down
22 changes: 19 additions & 3 deletions flopy/discretization/unstructuredgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,8 +580,7 @@ def map_polygons(self):

return copy.copy(self._polygons)

@property
def geo_dataframe(self):
def to_geodataframe(self):
"""
Returns a geopandas GeoDataFrame of the model grid

Expand All @@ -590,9 +589,26 @@ def geo_dataframe(self):
GeoDataFrame
"""
polys = [[self.get_cell_vertices(nn)] for nn in range(self.nnodes)]
gdf = super().geo_dataframe(polys)
gdf = super().to_geodataframe(polys)
return gdf

@property
def geo_dataframe(self):
"""
Returns a geopandas GeoDataFrame of the model grid

Returns
-------
GeoDataFrame
"""
import warnings

warnings.warn(
"geo_dataframe has been deprecated, use to_geodataframe() instead",
DeprecationWarning,
)
return self.to_geodataframe()

def neighbors(self, node=None, **kwargs):
"""
Method to get nearest neighbors of a cell
Expand Down
22 changes: 19 additions & 3 deletions flopy/discretization/vertexgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,7 @@ def map_polygons(self):

return copy.copy(self._polygons)

@property
def geo_dataframe(self):
def to_geodataframe(self):
"""
Returns a geopandas GeoDataFrame of the model grid

Expand All @@ -313,9 +312,26 @@ def geo_dataframe(self):
featuretype = "Polygon"
if self._cell1d is not None:
featuretype = "multilinestring"
gdf = super().geo_dataframe(cells, featuretype)
gdf = super().to_geodataframe(cells, featuretype)
return gdf

@property
def geo_dataframe(self):
"""
Returns a geopandas GeoDataFrame of the model grid

Returns
-------
GeoDataFrame
"""
import warnings

warnings.warn(
"geo_dataframe has been deprecated, use to_geodataframe() instead",
DeprecationWarning,
)
return self.to_geodataframe()

def convert_grid(self, factor):
"""
Method to scale the model grid based on user supplied scale factors
Expand Down
Loading
Loading