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)