Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create an accurate buffer of 5 miles around a coordinate in python?

I would like to create an accurate buffer of 5 miles around a coordinate, my current code is:

cpr_gdf['p_buffer']=cpr_gdf['coordinates'].buffer(5*(1/60))

The coordinates column was created with this code:

cpr_df['coordinates']=list(zip(cpr_df.sample_longitude_decimal,cpr_df.sample_latitude_decimal))
cpr_df['coordinates']=cpr_df['coordinates'].apply(Point)
cpr_gdf=gpd.GeoDataFrame(cpr_df,geometry='coordinates',crs={'init' :'epsg:4326'})

Thanks for any help!

like image 836
lourew Avatar asked Sep 14 '25 14:09

lourew


1 Answers

You need to convert to an equal area projection that is most accurate to where your buffer will be (good resource at https://epsg.io/)

For example, I'm making maps in Michigan, so I'm using EPSG:3174 (which I believe is in meters, correct me if wrong). Given you've already converted your dataframe to a GeoPandas dataframe, you can convert your current projection to 3174 and then create your buffer (converting miles to meters)

cpr_gdf= cpr_gdf.to_crs({'init': 'epsg:3174'})  
buffer_length_in_meters = (5 * 1000) * 1.60934
cpr_gdf['geometry'] = cpr_gdf.geometry.buffer(buffer_length_in_meters)
like image 103
Geoff Perrin Avatar answered Sep 17 '25 07:09

Geoff Perrin