【问题标题】:Python: how to create square buffers around points with a distance in metersPython:如何在距离以米为单位的点周围创建方形缓冲区
【发布时间】:2019-08-15 09:40:36
【问题描述】:

我有一个 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)

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

【问题讨论】:

标签: python gis geopandas shapely


【解决方案1】:

您需要将数据重新投影到使用米作为坐标的 CRS。当您使用经度和纬度时,您的值以度为单位。所有,包括缓冲距离。如果你想做方形缓冲区,你不需要使用信封,只需将cap_style设置为3(见shapely docs)。

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

更多详情我推荐geopandas user guide

【讨论】:

  • 缓存点后会丢失属性表信息吗?
  • 如果您将包含缓冲区的 GeoSeries 分配为列,则不会。替换原来的geometry 列或新列。
【解决方案2】:

这是我的函数,精度很高。 data 是一个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

【讨论】:

  • 您的方法返回圆形,而不是方形。您可以使用cap_style=3 上述答案
猜你喜欢
  • 1970-01-01
  • 2022-10-15
  • 1970-01-01
  • 1970-01-01
  • 2018-04-02
  • 1970-01-01
  • 2021-10-03
  • 1970-01-01
  • 2018-05-27
相关资源
最近更新 更多