flopy.export.shapefile_utils Module

Module for exporting and importing flopy model attributes

flopy.export.shapefile_utils.enforce_10ch_limit(names)

Enforce 10 character limit for fieldnames. Add suffix for duplicate names starting at 0.

Parameters:names : list of strings
Returns:names : list of unique strings of len <= 10.
flopy.export.shapefile_utils.get_pyshp_field_dtypes(code)

Returns a numpy dtype for a pyshp field type.

flopy.export.shapefile_utils.get_pyshp_field_info(dtypename)

Get pyshp dtype information for a given numpy dtype.

flopy.export.shapefile_utils.model_attributes_to_shapefile(filename, ml, package_names=None, array_dict=None, **kwargs)

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:

filename : string

name of the shapefile to write

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)

Returns:

None

Examples

>>> import flopy
>>> m = flopy.modflow.Modflow()
>>> flopy.utils.model_attributes_to_shapefile('model.shp', m)
flopy.export.shapefile_utils.recarray2shp(recarray, geoms, shpname='recarray.shp', epsg=None, prj=None)

Write a numpy record array to a shapefile, using a corresponding list of geometries.

Parameters:

recarray : np.recarry

Numpy record array with attribute information that will go in the shapefile

geoms : list of flopy.utils.geometry objects

The number of geometries in geoms must equal the number of records in recarray.

shpname : str

Path for the output shapefile

epsg : int

EPSG code. See https://www.epsg-registry.org/ or spatialreference.org

prj : str

Existing projection file to be used with new shapefile.

Notes

Uses pyshp. epsg code requires an internet connection the first time to get the projection file text from spatialreference.org, but then stashes the text in the file epsgref.py (located in the site-packages folder) for subsequent use. See flopy.reference for more details.

flopy.export.shapefile_utils.shape_attr_name(name, length=6, keep_layer=False)

Function for to format an array name to a maximum of 10 characters to conform with ESRI shapefile maximum attribute name length

Parameters:

name : string

data array name

length : int

maximum length of string to return. Value passed to function is overridden and set to 10 if keep_layer=True. (default is 6)

keep_layer : bool

Boolean that determines if layer number in name should be retained. (default is False)

Returns:

String

Examples

>>> import flopy
>>> name = flopy.utils.shape_attr_name('averylongstring')
>>> name
>>> 'averyl'
flopy.export.shapefile_utils.shp2recarray(shpname)

Read a shapefile into a numpy recarray.

Parameters:

shpname : str

ESRI Shapefile.

Returns:

recarray : np.recarray

flopy.export.shapefile_utils.write_grid_shapefile(filename, sr, array_dict, nan_val=-1000000000.0)

Write a grid shapefile array_dict attributes.

Parameters:

filename : string

name of the shapefile to write

sr : spatial reference instance

spatial reference object for model grid

array_dict : dict

Dictionary of name and 2D array pairs. Additional 2D arrays to add as attributes to the grid shapefile.

Returns:

None

flopy.export.shapefile_utils.write_gridlines_shapefile(filename, sr)

Write a polyline shapefile of the grid lines - a lightweight alternative to polygons.

Parameters:

filename : string

name of the shapefile to write

sr : spatial reference

Returns:

None