Wenyan Deng

Ph.D. Candidate

Massachusetts Institute of Technology

Side Note: Writing Geo-Dataframes as Shapefiles

January 17, 2018

Continuing from the example from last time, if you want to write a GeoDataframe as a shapefile, below is how to do it. Let's use a dataset for all armed groups (terminated and not terminated), and call it groups_df.

First, zip the longitude and latitude into one column called "geometry".

from shapely.geometry import Point


groups_df = pd.read_excel("AOSA_map.xls")

geometry = [Point(xy) for xy in zip(groups_df.Longitude, groups_df.Latitude)]

groups_coords = gpd.GeoDataFrame(groups_df, crs = result.crs, geometry=geometry)

groups_coords['geometry'] = groups_coords.apply(lambda x: Point((float(x.Longitude), float(x.Latitude))), axis=1) groups_coords.head()

See what the data points look like:

groups_coords.plot()

Now we can convert it into a geodataframe and save as a shapefile:

roups_coords = gpd.GeoDataFrame(groups_coords, geometry='geometry')

groups_coords.to_file('Groups.shp', driver='ESRI Shapefile')