pythongoogle-street-viewosmnxgoogle-street-view-static-api

Using geographical graph data to guide Google Street View Static API


I am trying to use geographical data - streets and intersections - derived from osmnx together with the Google Street View Static API to get street view images that are

  1. Taken from a intersection.
  2. Looks directly down the road.

I have used osmnx (see code below) to get data that looks like this:

Nodes:

(NodeView((298466819, 20925446, 298466822, ...

And edges:

OutMultiEdgeView([(298466819, 8324095, 0), (298466819, 298466822, 0), (298466822, 8324094, 0), ...

So I can draw maps like this:

enter image description here

It can easily be converted to lat/long coordinates if that helps.

Using the Google API is quite simple with the google_streetview api:

import google_streetview.api

# Define parameters for street view api
params = [{
    'size': '640x640', # max 640x640 pixels
    'location': '55.6901769, 12.5595158',
    'heading': '0',
    'pitch': '0',
    'key': '--'
}]

# Create a results object
results = google_streetview.api.results(params)

results.preview()

What I need help to figure out, is, that given the nodes and edges, can I calculate the heading parameter for each node, such that I get at least one image from the node looking down the street?


Road map graph data:

import osmnx as ox
location_point = (55.6901, 12.5638)
G_nbro = ox.graph_from_point(location_point, distance=500, distance_type='network', network_type='drive')

Related:

Getting the POV for Google StreetView API

Is there a way to use the Google Street View API and only return "side view"?


Solution

  • I figured it out.

    1. Get all connecting neighbours to a node:
    nodes_dict = {node:nx.neighbors(G_nbro, node) for node in G_nbro.nodes}
    
    for node in nodes_dict.keys():
        for nbr in nodes_dict[node]:
            print(node, nbr)
    
    1. Get headings between each point. One point example here:
    G_nbro[8322831][4555480822][0]['bearing']
    
    311.045
    

    Plug into Google API and it works beautifully.