为什么OSMnx占用空间无法填满整个图像?

问题描述

我正在使用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,filepath="images/us_cities/{}-dist{}- 
                            dpi{}.png".format(place,dpi),dpi=dpi)

make_plot(place,dist)

示例输出

  1. 脚印不会延伸到图像的边缘。图片顶部和底部的空白边距

    Footprint does not extend to the edge of the image.  Empty margin on top and bottom of image

  2. 图像左侧和右侧的边距,覆盖区不会延伸到边缘。

    enter image description here

  3. 大页边距和占用空间未填充图像。在生成地图时,我在日志中注意到了一些东西。创建了两个大小不同的bBox。它们在以下日志条目中以粗体显示

enter image description here

解决方法

简短的答案是您在最后调用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)

figure