Python:如何在距离以米为单位的点周围创建方形缓冲区
我有一个geopandas数据帧Python:如何在距离以米为单位的点周围创建方形缓冲区,python,gis,geopandas,shapely,Python,Gis,Geopandas,Shapely,我有一个geopandas数据帧gdf gdf ID longitude latitude geometry 0 80 103.619501 1.2810 POINT (103.619500987 1.281) 1 81 103.619501 1.2855 POINT (103.619500987 1.2855) 接下来,我在其周围创建一个方形缓冲区,其距离bd定义为: bd = abs((gdf['latitude'][0]-gdf['
gdf
gdf
ID longitude latitude geometry
0 80 103.619501 1.2810 POINT (103.619500987 1.281)
1 81 103.619501 1.2855 POINT (103.619500987 1.2855)
接下来,我在其周围创建一个方形缓冲区,其距离bd
定义为:
bd = abs((gdf['latitude'][0]-gdf['latitude'][1])/2)
最后,我能够得到以下信息:
buffer = gdf.buffer(bd)
envelope = buffer.envelope
f, ax = plt.subplots(figsize=(7.5, 7.5))
envelope.plot(color='white', edgecolor='gray',ax=ax)
gdf.plot(ax=ax)
如何设置对应于500米的距离
bd
?您需要将数据重新投影到使用米作为坐标的CRS。当您使用经度和纬度时,您的值以度为单位。所有,包括缓冲距离。如果要使用方形缓冲区,不需要使用信封,只需将cap_style
设置为3(请参阅)
有关更多详细信息,我推荐。这是我的函数,精度很高。数据是一个数据框,它包含一个
形状的几何体类型
def generate_buffer_meter(数据、半径、几何体='geometry',crs='epsg:4326'):
数据=gpd.GeoDataFrame(数据,几何=几何,crs=crs)
数据=data.to_crs('+proj=aeqd+units=m+x_0=0+y_0=0')
数据[几何体]=数据[几何体].缓冲区(半径)
数据=数据到crs(crs)
返回数据
此链接有帮助吗?对点进行缓冲后是否会丢失属性表信息?如果将包含缓冲区的GeoSeries指定为列,则不会。替换原始的几何图形
列或新列。
gdf.crs = 'epsg:4326' # I am assuming here
gdf = gdf.to_crs(epsg=3395)
buffer = gdf.buffer(500, cap_style=3) # you might want to use 250, guessing from your image