flopy.export.shapefile_utils module
Module for exporting and importing flopy model attributes
- class CRS(prj=None, esri_wkt=None, epsg=None)[source]
Bases:
object
Container to parse and store coordinate reference system parameters, and translate between different formats.
- property crs
Dict mapping crs attributes to proj4 parameters
- static get_spatialreference(epsg, text='esriwkt')[source]
Gets text for given epsg code and text format from spatialreference.org Fetches the reference text using the url:
https://spatialreference.org/ref/epsg/<epsg code>/<text>/
See: https://www.epsg-registry.org/
- Parameters
epsg (int) – epsg code for coordinate system
text (str) – string added to url
- Return type
str
- static getprj(epsg, addlocalreference=True, text='esriwkt')[source]
Gets projection file (.prj) text for given epsg code from spatialreference.org See: https://www.epsg-registry.org/
- Parameters
epsg (int) – epsg code for coordinate system
addlocalreference (boolean) – adds the projection file text associated with epsg to a local database, epsgref.json, located in the user’s data directory.
- Returns
text for a projection (*.prj) file.
- Return type
str
- static getproj4(epsg)[source]
Gets projection file (.prj) text for given epsg code from spatialreference.org. See: https://www.epsg-registry.org/
- Parameters
epsg (int) – epsg code for coordinate system
- Returns
text for a projection (*.prj) file.
- Return type
str
- property grid_mapping_attribs
Map parameters for CF Grid Mappings https://cfconventions.org/cf-conventions/cf-conventions.html#appendix-grid-mappings, Appendix F: Grid Mappings
- property proj4
Not implemented yet
- class EpsgReference[source]
Bases:
object
Sets up a local database of text representations of coordinate reference systems, keyed by EPSG code.
The database is epsgref.json, located in either “%LOCALAPPDATA%flopy” for Windows users, or $HOME/.local/share/flopy for others.
- enforce_10ch_limit(names)[source]
Enforce 10 character limit for fieldnames. Add suffix for duplicate names starting at 0.
- Parameters
names (list of strings) –
- Returns
list of unique strings of len <= 10.
- Return type
list
- model_attributes_to_shapefile(path, ml, package_names=None, array_dict=None, **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 (Path or str) – 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)
**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
- epsgint
epsg projection information
- prjPath or str
user supplied prj file
- Return type
None
Examples
>>> import flopy >>> m = flopy.modflow.Modflow() >>> flopy.utils.model_attributes_to_shapefile('model.shp', m)
- recarray2shp(recarray, geoms, shpname='recarray.shp', mg=None, epsg=None, prj=None, **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 (Path or str, default "recarray.shp") – Path for the output shapefile
epsg (int) – EPSG code. See https://www.epsg-registry.org/ or spatialreference.org
prj (Path or 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.json (located in the user’s data directory) for subsequent use. See flopy.reference for more details.
- 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
name (str) – 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)
- Return type
str
Examples
>>> import flopy >>> name = flopy.utils.shape_attr_name('averylongstring') >>> name >>> 'averyl'
- shp2recarray(shpname)[source]
Read a shapefile into a numpy recarray.
- Parameters
shpname (Path or str) – ESRI Shapefile.
- Return type
np.recarray
- write_grid_shapefile(path, mg, array_dict, nan_val=nan, epsg=None, prj=None)[source]
Method to write a shapefile of gridded input data
- Parameters
path (Path or str) – 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
epsg (str, int) – epsg code
prj (Path or str) – projection file name path
- Return type
None