Skip to content

Instantly share code, notes, and snippets.

@paulopperman
Last active May 14, 2017 18:36
Show Gist options
  • Save paulopperman/18e44aa73b8a3a0f50558a79bf3bee06 to your computer and use it in GitHub Desktop.
Save paulopperman/18e44aa73b8a3a0f50558a79bf3bee06 to your computer and use it in GitHub Desktop.
workaround for importing shapefile into geopandas
import shapefile
import geopandas as gp
def convert_shapefile(filepath, crs=None):
# Function to read an ESRI shapefile and return a geopandas GeoDataFrame
reader = shapefile.Reader(filepath)
# Extract the column names for the data
fields = reader.fields[1:]
field_names = [field[0] for field in fields]
buffer = []
for sr in reader.shapeRecords():
atr = dict(zip(field_names, sr.record))
geom = sr.shape.__geo_interface__
buffer.append(dict(type="Feature", geometry=geom, properties=atr))
frame = gp.GeoDataFrame.from_features(buffer, crs=crs)
return frame
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment