gisutils.shapefile module

Functions for working with shapefiles.

gisutils.shapefile.df2shp(dataframe, shpname, geo_column='geometry', index=False, retain_order=False, prj=None, epsg=None, proj_str=None, crs=None)[source]

Write a DataFrame with a column of shapely geometries to a shapefile.

Parameters
dataframepandas.DataFrame
shpnamestr, filepath

Output shapefile

geo_columnstr

Name of column in dataframe with feature geometries (default ‘geometry’)

indexbool

If True, include the DataFrame index in the written shapefile

retain_orderbool

Retain column order in dataframe, using an OrderedDict. Shapefile will take about twice as long to write, since OrderedDict output is not supported by the pandas DataFrame object.

prjstr

Path to ESRI projection file describing the coordinate reference system of the feature geometries in the ‘geometry’ column. (specify one of prj, epsg, proj_str)

epsgint

EPSG code describing the coordinate reference system of the feature geometries in the ‘geometry’ column.

proj_strstr

PROJ string describing the coordinate reference system of the feature geometries in the ‘geometry’ column.

crsobj

A Python int, dict, str, or pyproj.crs.CRS instance passed to the pyproj.crs.CRS.from_user_input() See http://pyproj4.github.io/pyproj/stable/api/crs/crs.html#pyproj.crs.CRS.from_user_input. Can be any of:

  • PROJ string

  • Dictionary of PROJ parameters

  • PROJ keyword arguments for parameters

  • JSON string with PROJ parameters

  • CRS WKT string

  • An authority string [i.e. ‘epsg:4326’]

  • An EPSG integer code [i.e. 4326]

  • A tuple of (“auth_name”: “auth_code”) [i.e (‘epsg’, ‘4326’)]

  • An object with a to_wkt method.

  • A pyproj.crs.CRS class

Returns
writes a shapefile to shpname
gisutils.shapefile.rename_fields_to_10_characters(columns, limit=10)[source]
gisutils.shapefile.shp2df(shplist, index=None, index_dtype=None, clipto=[], filter=None, true_values=None, false_values=None, layer=None, dest_crs=None, skip_empty_geom=True)[source]
Read shapefile/DBF, list of shapefiles/DBFs, or File geodatabase (GDB)

into pandas DataFrame.

Parameters
shpliststring or list

of shapefile/DBF name(s) or FileGDB

indexstring

Column to use as index for dataframe

index_dtypedtype

Enforces a datatype for the index column (for example, if the index field is supposed to be integer but pandas reads it as strings, converts to integer)

cliptolist

limit what is brought in to items in index of clipto (requires index)

filtertuple (xmin, ymin, xmax, ymax)

bounding box to filter which records are read from the shapefile.

true_valueslist

same as argument for pandas read_csv

false_valueslist

same as argument for pandas read_csv

layerstr

Layer name to read (if opening FileGDB)

dest_crsobj

A Python int, dict, str, or pyproj.crs.CRS instance passed to the pyproj.crs.from_user_input See http://pyproj4.github.io/pyproj/stable/api/crs/crs.html#pyproj.crs.CRS.from_user_input. Can be any of:

  • PROJ string

  • Dictionary of PROJ parameters

  • PROJ keyword arguments for parameters

  • JSON string with PROJ parameters

  • CRS WKT string

  • An authority string [i.e. ‘epsg:4326’]

  • An EPSG integer code [i.e. 4326]

  • A tuple of (“auth_name”: “auth_code”) [i.e (‘epsg’, ‘4326’)]

  • An object with a to_wkt method.

  • A pyproj.crs.CRS class

skip_empty_geomTrue/False, default True

Drops shapefile entries with null geometries. DBF files (which specify null geometries in their schema) will still be read.

Returns
dfDataFrame

with attribute fields as columns; feature geometries are stored as

shapely geometry objects in the ‘geometry’ column.
gisutils.shapefile.shp_properties(df)[source]