Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save liquidgenius/c0dfc0d0a7e6f859f7f341a8f61570b0 to your computer and use it in GitHub Desktop.
Save liquidgenius/c0dfc0d0a7e6f859f7f341a8f61570b0 to your computer and use it in GitHub Desktop.
Read a CSV with Pandas and set as GeoDataFrame with geopandas and save as Shapefile with fiona
import pandas as pd
from geopandas import GeoDataFrame
from shapely.geometry import Point
import fiona
df = pd.read_csv('data.csv')
geometry = [Point(xy) for xy in zip(df.x, df.y)]
crs = {'init': 'epsg:2263'} #http://www.spatialreference.org/ref/epsg/2263/
geo_df = GeoDataFrame(df, crs=crs, geometry=geometry)
geo_df.to_file(driver='ESRI Shapefile', filename='data.shp')
# https://gis.stackexchange.com/questions/204201/geopandas-to-file-saves-geodataframe-without-coordinate-system
# http://geopandas.org/io.html#writing-spatial-data
# https://gis.stackexchange.com/questions/174159/convert-a-pandas-dataframe-to-a-geodataframe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment