Skip to content Skip to sidebar Skip to footer

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

Solution 1:

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)

Solution 2:

At the equator, one minute of latitude or longitude is ~ 1.84 km or 1.15 mi (ref).

So if you define your point as P = [y, x] then you can create a buffer around it of lets say 4 minutes which are approximately 5 miles: buffer = 0.04. The bounding box then is easily obtained with

minlat = P[0]-(P[0]*buffer)
maxlat = P[0]+(P[0]*buffer)
minlon = P[1]-(P[1]*buffer)
maxlon = P[1]+(P[1]*buffer)

Post a Comment for "How To Create An Accurate Buffer Of 5 Miles Around A Coordinate In Python?"