TopologicalError: The operation 'GEOSDifference_r' could not be performed

TopologicalError: The operation 'GEOSDifference_r' could not be performed

我正在尝试一些代码来获取巴塞罗那的建筑足迹:

import osmnx as ox
import matplotlib.pyplot as plt
%matplotlib inline

place_name = "Barcelona, Barcelona, Catalonia, Spain"
graph = ox.graph_from_place(place_name)
buildings = ox.footprints_from_place(place_name)

当我 运行 代码时,它会产生以下错误消息:

TopologicalError: The operation 'GEOSDifference_r' could not be performed. Likely cause is invalidity of the geometry <shapely.geometry.polygon.Polygon object at 0x00000262079B6550>

我已经尝试更新 OSMnx 版本,但似乎不是问题所在。 我该如何解决这个问题?

解决方案发布在以下 github 存储库中:

https://github.com/gboeing/osmnx/blob/5176d4a2f86fd2adaf523d3d9bd0bed9b9b1d6ec/osmnx/footprints.py

您应该使用更新后的代码更改 footprints.py 文件。 为此,您可以: -打开osmnx包粘贴中的文件,删除其内容并复制更新的内容,

-或者创建一个新文件,然后在osmnx包粘贴中替换它。