diff --git a/__pycache__/coord_to_intersections.cpython-38.pyc b/__pycache__/coord_to_intersections.cpython-38.pyc index 4e434e589c9f348322a23a18123b699838c1e18e..28d62caf207a3a0fc43ea6b8353d4b7d8ead0dcd 100644 Binary files a/__pycache__/coord_to_intersections.cpython-38.pyc and b/__pycache__/coord_to_intersections.cpython-38.pyc differ diff --git a/__pycache__/request.cpython-38.pyc b/__pycache__/request.cpython-38.pyc index 454e263dc447ff9d2e00c723570c962dccb8a888..f2d7bc282e9d2d99e690ff0bac818d90e7e9312d 100644 Binary files a/__pycache__/request.cpython-38.pyc and b/__pycache__/request.cpython-38.pyc differ diff --git a/__pycache__/request2.cpython-38.pyc b/__pycache__/request2.cpython-38.pyc index 2d6200b60d09ad0827b735dc5ac0aa896231d5ec..2706939884af8b3792d4bf002d805634c1a2ab10 100644 Binary files a/__pycache__/request2.cpython-38.pyc and b/__pycache__/request2.cpython-38.pyc differ diff --git a/__pycache__/research.cpython-38.pyc b/__pycache__/research.cpython-38.pyc index 95da01e8ab97a032581d32d5198493c24133f2be..93e98b12919c39a7ab7e7ed717d0bc3c49314af2 100644 Binary files a/__pycache__/research.cpython-38.pyc and b/__pycache__/research.cpython-38.pyc differ diff --git a/coord_to_intersections.py b/coord_to_intersections.py index 082d1e7f15dee365b0e946424d13468709a93f3b..92b37ce74b365098e5c6aec6f0cda18df999ff71 100644 --- a/coord_to_intersections.py +++ b/coord_to_intersections.py @@ -11,7 +11,16 @@ def coord_to_inter(liste_coord,lat,long,main_street): dist.append(d) while len(inter_street)<1 : #On regarde l'intersection la plus proche de l'arbre - candidat=liste_coord[dist.index(min(dist))] + print('nouveau candidat') + try: + candidat=liste_coord[dist.index(min(dist))] + except ValueError: + inter_street.append(main_street) + inter_street_coord.append([long, lat]) + inter_street.append(main_street) + inter_street_coord.append([long, lat]) + print('aucune intersection trouvée') + return inter_street+inter_street_coord #On regarde si cette intersection correspond bien au croisement avec une autre rue, on trouve le nom de cette autre rue nom_de_rue=circular_research(candidat[1], candidat[0], main_street) if nom_de_rue== None : @@ -28,6 +37,7 @@ def coord_to_inter(liste_coord,lat,long,main_street): dist.pop(indice) liste_coord.pop(indice) print('Début du tronçon trouvé') + print(inter_street[0]) #Recherche de la fin du tronçon liste_coord_admissibles = [] d_1_2 = [] @@ -43,7 +53,14 @@ def coord_to_inter(liste_coord,lat,long,main_street): dist2.append(dist[i]) while len(inter_street)<2 : #On regarde l'intersection admissible la plus proche du début du tronçon - candidat=liste_coord_admissibles[d_1_2.index(min(d_1_2))] + print('nouveau candidat 2') + try: + candidat=liste_coord_admissibles[d_1_2.index(min(d_1_2))] + except ValueError: + inter_street.append(inter_street[0]) + inter_street_coord.append(inter_street_coord[0]) + print("Arbre au niveau de l'intersection") + return inter_street+inter_street_coord nom_de_rue=circular_research(candidat[1], candidat[0], main_street) if nom_de_rue== None : #Si cette intersection ne donne rien, on la rejette diff --git a/main.py b/main.py index 8743d4f93312935cf9484c87e978f4a3d84d3789..b56b503a3e3ed0523fce912271ce3f1c491901c6 100644 --- a/main.py +++ b/main.py @@ -2,10 +2,12 @@ from request import requete_osm from coord_to_intersections import coord_to_inter from request2 import search_osm, all_intersect from ordre_arbres import ordre_arbre +import time def tree_position(lat, lon): req = requete_osm(lat, lon) main_street = req['address']['road'] + print(main_street) city = req['address']['town'] country = req['address']['country'] json = search_osm(main_street, city, country) @@ -44,9 +46,11 @@ def classement_arbres(liste_coord): if __name__=="__main__": - lat = 48.89627806 - lon = 2.248657510 + t1 = time.time() + lat, lon = 48.892046, 2.249319 print(tree_position(lat, lon)) + t2 = time.time() + print(t2-t1) ''' lat = 48.89227652 lon = 2.253773690 diff --git a/request.py b/request.py index 7f87b5ba435d4104c19114bb5e8dd2f2b002b03b..16b9ddd173ac867917807f7b8ce3cf150e105165 100644 --- a/request.py +++ b/request.py @@ -22,15 +22,24 @@ if __name__=="__main__": # coordinates =[49.15,2.325] # intersection : 48.895307, 2.247367 48.894596, 2.247958 48.853994, 2.247177 48.894998, 2.247467 #g = geocoder.osm([48.89, 2.247], method='reverse') + lat, lon = 48.89394122, 2.247959188 params = { - 'lat':48.89394122, + 'lat':lat, + 'lon':lon, + 'format':'json', + 'zoom': 17, + 'polygon_geojson' : 1 + } + params2 = { + 'lat':48.89494122, 'lon':2.247959188, 'format':'json', 'zoom': 17, 'polygon_geojson' : 1 } + req = requests.get("https://nominatim.openstreetmap.org/reverse",params) - print(req.headers) + #print(req.headers) reqJson = req.json() - #print(reqJson) #['geojson']['coordinates'] + print(reqJson) #['geojson']['coordinates'] diff --git a/research.py b/research.py index b1f28c7a69dbf1cb6d567c85b100001dbfa732d5..ab83ab6fb48dd3eb19f738f597af01b000b505e2 100644 --- a/research.py +++ b/research.py @@ -1,18 +1,23 @@ from request import requete_osm -from math import sqrt +from math import sqrt, sin, cos, pi +from concurrent.futures import ThreadPoolExecutor +import time def circular_research(lat, lon, main_street): #Recherche un rue autre que main_street par recherche circulaire autour du point d'intersection - street = requete_osm(lat, lon)['address']['road'] + try: + street = requete_osm(lat, lon)['address']['road'] + except KeyError: + street = '' if not(street == main_street) and not(street == ''): return street - step = 10**(-5) - while step < 4*10**(-5): + step = 5*10**(-5) + while step < 6*10**(-5): for i in range(8): street = check_position(lat, lon, step, main_street, i) if not(street == main_street) and not(street == ''): return street - step += 10**(-5) + step += 4*10**(-5) return None def check_position(lat, lon, step, main_street, i): @@ -60,3 +65,37 @@ def check_position(lat, lon, step, main_street, i): except KeyError: pass return street + + +def multi_position(lat, lon, step): + latitude = [] + longitude = [] + for j in range(1,4): + stp = j*step + for i in range(8): + latitude.append(lat+stp*cos(i*2*pi/8)) + longitude.append(lon+stp*sin(i*2*pi/8)) + with ThreadPoolExecutor(max_workers=30) as executor: + streets = executor.map(requete_osm, latitude, longitude) + executor.shutdown(wait=True) + return streets + +if __name__=="__main__": + lat = 48.89494122 + lon = 2.247959188 + step = 10**(-5) + main_street = 'Avenue Gambetta' + t1 = time.time() + streets = multi_position(48.89494122, 2.247959188, 10**(-5)) + t2 = time.time() + #print(len(list(streets))) + print(t2-t1) + t1 = time.time() + for j in range(1,4): + stp = j*step + for i in range(8): + check_position(lat, lon, stp, main_street, i) + t2 = time.time() + print(t2-t1) + +