我有一个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)
在this suggestion之后,我围绕它创建了一个方形缓冲区,其距离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)
如何设置bd
对应于500米的距离?
答案 0 :(得分:1)
您需要将数据重新投影到使用仪表作为坐标的CRS。使用经度和纬度时,您的值以度为单位。全部,包括缓冲距离。如果要进行正方形缓冲,则不需要使用信封,只需将cap_style
设置为3(请参阅shapely docs)。
gdf.crs = {'init' :'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
有关更多详细信息,我建议使用geopandas user guide。
答案 1 :(得分:0)
这是我的函数,具有很高的精度。数据是一个DataFrame,其中包含shapely
的几何类型
def generate_buffer_meter(data, radiu, geometry='geometry', crs='epsg:4326'):
data = gpd.GeoDataFrame(data, geometry=geometry, crs=crs)
data = data.to_crs('+proj=aeqd +units=m +x_0=0 +y_0=0')
data[geometry] = data[geometry].buffer(radiu)
data = data.to_crs(crs)
return data