Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
136 changes: 68 additions & 68 deletions autotest/t065_test_gridintersect.py

Large diffs are not rendered by default.

462 changes: 462 additions & 0 deletions autotest/t074_test_geospatial_util.py

Large diffs are not rendered by default.

132 changes: 64 additions & 68 deletions examples/Notebooks/flopy3_grid_intersection_demo.ipynb

Large diffs are not rendered by default.

45 changes: 36 additions & 9 deletions flopy/export/shapefile_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,12 @@ def write_gridlines_shapefile(filename, mg):


def write_grid_shapefile(
filename, mg, array_dict, nan_val=np.nan, epsg=None, prj=None # -1.0e9,
filename,
mg,
array_dict,
nan_val=np.nan,
epsg=None,
prj=None, # -1.0e9,
):
"""
Method to write a shapefile of gridded input data
Expand Down Expand Up @@ -357,7 +362,8 @@ def model_attributes_to_shapefile(
for ilay in range(a.model.modelgrid.nlay):
u2d = a[ilay]
name = "{}_{}".format(
shape_attr_name(u2d.name), ilay + 1
shape_attr_name(u2d.name),
ilay + 1,
)
arr = u2d.array
assert arr.shape == horz_shape
Expand Down Expand Up @@ -463,7 +469,12 @@ def get_pyshp_field_info(dtypename):

def get_pyshp_field_dtypes(code):
"""Returns a numpy dtype for a pyshp field type."""
dtypes = {"N": np.int, "F": np.float, "L": np.bool, "C": np.object}
dtypes = {
"N": np.int,
"F": np.float,
"L": np.bool,
"C": np.object,
}
return dtypes.get(code, np.object)


Expand All @@ -480,7 +491,7 @@ def shp2recarray(shpname):
recarray : np.recarray

"""
from ..utils.geometry import shape
from ..utils.geospatial_utils import GeoSpatialCollection

sf = import_shapefile(check_version=False)

Expand All @@ -489,7 +500,7 @@ def shp2recarray(shpname):
(str(f[0]), get_pyshp_field_dtypes(f[1])) for f in sfobj.fields[1:]
]

geoms = [shape(s) for s in sfobj.iterShapes()]
geoms = GeoSpatialCollection(sfobj).flopy_geometry
records = [
tuple(r) + (geoms[i],) for i, r in enumerate(sfobj.iterRecords())
]
Expand All @@ -510,14 +521,18 @@ def recarray2shp(
):
"""
Write a numpy record array to a shapefile, using a corresponding
list of geometries.
list of geometries. Method supports list of flopy geometry objects,
flopy Collection object, shapely Collection object, and geojson
Geometry Collection objects

Parameters
----------
recarray : np.recarray
Numpy record array with attribute information that will go in the
shapefile
geoms : list of flopy.utils.geometry objects
geoms : list of flopy.utils.geometry, shapely geometry collection,
flopy geometry collection, shapefile.Shapes,
list of shapefile.Shape objects, or geojson geometry collection
The number of geometries in geoms must equal the number of records in
recarray.
shpname : str
Expand All @@ -536,6 +551,7 @@ def recarray2shp(
subsequent use. See flopy.reference for more details.

"""
from ..utils.geospatial_utils import GeoSpatialCollection

if len(recarray) != len(geoms):
raise IndexError(
Expand All @@ -546,6 +562,9 @@ def recarray2shp(
raise Exception("Recarray is empty")

geomtype = None

geoms = GeoSpatialCollection(geoms).flopy_geometry

for g in geoms:
try:
geomtype = g.shapeType
Expand Down Expand Up @@ -722,7 +741,10 @@ def grid_mapping_attribs(self):
if self.wktstr is not None:
sp = [
p
for p in [self.standard_parallel_1, self.standard_parallel_2]
for p in [
self.standard_parallel_1,
self.standard_parallel_2,
]
if p is not None
]
sp = sp if len(sp) > 0 else None
Expand Down Expand Up @@ -797,7 +819,12 @@ def _getvalue(self, k):
end = s[strt:].find("]") + strt
try:
return float(self.wktstr[strt:end].split(",")[1])
except (IndexError, TypeError, ValueError, AttributeError):
except (
IndexError,
TypeError,
ValueError,
AttributeError,
):
pass

def _getgcsparam(self, txt):
Expand Down
Loading