Created
August 22, 2022 15:43
-
-
Save jamesdamillington/5f7c4c231b74a068be4cb232b1b9dea5 to your computer and use it in GitHub Desktop.
read a csv (containing a column with geometries) as geopandas gdf
This file contains 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
#import relevant packages | |
import pandas as pd | |
import geopandas as gpd | |
from shapely.wkt import loads | |
#set variables for this particular data set | |
file_path = "data/mydata.csv" #location of data | |
geom_col = 'geometry' #name of column containing geometries | |
epsg_id = 27700 #see https://epsg.io/ | |
crs_str = "EPSG:" + str(epsg_id) #concat | |
#read the data and create gdf | |
df = pd.read_csv(file_path) #pandas | |
gdf = gpd.GeoDataFrame(df) #geopandas | |
gdf[geom_col] = gdf[geom_col].apply(lambda x: loads(x)) #from shapely | |
gdf = gdf.set_geometry(geom_col).set_crs(crs_str) #set geometry and crs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment