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

萝らか妹 提交于 2020-01-15 03:21:10

问题


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!


回答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)



回答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)


来源:https://stackoverflow.com/questions/51263138/how-to-create-an-accurate-buffer-of-5-miles-around-a-coordinate-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!