Why are OSMnx footprints not filling up the entire image?

北城余情 提交于 2021-01-29 09:00:48

问题


I'm using the helper function provided here with some modifications for distance and color. I tried it without my changes and it has the same result. I noticed if I used the 'natural' tag that water ways will extend past the figure but I'm not using it in these, only 'building'.

Code being used:

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)

Example output:

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

  2. Margin on left and right of image, footprint doesn't extend to edges.

  3. Large margin and footprint not filling image. I noticed something in the logs while it was generating the map; two bboxes of different sizes are created. They are bold in the log entries below:

  • 2020-10-04 11:37:28 Configured osmnx 2020-10-04 11:37:28 Created
    bbox 3000 m
    from (40.7154, -73.9853): 40.74237961006479,40.68842038993522,-73.9497049233066,-74.02089507669339

  • 2020-10-04 11:37:28 Projected GeoDataFrame to +proj=utm +zone=18
    +ellps=WGS84 +datum=WGS84 +units=m +no_defs +type=crs

  • 2020-10-04 11:37:28 Projected GeoDataFrame to epsg:4326

  • 2020-10-04 11:37:28 Requesting data within polygon from API in 1 request(s)

  • 2020-10-04 11:37:29 Pausing 0 seconds before making HTTP POST request

  • 2020-10-04 11:37:29 Post
    http://overpass-api.de/api/interpreter?data=%5Bout%3Ajson%5D%5Btimeout%3A180%5D%3B%28%28node%5B%27building%27%5D%28poly%3A%2740.688420+-74.020895+40.688420+-73.949705+40.742380+-73.949705+40.742380+-74.020895+40.688420+-74.020895%27%29%3B%28._%3B%3E%3B%29%3B%29%3B%28way%5B%27building%27%5D%28poly%3A%2740.688420+-74.020895+40.688420+-73.949705+40.742380+-73.949705+40.742380+-74.020895+40.688420+-74.020895%27%29%3B%28._%3B%3E%3B%29%3B%29%3B%28relation%5B%27building%27%5D%28poly%3A%2740.688420+-74.020895+40.688420+-73.949705+40.742380+-73.949705+40.742380+-74.020895+40.688420+-74.020895%27%29%3B%28._%3B%3E%3B%29%3B%29%3B%29%3Bout%3B with timeout=180

  • 2020-10-04 11:37:37 Downloaded 25,341.0KB from overpass-api.de 2020-10-04 11:37:39 Saved response to cache file "cache/5c31a2f980a9dc4969b2dd7541ef5eff.json"

  • 2020-10-04 11:37:39 Got all geometry data within polygon from API in 1 request(s)

  • 2020-10-04 11:37:39 196787 elements in the JSON responses (includes every node).

  • 2020-10-04 11:37:39 Converting elements to geometries

  • 2020-10-04 11:37:42 No outer polygons were created for https://www.openstreetmap.org/relation/7774552

  • 2020-10-04 11:37:42 30055 geometries created in the dict

  • 2020-10-04 11:37:42 376 untagged geometries removed

  • 2020-10-04 11:37:53 Created r-tree spatial index for 29679 geometries

  • 2020-10-04 11:37:54 Identified 29669 geometries inside polygon

  • 2020-10-04 11:37:54 10 geometries removed by the polygon filter

  • 2020-10-04 11:37:54 413 geometries removed by the tag filter

  • 2020-10-04 11:37:56 29265 geometries in the final GeoDataFrame

  • 2020-10-04 11:37:56 Created bbox 3600.0 m from (40.7154, -73.9853): 40.747775532077746,40.68302446792226,-73.94258590796792,-74.02801409203207

  • 2020-10-04 11:37:57 Projected GeoDataFrame to +proj=utm +zone=18 +ellps=WGS84 +datum=WGS84 +units=m +no_defs +type=crs

  • 2020-10-04 11:37:57 Projected GeoDataFrame to epsg:4326

  • 2020-10-04 11:37:57 Projected GeoDataFrame to +proj=utm +zone=18 +ellps=WGS84 +datum=WGS84 +units=m +no_defs +type=crs

  • 2020-10-04 11:37:57 Projected GeoDataFrame to epsg:4326

  • 2020-10-04 11:37:57 Requesting data within polygon from API in 1 request(s)

  • 2020-10-04 11:37:57 Pausing 0 seconds before making HTTP POST request


回答1:


The short answer is you are calling plot_footprints at the end, but not passing it a bbox argument. So, per the docs, it calculates the figure's bounding box to display from the spatial extents of the geometries. Some of the geometries that intersect your query area also extend far beyond it. Create a bbox that matches your query area and pass it to the plotting function.

Here's a simplified but complete working example.

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)



来源:https://stackoverflow.com/questions/64186657/why-are-osmnx-footprints-not-filling-up-the-entire-image

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!