Python:如何在距离以米为单位的点周围创建方形缓冲区

时间:2019-08-15 09:40:36

标签: 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)

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)

enter image description here

如何设置bd对应于500米的距离?

2 个答案:

答案 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