【问题标题】:Is overlay how='difference' supposed to operate differently from geopandas 0.9 vs 0.10?overlay how='difference' 应该与 geopandas 0.9 和 0.10 不同吗?
【发布时间】:2021-10-06 03:21:55
【问题描述】:

我使用差异集操作来解决不同的问题,但是当用我的地理数据帧中的差异替换多边形时,我会得到一个空的地理数据帧或无类型。我发现这是由于多边形不相交并进行差异集操作的结果。我想知道这是正常行为还是应该保留 df1 的几何形状?此行为在 0.10 版和 0.9 版之间有所不同。

例如:

import geopandas

polys1 = geopandas.GeoSeries([Polygon([(0,0), (2,0), (2,2), (0,2)])])

polys2 = geopandas.GeoSeries([Polygon([(3,3), (5,3), (5,5), (3,5)])])


df1 = geopandas.GeoDataFrame({'geometry': polys1, 'df1':[1]})

df2 = geopandas.GeoDataFrame({'geometry': polys2, 'df2':[1]})

ax = df1.plot(color='red');

df2.plot(ax=ax, color='green', alpha=0.5);

显示两个不相交的多边形

如您所见,这些多边形并不相交。所以当我做差集操作的时候,

res_difference = df1.overlay(df2, how='difference')

print(res_difference)


ax = res_difference.plot(cmap='tab10')

df1.plot(ax=ax, facecolor='none', edgecolor='k');

df2.plot(ax=ax, facecolor='none', edgecolor='k');

输出就是这个,

空地理数据框

我希望在 res_difference 变量中看到 df1 几何图形。这是应该如何工作的差异吗?

我希望 df1 几何体出现在 res_difference 中的原因是基于 geopandas 0.9 中的行为。当我使用 geopandas 0.9 而不是 geopandas 0.10 运行以下代码时

# I use the function vs method since it seems the method isn't
# implemented in geopandas 0.9

res_difference = geopandas.overlay(df1, df2, how='difference')
print(res_difference)


ax = res_difference.plot(cmap='tab10')

df1.plot(ax=ax, facecolor='none', edgecolor='k');

df2.plot(ax=ax, facecolor='none', edgecolor='k');

你得到这个输出

这是我希望在 geopandas 0.10 中看到的行为,但如果多边形不相交,那么你会得到一个空的地理数据框。这是应该发生的还是这是实施空间索引的结果?

【问题讨论】:

  • 从您的代码中,您绘制res_difference,然后绘制df1df2。这就是为什么你会在你的情节上得到一切。
  • 嗨@swatchai,我的问题不是关于为什么空的 df1 显示为绘制的那样。我的问题是res_difference 应该是空的,如果我们将 df2 与 df1 的差异作为整体作为 df1 没有区别,所以我希望它返回res_difference 中的 df1 几何。除非那是差异的意图,我想这是我感到困惑的事情。是否只有至少有一个重叠多边形时,差异才会产生影响?

标签: python pandas geospatial geopandas


【解决方案1】:

这是 0.10 版本中的回归。对于那个很抱歉!我们会尽快修复它。同时,我建议坚持使用 0.9。

【讨论】:

  • 该修复刚刚在 0.10.1 中发布。它现在可以在 PyPI 上使用,并且将在一天结束时在 conda-forge 上。
猜你喜欢
  • 1970-01-01
  • 2018-09-15
  • 2019-11-27
  • 2020-10-22
  • 2018-11-25
  • 2022-12-01
  • 2017-12-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多