【发布时间】:2020-07-22 14:18:57
【问题描述】:
我的问题非常简单:我有一个由 2 个多边形组成的网络,另一个仅包含前一个网络中的两个多边形之一。如果我检查有 2 个多边形的网络中一个多边形中有多少个节点,我会得到 9735 个节点。但是,如果我检查有多少节点在同一个多边形中,但在只有一个多边形的网络中,我得到 9719。我不明白为什么会有差异,它们应该是相同的。
代码如下:
cities = ox.geocode_to_gdf(['Município de Lisboa', 'Município da Amadora'])
whole_polygon = cities.unary_union #unary union of both geometries
lisbon_pol = cities['geometry'].iloc[0] #geometry of just lisbon
amadora_pol = cities['geometry'].iloc[1]
G = ox.graph_from_polygon(whole_polygon, network_type='drive', simplify=True)
G_nx = nx.relabel.convert_node_labels_to_integers(G)
nodes_in_lx = nodes[nodes.within(lisbon_pol)]
print(len(nodes_in_lx)) # This gives 9735 nodes
G_lx = ox.graph_from_polygon(lisbon_pol, network_type='drive', simplify=True)
print(len(G_lx)) # This gives 9719 nodes
导致不一致的更大原因是,如果我将各个多边形中的节点相加,我得到的节点少于whole_polygon 中的节点:
print(len(G)) # gives 12812
G_am = ox.graph_from_polygon(amadora_pol, network_type='drive', simplify=True)
print(len(G_am)) # gives 3071 nodes
因此:3071 + 9719 =12790 and not 12812
我不明白错误在哪里或是否有任何错误。
【问题讨论】:
-
你用
simplify=False得到同样的效果吗? -
是的,它仍然给了我不同数量的节点
-
这样的话,你可以试试
retain_all=True吗?