0

I'm following gboeing's reply in this post https://github.com/gboeing/osmnx/issues/269 and using the osmnx Docker image, but I'm getting the error AttributeError: module 'osmnx' has no attribute 'great_circle_vec'

The Docker does seem to have the latest 0.16 osmnx version, and the current doc does not mention this function being deprecated or private. The suggested code is a year and a half old, so maybe something has changed. Does anyone have a current solution for getting the nearest node along the nearest edge?

2 Answers2

0

Use osmnx.distance.great_circle_vec(args) https://osmnx.readthedocs.io/en/stable/osmnx.html#osmnx.distance.great_circle_vec

gboeing
  • 5,691
  • 2
  • 15
  • 41
  • Thanks for pointing that out. Should have been obvious in hindsight. But I do have a question about your response to the original question, which was to find the nearest point on the nearest edge. I see that your built-in solution finds the nearest node of the nearest edge. Is there a built-in way in osmnx to get the coordinates for the nearest point on the nearest edge? – Jamie Burks Sep 16 '20 at 18:24
  • Nope, not built in. – gboeing Sep 16 '20 at 18:25
  • 1
    Thanks. I was able to do this with part of the code in the original post. I'll post it here just in case anyone is interested. – Jamie Burks Sep 16 '20 at 23:25
0

I case anyone is interested, I was able to write some code based on the original github issue to get the nearest lat/lng on the nearest edge. It looks something like this:

def nearest_point_on_edge(G, lat, lng, edge):
    ''' Return nearest point to lat/lng on edge 
    '''
    orig_point = Point(lng, lat)
    a_point = Point(G.nodes[edge[0]]['x'], G.nodes[edge[0]]['y'])
    b_point = Point(G.nodes[edge[1]]['x'], G.nodes[edge[1]]['y'])
    a_latlng = (G.nodes[edge[0]]['y'], G.nodes[edge[0]]['x'])
    b_latlng = (G.nodes[edge[1]]['y'], G.nodes[edge[1]]['x'])
    dist_ab = LineString([a_point, b_point]).project(orig_point)
    projected_orig_point = list(LineString([a_point, b_point]).interpolate(dist_ab).coords)
    nearest_latlng = (projected_orig_point[0][1], projected_orig_point[0][0])
    return nearest_latlng