【问题标题】:Why are OSMnx footprints not filling up the entire image?为什么 OSMnx 足迹没有填满整个图像?
【发布时间】:2023-03-24 14:05:01
【问题描述】:

我正在使用here 提供的辅助函数,对距离和颜色进行了一些修改。我在没有更改的情况下尝试了它,结果相同。我注意到如果我使用“自然”标签,水道会延伸到数字之外,但我没有在这些中使用它,只是“建筑”。

正在使用的代码:

import osmnx as ox
from IPython.display import Image
ox.config(log_console=True, use_cache=True)
bgcolor="#343434"
edge_color="#FFB0E2"
bldg_color="#F4FF6E"

point = (40.7154,-73.9853)
place = 'New York City, NY'
dist = 3000
dpi = 100

# helper funcion to get one-square-mile street networks, building. 
footprints, and plot them
def make_plot(place, point, dist, network_type='all', 
    bldg_color=bldg_color, dpi=dpi,
            default_width=0.5,
            street_widths = {
                "footway": 0.25,
                "steps": 0.25,
                "pedestrian": 0.25,
                "service": 0.25,
                "path": 0.25,
                "track": 0.25,
                "primary": 1,
                "secondary": 0.5,
                "motorway": 2 ,
                }):
    tags = {
        #'amenity':True,
        'building':True,
        #'geological':True,
        #'historic':True,
        #'landuse':['retail', 'commercial'],
        #'natural':True,
        #'waterway':True,
        }
    gdf = ox.geometries.geometries_from_point(center_point=point, 
          tags=tags, dist=dist)
    fig, ax = ox.plot.plot_figure_ground(point=point, dist=dist, 
              network_type=network_type,
              default_width=default_width, 
              street_widths=street_widths,
              edge_color=edge_color ,save=False, show=False, 
              close=True, bgcolor=bgcolor)
    fig, ax = ox.plot.plot_footprints(gdf, ax=ax, color=bldg_color,
                            save=True, show=False, close=True,
                            filepath="images/us_cities/{}-dist{}- 
                            dpi{}.png".format(place,dist,dpi), dpi=dpi)

make_plot(place, point, dist)

示例输出:

  1. 足迹没有延伸到图像的边缘。图像顶部和底部的空白边距

  2. 图像左右边距,足迹不延伸到边缘。

  3. 较大的边距和足迹未填充图像。我在生成地图时注意到日志中有一些东西;创建了两个不同大小的 bbox。它们在下面的日志条目中以粗体显示:

【问题讨论】:

  • 请参阅 StackOverflow 的指南,了解如何在本网站提出问题以及如何提供完整的最小工作示例以允许其他人回答您的问题。
  • 我更新了问题

标签: osmnx


【解决方案1】:

简短的回答是你最后调用plot_footprints,但没有传递bbox 参数。因此,根据the docs,它会根据几何图形的空间范围计算要显示的图形边界框。与您的查询区域相交的一些几何图形也远远超出了它。创建一个与您的查询区域匹配的 bbox 并将其传递给绘图函数。

这是一个简化但完整的工作示例。

import osmnx as ox
ox.config(log_console=True, use_cache=True)

bgcolor = '#343434'
edge_color = '#FFB0E2'
bldg_color = '#F4FF6E'
point = (40.7154,-73.9853)
dist = 3000

bbox = ox.utils_geo.bbox_from_point(point, dist=dist)
fp = ox.geometries_from_point(point, tags={'building':True}, dist=dist)
G = ox.graph_from_point(point, network_type='drive', dist=dist, truncate_by_edge=True, retain_all=True)

fig, ax = ox.plot_graph(G, bgcolor=bgcolor, node_size=0, edge_color=edge_color, show=False)
fig, ax = ox.plot_footprints(fp, ax=ax, bbox=bbox, color=bldg_color, save=True)

【讨论】:

  • 有没有办法让水体与建筑脚印分开颜色? This post 谈论填充水体,但我认为它是在 v0.16 之前,如果我在上面的地图上添加“自然”标签,它会填充它们,但颜色与建筑物相同。
  • 下载一个单独的 geometries_from_point 然后也绘制这些足迹。
猜你喜欢
  • 1970-01-01
  • 2014-04-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-03-25
  • 1970-01-01
相关资源
最近更新 更多