userscript osm osmnx chemins
This commit is contained in:
parent
ce92dcacb0
commit
d3bf80c481
1
osm-itineraire-userscript/cache/4aa3239612a717c7675cf8a757d628b92124e20e.json
vendored
Normal file
1
osm-itineraire-userscript/cache/4aa3239612a717c7675cf8a757d628b92124e20e.json
vendored
Normal file
File diff suppressed because one or more lines are too long
1
osm-itineraire-userscript/cache/b995351c17ca33a7ccbe8fa427b09b6d3d81a462.json
vendored
Normal file
1
osm-itineraire-userscript/cache/b995351c17ca33a7ccbe8fa427b09b6d3d81a462.json
vendored
Normal file
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,14 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<svg baseProfile="full" height="200" version="1.1" viewBox="0 0 200 200" width="200" xmlns="http://www.w3.org/2000/svg"
|
||||||
|
>
|
||||||
|
<defs/>
|
||||||
|
<rect fill="#f9f9f9" height="200" width="200" x="0" y="0"/>
|
||||||
|
<path d="M 0.0010843654 0.0499234408 L 0.0010837509000000002 0.0499231158 M 0.0010837509000000002 0.0499231158 L 0.0010828001000000001 0.0499225948 M 0.0010828001000000001 0.0499225948 L 0.0010825184000000001 0.0499224404 M 0.0010825184000000001 0.0499224404 L 0.0010818006 0.0499226316 M 0.0010818006 0.0499226316 L 0.0010815867999999999 0.0499234258 M 0.0010815867999999999 0.0499234258 L 0.0010809724999999999 0.0499236092 M 0.0010809724999999999 0.0499236092 L 0.0010807002999999999 0.0499236039 M 0.0010807002999999999 0.0499236039 L 0.0010795367 0.0499235696 M 0.0010795367 0.0499235696 L 0.001078552 0.04992354189999999 M 0.001078552 0.04992354189999999 L 0.0010781686 0.049923533 M 0.0010781686 0.049923533 L 0.0010774013 0.0499235152 M 0.0010774013 0.0499235152 L 0.001076362 0.049923492699999995 M 0.001076362 0.049923492699999995 L 0.0010764354 0.0499239727"
|
||||||
|
fill="none" stroke="#00698f" stroke-width="2"/>
|
||||||
|
<path d="M 0.0010843654 0.0499234408 L 0.0010837509000000002 0.0499231158 M 0.0010837509000000002 0.0499231158 L 0.0010828001000000001 0.0499225948 M 0.0010828001000000001 0.0499225948 L 0.0010825184000000001 0.0499224404 M 0.0010825184000000001 0.0499224404 L 0.0010818006 0.0499226316 M 0.0010818006 0.0499226316 L 0.0010815867999999999 0.0499234258 M 0.0010815867999999999 0.0499234258 L 0.0010809724999999999 0.0499236092 M 0.0010809724999999999 0.0499236092 L 0.0010807002999999999 0.0499236039 M 0.0010807002999999999 0.0499236039 L 0.0010795367 0.0499235696 M 0.0010795367 0.0499235696 L 0.001078552 0.04992354189999999 M 0.001078552 0.04992354189999999 L 0.0010781686 0.049923533 M 0.0010781686 0.049923533 L 0.0010774013 0.0499235152 M 0.0010774013 0.0499235152 L 0.0010775613 0.0499240001 M 0.0010775613 0.0499240001 L 0.0010764354 0.0499239727"
|
||||||
|
fill="none" stroke="#aaaaaa" stroke-width="1"/>
|
||||||
|
<path d="M 0.0010843654 0.0499234408 L 0.0010837509000000002 0.0499231158 M 0.0010837509000000002 0.0499231158 L 0.0010828001000000001 0.0499225948 M 0.0010828001000000001 0.0499225948 L 0.0010825184000000001 0.0499224404 M 0.0010825184000000001 0.0499224404 L 0.0010818006 0.0499226316 M 0.0010818006 0.0499226316 L 0.0010815867999999999 0.0499234258 M 0.0010815867999999999 0.0499234258 L 0.0010809724999999999 0.0499236092 M 0.0010809724999999999 0.0499236092 L 0.0010807002999999999 0.0499236039 M 0.0010807002999999999 0.0499236039 L 0.0010806049 0.0499241392 M 0.0010806049 0.0499241392 L 0.0010803225999999999 0.0499241465 M 0.0010803225999999999 0.0499241465 L 0.0010796568 0.0499241637 M 0.0010796568 0.0499241637 L 0.0010795367 0.0499235696 M 0.0010795367 0.0499235696 L 0.001078552 0.04992354189999999 M 0.001078552 0.04992354189999999 L 0.0010781686 0.049923533 M 0.0010781686 0.049923533 L 0.0010774013 0.0499235152 M 0.0010774013 0.0499235152 L 0.001076362 0.049923492699999995 M 0.001076362 0.049923492699999995 L 0.0010764354 0.0499239727"
|
||||||
|
fill="none" stroke="#aaaaaa" stroke-width="1"/>
|
||||||
|
<circle cx="0.0010833" cy="0.0499242" fill="#ff0000" r="5"/>
|
||||||
|
<circle cx="0.0010764" cy="0.0499239" fill="#00ff00" r="5"/>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 3.3 KiB |
|
@ -0,0 +1,68 @@
|
||||||
|
import osmnx as ox
|
||||||
|
import svgwrite
|
||||||
|
|
||||||
|
# Définir les coordonnées de la plage de Dieppe et de la gare SNCF de Dieppe
|
||||||
|
start_point = (49.9242, 1.0833) # Plage de Dieppe
|
||||||
|
end_point = (49.9239, 1.0764) # Gare SNCF de Dieppe
|
||||||
|
|
||||||
|
# Charger le graphe routier de Dieppe
|
||||||
|
G = ox.graph_from_place('Dieppe, France', network_type='drive')
|
||||||
|
|
||||||
|
# Trouver les noeuds les plus proches des coordonnées de départ et d'arrivée
|
||||||
|
start_node = ox.nearest_nodes(G, start_point[1], start_point[0])
|
||||||
|
end_node = ox.nearest_nodes(G, end_point[1], end_point[0])
|
||||||
|
|
||||||
|
# Trouver le plus court chemin entre les deux points
|
||||||
|
route = ox.shortest_path(G, start_node, end_node, weight='length')
|
||||||
|
|
||||||
|
# Trouver les 3 plus courts chemins entre les deux points
|
||||||
|
routes = ox.k_shortest_paths(G, start_node, end_node, k=3, weight='length')
|
||||||
|
|
||||||
|
# Définir les dimensions du canevas
|
||||||
|
canvas_width = 200
|
||||||
|
canvas_height = 200
|
||||||
|
|
||||||
|
# Définir la bounding box des coordonnées géographiques
|
||||||
|
min_lat = min(node['y'] for node in G.nodes.values())
|
||||||
|
max_lat = max(node['y'] for node in G.nodes.values())
|
||||||
|
min_lon = min(node['x'] for node in G.nodes.values())
|
||||||
|
max_lon = max(node['x'] for node in G.nodes.values())
|
||||||
|
|
||||||
|
# Créer une matrice de transformation pour mapper les coordonnées géographiques au canevas
|
||||||
|
transform = svgwrite.transforms.Matrix()
|
||||||
|
transform.translate(-min_lon, -min_lat)
|
||||||
|
transform.scale(canvas_width / (max_lon - min_lon), canvas_height / (max_lat - min_lat))
|
||||||
|
|
||||||
|
# Créer un objet SVG
|
||||||
|
dwg = svgwrite.Drawing('itineraire_dieppe.svg', (canvas_width, canvas_height), viewBox=f"0 0 {canvas_width} {canvas_height}")
|
||||||
|
|
||||||
|
# Ajouter le fond de carte
|
||||||
|
dwg.add(dwg.rect(insert=(0, 0), size=(canvas_width, canvas_height), fill='#f9f9f9'))
|
||||||
|
|
||||||
|
# Dessiner le tracé de l'itinéraire principal
|
||||||
|
path = svgwrite.path.Path(stroke='#00698f', stroke_width=2, fill='none')
|
||||||
|
for i in range(len(route) - 1):
|
||||||
|
node1 = G.nodes[route[i]]
|
||||||
|
node2 = G.nodes[route[i + 1]]
|
||||||
|
path.push('M', *transform.apply(node1['x'], node1['y']))
|
||||||
|
path.push('L', *transform.apply(node2['x'], node2['y']))
|
||||||
|
dwg.add(path)
|
||||||
|
|
||||||
|
# Dessiner les tracés des chemins alternatifs
|
||||||
|
for i, route_alt in enumerate(routes):
|
||||||
|
if i == 0:
|
||||||
|
continue # skip the shortest path
|
||||||
|
path = svgwrite.path.Path(stroke='#aaaaaa', stroke_width=1, fill='none')
|
||||||
|
for j in range(len(route_alt) - 1):
|
||||||
|
node1 = G.nodes[route_alt[j]]
|
||||||
|
node2 = G.nodes[route_alt[j + 1]]
|
||||||
|
path.push('M', *transform.apply(node1['x'], node1['y']))
|
||||||
|
path.push('L', *transform.apply(node2['x'], node2['y']))
|
||||||
|
dwg.add(path)
|
||||||
|
|
||||||
|
# Ajouter des marques pour les points de départ et d'arrivée
|
||||||
|
dwg.add(dwg.circle(center=transform.apply(*start_point), r=5, fill='#ff0000'))
|
||||||
|
dwg.add(dwg.circle(center=transform.apply(*end_point), r=5, fill='#00ff00'))
|
||||||
|
|
||||||
|
# Enregistrer le fichier SVG
|
||||||
|
dwg.save()
|
Loading…
Reference in New Issue