【问题标题】:OSMNX : How to plot nodes only?OSMNX:如何仅绘制节点?
【发布时间】:2020-07-25 11:14:19
【问题描述】:

我尝试用树木绘制地图。这些是 openstreetmap 中的节点,所以我想知道是否可以仅绘制带有节点的地图,它们之间没有边缘?

这是我的代码:

place=['Saint-Egreve,France']
G = ox.graph_from_place(place,retain_all=True,truncate_by_edge=True,simplify=False, network_type='none',infrastructure='node[natural=tree]')
fig, ax = ox.plot_graph(ox.project_graph(G))

返回错误:

Traceback (most recent call last):
  File "./test.py", line 102, in <module>
    fig, ax = ox.plot_graph(ox.project_graph(G))
  File "/home/syl20/.conda/envs/ox/lib/python3.8/site-packages/osmnx/plot.py", line 362, in plot_graph
    west, south, east, north = edges.total_bounds
  File "/home/syl20/.conda/envs/ox/lib/python3.8/site-packages/pandas/core/generic.py", line 5274, in __getattr__
    return object.__getattribute__(self, name)
  File "/home/syl20/.conda/envs/ox/lib/python3.8/site-packages/geopandas/base.py", line 523, in total_bounds
    return GeometryArray(self.geometry.values).total_bounds
  File "/home/syl20/.conda/envs/ox/lib/python3.8/site-packages/pandas/core/generic.py", line 5274, in __getattr__
    return object.__getattribute__(self, name)
  File "/home/syl20/.conda/envs/ox/lib/python3.8/site-packages/geopandas/geodataframe.py", line 101, in _get_geometry
    raise AttributeError(
AttributeError: No geometry data set yet (expected in column 'geometry'.

感谢您的宝贵帮助!

西尔万

【问题讨论】:

    标签: python python-3.x osmnx


    【解决方案1】:

    试试这个:

    import osmnx as ox
    import matplotlib.pyplot as plt
    
    place = 'Saint-Egreve,France'
    graph = ox.graph_from_place(place)
    
    # Plot the streets
    fig, ax = ox.plot_graph(graph)
    
    # Retrieve nodes and edges
    nodes, edges = ox.graph_to_gdfs(graph)
    nodes.head()
    
    # Plot the nodes
    fig, ax = plt.subplots(figsize=(12,8))
    nodes.plot(ax=ax, facecolor='black')
    

    【讨论】:

    • 嗨威廉,感谢您的帮助,但这段代码没有做我想要的。 G=ox.graph_from_place(place,network_type='none',infrastructure='node[natural=tree]') 给我:raise nx.NetworkXPointlessConcept(networkx.exception.NetworkXPointlessConcept:空图未定义连接性。,所以我无法绘制任何东西。
    • 不,它不能工作,因为树没有被映射为 POI,而是作为简单的节点。感谢您分享此链接,它对我解决其他问题有很大帮助;-)
    【解决方案2】:

    我真的不知道如何用osmnx获取树木数据,但是如果树木数据是以geopandas格式收集的,并且上面有geometry列,它可以与节点数据绘制在相同的轴上(节点数据也必须是 geopandas 格式)。

    但请确保将两个数据绘制在相同的轴上。

    代码如下: 创建空白轴

    hf, ha = plt.subplots()

    空白轴是'ha'

    将节点和树绘制到空白轴中

    nodes_data_in_geopandas_format.plot(color="blue", ax=ha) trees_data_in_geopandas_format.plot(color="red", ax=ha)

    【讨论】:

      猜你喜欢
      • 2019-12-08
      • 1970-01-01
      • 2019-06-18
      • 1970-01-01
      • 2020-07-16
      • 1970-01-01
      • 2020-09-04
      • 2020-10-04
      • 2020-11-07
      相关资源
      最近更新 更多