Search code examples
pythonnetworkxopenstreetmaposmnx

Retreiving building addresses between origin and destination


I am using OSMNx and trying to retrieve the addresses between Origin and destination point as shown in below figure.

  • Is it possible to extract the addresses between two points or Nodes?

enter image description here

import osmnx as ox
import networkx as nx
import matplotlib.pyplot as plt

address='45 Stodart St, Colac VIC 3250'
G = ox.graph_from_address(address, distance=500, network_type="drive")
fig1, ax1 = ox.plot_graph(G,node_size=0, edge_linewidth=0.5, dpi=250)
  • Is it possible to extract the addresses between two points or Nodes?

Solution

  • Is it possible to extract the addresses between two points or nodes?

    Yes:

    import osmnx as ox
    ox.config(use_cache=True, log_console=True)
    
    address = '20 W 34th St, Manhattan, NY, USA'
    G = ox.graph_from_address(address, dist=500, network_type='drive')
    
    # osmids of nodes at either end of block
    # or you could do this programmatically with ox.geocode and ox.get_nearest_node
    osmids = [42437644, 42430304]
    
    # bounding box around those nodes, buffered as needed
    polygon = ox.graph_to_gdfs(G, edges=False).loc[osmids, 'geometry'].unary_union.envelope
    polygon_proj, crs = ox.projection.project_geometry(polygon)
    polygon_buff, crs = ox.projection.project_geometry(polygon_proj.buffer(10), crs=crs, to_latlong=True)
    
    # get building footprints and show their addresses
    fp = ox.footprints_from_polygon(polygon)
    cols = [c for c in fp.columns if 'addr' in c]
    fp[cols]
    

    So yes, this is possible. But it is not possible for your specific desired location, because OpenStreetMap contains no building or address information there. The screenshot you posted is from Google Maps rather than OpenStreetMap.