问题描述
我正在使用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)
示例输出:
-
2020-10-04 11:37:28配置的osmnx 2020-10-04 11:37:28 已创建
bBox 3000 m 来自(40.7154,-73.9853): 40.74237961006479,40.68842038993522,-73.9497049233066,-74.02089507669339 -
2020-10-04 11:37:28将GeoDataFrame投影到+ proj = utm + zone = 18
+ ellps = wgs84 + datum = wgs84 + units = m + no_defs + type = crs -
2020-10-04 11:37:28将GeoDataFrame投影到epsg:4326
-
2020-10-04 11:37:28在1中从API请求多边形内的数据 请求
-
2020-10-04 11:37:29在进行HTTP POST之前暂停0秒 请求
-
2020-10-04 11:37:37从overpass-api.de下载25,341.0KB 2020-10-04 11:37:39已保存对缓存文件“ cache / 5c31a2f980a9dc4969b2dd7541ef5eff.json”的响应
-
2020-10-04 11:37:39在1个请求中从API获得了多边形内的所有几何数据
-
2020-10-04 11:37:39 196787 JSON响应中的元素(包括每个节点)。
-
2020-10-04 11:37:39将元素转换为几何
-
2020-10-04 11:37:42没有为https://www.openstreetmap.org/relation/7774552创建外部多边形
-
2020-10-04 11:37:42 30055在字典中创建的几何图形
-
2020-10-04 11:37:53为29679个几何创建了r树空间索引
-
2020-10-04 11:37:54确定了多边形内部的29669个几何形状
-
2020-10-04 11:37:54多边形过滤器删除了10个几何形状
- 最终GeoDataFrame中的
-
2020-10-04 11:37:56 29265几何
-
2020-10-04 11:37:56 从(40.7154,-73.9853)创建的bBox 3600.0 m :40.747775532077746,40.68302446792226,-73.94258590796792,-74.02801409203207
-
2020-10-04 11:37:57将GeoDataFrame投影到+ proj = utm + zone = 18 + ellps = wgs84 + datum = wgs84 + units = m + no_defs + type = crs
-
2020-10-04 11:37:57将GeoDataFrame投影到epsg:4326
-
2020-10-04 11:37:57将GeoDataFrame投影到+ proj = utm + zone = 18 + ellps = wgs84 + datum = wgs84 + units = m + no_defs + type = crs
-
2020-10-04 11:37:57将GeoDataFrame投影到epsg:4326
-
2020-10-04 11:37:57在1个请求中从API请求多边形内的数据
-
2020-10-04 11:37:57在发出HTTP POST请求之前暂停0秒
解决方法
简短的答案是您在最后调用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)