Роутеры
Размещение роутеров
Вычисление расстояний между роутерами
import osmnx as ox
import networkx as nx
import csv
points = [[37.618886,54.204617,"0648078a-9d45-4577-af14-12b49e8f017b"],
[37.5826629190378,54.1688958982062,"6422a0a5-2c2d-4610-bebc-91722ea37827"],
[37.5931054621157,54.1854456631672,"b17aefd3-8431-4054-a0b5-b0a26eeb9f14"],
[37.5726628595483,54.1691301221863,"92c1cc9e-cfa4-4ef0-91f0-c0a158f547e7"],
[37.6230252453024,54.2347433816421,"f0058c02-034f-429a-b932-8638089d8718"],
[37.616479,54.191903,"37cea6a6-eaaa-4e12-9b4b-b444163a2cc8"],
[37.622509,54.2128,"07190dec-be71-44a2-8d64-c24fb51ebc7b"],
[37.611688,54.195984,"8a823f01-771f-420e-8971-928cba314a24"],
[37.625018,54.218076,"8a734674-e451-4fe1-8b50-3b3b46e334a1"],
[37.622566,54.189654,"cdcab165-cc3a-460f-ae99-024216190ab1"],
[37.604794,54.18133,"64642101-76de-4d38-9a09-c595b0c310d5"],
[37.614096,54.193204,"b42c687a-0dc2-49d1-9d6e-0d9e514d29bf"],
[37.6286864157148,54.2276569624141,"4cf88651-6c76-46a4-80d0-5dea3e5bcce2"],
[37.6245072514748,54.2333462654037,"7a04763d-e3ba-4e45-b1df-1d322a449030"],
[37.67935,54.219052,"4deed344-b28a-4ecb-818e-252e4fc70a97"],
[37.6182365086987,54.2413214831852,"86b9b151-ae96-45b1-97b2-20558726245c"],
[37.627888,54.191341,"3d9490f4-fb08-4c4c-80ec-ca744a6d9ab4"],
[37.6119371506259,54.2491761841739,"be579fae-23ff-48ed-a400-0691c6075faa"],
[37.625265,54.190082,"7080fd33-a510-4b1a-af7e-99fb5abc29d7"],
[37.620844,54.2101,"5481c7a7-fd20-4b84-afb9-d7d2afd599e6"],
[37.5855121948686,54.1714546891764,"6bd0d45b-c204-4d89-87eb-ff08c5e906ec"],
[37.5799264475165,54.1666267574838,"7bc69835-bbd1-4fc3-b742-6101e3e1e32f"],
[37.5754334510529,54.1718766491252,"1aa15d03-6814-40c2-9b57-34a55ae7951b"],
[37.619014,54.191034,"090a6502-bfc4-4d39-bc94-b0519fee04d6"],
[37.5946593824111,54.1646166190679,"7d460e9e-4351-4a42-b7e9-40addd0b01c5"],
[37.5974766750285,54.1839287967087,"37ab13f5-8c0b-4ece-b4fb-e1cf070bab95"],
[37.619966,54.208412,"c2fa0fb8-03c9-4eb2-900f-f0d140128a5f"],
[37.614644,54.200674,"0b91ef8c-3b4f-4a39-b3a3-9683c6fd7832"],
[37.619182,54.205679,"a8c8525e-cfcf-416f-88dd-bf1efc79df00"]
]
with open("marshruts_lengts.csv","w") as file:
writer = csv.writer(file)
writer.writerow(("from","from_guid","to","to_guid","length"))
mode = 'drive'
optimizer = 'length'
center = (54.203918, 37.618391) # меняем местами
graph = ox.graph_from_point(center, 10000, dist_type='network', simplify=True)
for i in range(0,len(points)):
for j in range(0,len(points)):
if i == j:
continue
orig_node = ox.distance.nearest_nodes(graph,points[i][0],points[i][1])
dest_node = ox.distance.nearest_nodes(graph, points[j][0],points[j][1])
shortest_route = nx.shortest_path(graph, orig_node,dest_node,
weight=optimizer)
length = nx.shortest_path_length(G=graph, source=orig_node, target=dest_node, weight='length')
newRow = [str(points[i][0]) + ' ' + str(points[i][1]),points[i][2],str(points[j][0]) + ' ' + str(points[j][1]),points[j][2],length]
with open("marshruts_lengts.csv","a") as file:
writer = csv.writer(file)
writer.writerow(newRow)
Результат
Датасет
https://storage.yandexcloud.net/roadgraph/marshruts_lengts.csv