Created
August 29, 2019 21:40
-
-
Save jterstriep/6e3abcd09de3a14739474d1d373d5820 to your computer and use it in GitHub Desktop.
Convert CSV with Lat Long to GeoDataFrame
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## https://gis.stackexchange.com/questions/174159/convert-a-pandas-dataframe-to-a-geodataframe | |
| from geopandas import GeoDataFrame | |
| from shapely.geometry import Point | |
| geometry = [Point(xy) for xy in zip(df.Lon, df.Lat)] | |
| df = df.drop(['Lon', 'Lat'], axis=1) | |
| crs = {'init': 'epsg:4326'} | |
| gdf = GeoDataFrame(df, crs=crs, geometry=geometry) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## Adds geometry from WKT | |
| import geopandas as gpd | |
| import shapely.wkt | |
| geometry = df['wktcolumn'].map(shapely.wkt.loads) | |
| df = df.drop('wktcolumn', axis=1) | |
| crs = {'init': 'epsg:4326'} | |
| gdf = gpd.GeoDataFrame(df, crs=crs, geometry=geometry) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment