Why are OSMnx footprints not filling up the entire image?

654 views Asked by At

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 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. enter image description here

  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:

enter image description here

1

There are 1 answers

2
gboeing On BEST ANSWER

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)

figure