flopy.export.shapefile_utils module
Module for exporting and importing flopy model attributes
- enforce_10ch_limit(names)[source]
Enforce 10 character limit for fieldnames. Add suffix for duplicate names starting at 0.
- model_attributes_to_shapefile(path: str | PathLike, ml, package_names=None, array_dict=None, verbose=False, **kwargs)[source]
Wrapper function for writing a shapefile of model data. If package_names is not None, then search through the requested packages looking for arrays that can be added to the shapefile as attributes
- Parameters:
path (str or PathLike) – path to write the shapefile to
ml (flopy.mbase) – model instance
package_names (list of package names (e.g. ["dis","lpf"])) – Packages to export data arrays to shapefile. (default is None)
array_dict (dict of {name:2D array} pairs) – Additional 2D arrays to add as attributes to the shapefile. (default is None)
verbose (bool, optional, default False) – whether to print verbose output
**kwargs (keyword arguments) –
- modelgridfp.modflow.Grid object
if modelgrid is supplied, user supplied modelgrid is used in lieu of the modelgrid attached to the modflow model object
- crspyproj.CRS, optional if prjfile is specified
Coordinate reference system (CRS) for the model grid (must be projected; geographic CRS are not supported). The value can be anything accepted by
pyproj.CRS.from_user_input()
, such as an authority string (eg “EPSG:26916”) or a WKT string.- prjfilestr or pathlike, optional if crs is specified
ESRI-style projection file with well-known text defining the CRS for the model grid (must be projected; geographic CRS are not supported).
- Return type:
None
Examples
>>> import flopy >>> m = flopy.modflow.Modflow() >>> flopy.utils.model_attributes_to_shapefile('model.shp', m)
- recarray2shp(recarray, geoms, shpname: str | PathLike = 'recarray.shp', mg=None, crs=None, prjfile=None, epsg=None, prj: str | PathLike | None = None, verbose=False, **kwargs)[source]
Write a numpy record array to a shapefile, using a corresponding 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, 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 or PathLike, default "recarray.shp") – Path for the output shapefile
crs (pyproj.CRS, optional if prjfile is specified) – Coordinate reference system (CRS) for the model grid (must be projected; geographic CRS are not supported). The value can be anything accepted by
pyproj.CRS.from_user_input()
, such as an authority string (eg “EPSG:26916”) or a WKT string.prjfile (str or pathlike, optional if crs is specified) – ESRI-style projection file with well-known text defining the CRS for the model grid (must be projected; geographic CRS are not supported).
Notes
Uses pyshp.
- shape_attr_name(name, length=6, keep_layer=False)[source]
Function for to format an array name to a maximum of 10 characters to conform with ESRI shapefile maximum attribute name length
- Parameters:
- Return type:
Examples
>>> import flopy >>> name = flopy.utils.shape_attr_name('averylongstring') >>> name >>> 'averyl'
- shp2recarray(shpname: str | PathLike)[source]
Read a shapefile into a numpy recarray.
- Parameters:
shpname (str or PathLike) – ESRI Shapefile path
- Return type:
np.recarray
- write_grid_shapefile(path: str | PathLike, mg, array_dict, nan_val=nan, crs=None, prjfile=None, epsg=None, prj: str | PathLike | None = None, verbose=False)[source]
Method to write a shapefile of gridded input data
- Parameters:
path (str or PathLike) – shapefile file path
mg (flopy.discretization.Grid object) – flopy model grid
array_dict (dict) – dictionary of model input arrays
nan_val (float) – value to fill nans
crs (pyproj.CRS, optional if prjfile is specified) – Coordinate reference system (CRS) for the model grid (must be projected; geographic CRS are not supported). The value can be anything accepted by
pyproj.CRS.from_user_input()
, such as an authority string (eg “EPSG:26916”) or a WKT string.prjfile (str or pathlike, optional if crs is specified) – ESRI-style projection file with well-known text defining the CRS for the model grid (must be projected; geographic CRS are not supported).
- Return type:
None