1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| import numpy as np
import matplotlib.pyplot as plt
import overpy
import mplcursors
from haversine import haversine, Unit
import time
start = time.time()
api = overpy.Overpass()
r = api.query("""
area["ISO3166-1"="FR"][admin_level=2];
(node["station"="subway"](area););
out center;
""")
end = time.time()
print("temps de récupération des coordonnées : " + str(end-start) + " secondes")
start = time.time()
noms = []
coords = []
coords += [(float(node.lon), float(node.lat))
for node in r.nodes]
noms += [node.tags['name'] for node in r.nodes]
X = np.array(coords)
plt.plot(X[:, 0], X[:, 1], 'o')
plt.title('Stations de métro en France')
plt.xlabel('Longitude')
plt.ylabel('Latitude')
plt.axis('equal')
mplcursors.cursor(hover=True).connect("add", lambda sel: sel.annotation.set_text(noms[sel.index]))
end = time.time()
print("temps de tracé des coordonnées : " + str(end-start) + " secondes")
resultat=[]
start = time.time()
for pt1 in coords:
for pt2 in coords:
res = haversine(pt1, pt2, unit='m')
if 400 < res < 450:
plt.plot([pt1[0],pt2[0]],[pt1[1],pt2[1]],color = 'red', linestyle = 'solid')
resultat.append(res)
end = time.time()
print("temps de calcul des distances : " + str(end-start) + " secondes")
plt.show() |