-1

New to GIS and OSMnx, thank you for your help!

Konwn: One area generated by Osmnx, Several points with (lon, lat) coordinates in the area (I think that is what we call 'POI')

Question: How to connect and interpolate this ponits to the area, and then merge then into a new Multidigraph that can be handled by OSMnx. (I want to calculate the shortest path of nodes in the new graph, so I have to merge it first.)

If you need specific data and area of the aforementioned konwn part, please let me know and I will attach it.

wzwqlx
  • 1
  • 3

1 Answers1

0

The first step is to create the new Multidigraph from the points, using the Multidigraph.from_points() method:

Multidigraph.from_points(points, source_id='puntos_osm') #source_id is optional

Multidigraph(points=[[(37.23, -121.39), (37.21, -121.39), (37.22, -121.41)], [(37.23, -121.39), (37.23, -121.39), (37.23, -121.39)], [(37.23, -121.39), (37.23, -121.39), (37.23, -121.39)], [(37.23, -121.39), (37.23, -121.39), (37.23, -121.39)], [(37.23, -121.39), (37.23, -121.39), (37.23, -121.39)], [(37.23, -121.39), (37.23, -121.39), (37.23, -121.39)]], id='multido')

The next step is to interpolate the points using the interpolation package.

from interpolate import Interpolate # you can use your own interpolation routine if you want

Multidigraph.from_points(points, source_id='puntos_osm') interpolated = Interpolate(interpolate_kwargs={'method': 'nearest'}) Multidigraph(points=[[(37.23, -121.39), (37.21, -121.39), (37.22, -121.41)], [(37.23, -121.39), (37.23, -121.39), (37.23, -121.39)], [(37.23, -121.39), (37.23, -121.39), (37.23, -121.39)], [(37.23, -121.39), (37.23, -121.39), (37.23, -121.39)], [(37.23, -121.39), (37.23, -121.39), (37.23, -121.39)], [(37.23, -121.39), (37.23, -121.39), (37.23, -121.39)]], id='multido')

Merging the new Multidigraph into the destination Multidigraph

The new Multidigraph can be now merged into the destination Multidigraph, using the Multidigraph.merge_from() method: destination_multidigraph.merge_from(interpolated, source_id='interpolated') Destination Multidigraph:

Multidigraph(points=[[(37.23, -121.39), (37.21, -121.39), (37.22, -121.41)], [(37.23, -121.39), (37.23, -121.39), (37.23, -121.39)], [(37.23, -121.39), (37.23, -121.39), (37.23, -121.39)], [(37.23, -121.39), (37.23, -121.39), (37.23, -121.39)], [(37.23, -121.39), (37.23, -121.39), (37.23, -121.39)], [(37.23, -121.39), (37.23, -121.39), (37.23, -121.39)], [(37.23, -121.39), (37.23, -121.39), (37.23, -121.39)], [(37.23, -121.39), (37.23, -121.39), (37.23, -121.39)], [(37.23, -121.39), (37.23, -121.39), (37.23, -121.39)], [(37.23, -121.39), (37.23, -121.39), (37.23, -121.39)]], id='destination_multido')

This new Multidigraph can now be used as a source for any other Osmnx methods. For example, it can be converted to a Shapely Polygon destination_multidigraph.to_poly(name='merged_multido') (37.23 -121.39, 37.21 -121.39, 37.22 -121.41)

c0d3x27
  • 193
  • 2
  • 15
  • First, you will need to convert the data to lines. Then, you will need to make a polygon out of the new lines. Finally, merge the polygon into a Multidigraph. – c0d3x27 Aug 04 '22 at 14:48
  • There is no function named '''Multidigraph.from_points()''' – wzwqlx Aug 05 '22 at 01:16
  • is not a function but a method. Function: Standalone feature or functionality. Method: One way of doing something, which has different approaches or methods, but is related to the same aspect, a class. In case you don't feel comfortable using multidigraph you can use DiGraph.() which is a function – c0d3x27 Aug 05 '22 at 03:07
  • [info](https://networkx.org/documentation/stable/reference/classes/multidigraph.html) here is the dommentations to read more about the differences. – c0d3x27 Aug 05 '22 at 03:14
  • Frankly speaking, far from my idea, thanks anyway. – wzwqlx Aug 08 '22 at 07:29