Skip to content
Snippets Groups Projects
Commit 7e4bbdde authored by Alexandre Pradeilles's avatar Alexandre Pradeilles
Browse files

tache 1 full

parent 6068f925
Branches
No related tags found
No related merge requests found
No preview for this file type
No preview for this file type
File added
No preview for this file type
from research import circular_research
from copy import deepcopy
def coord_to_inter(liste_coord,lat,long,main_street):
dist=[]
inter_street=[]
......@@ -8,6 +10,7 @@ def coord_to_inter(liste_coord,lat,long,main_street):
dist.append(d)
while len(inter_street)<1 :
candidat=liste_coord[dist.index(min(dist))]
#print(candidat)
nom_de_rue=circular_research(candidat[1], candidat[0], main_street)
if nom_de_rue== None :
indice=dist.index(min(dist))
......@@ -17,33 +20,123 @@ def coord_to_inter(liste_coord,lat,long,main_street):
inter_street.append(nom_de_rue)
inter_street_coord.append(candidat)
indice=dist.index(min(dist))
d_1 = min(dist)
dist.pop(indice)
liste_coord.pop(indice)
#Calcul du tronçon de l'autre coté
liste_coord_admissibles = []
d_1_2 = []
dist2 = []
for i in range(len(liste_coord)):
#On prend la liste des intersection situé du second coté de l'arbe
d=(liste_coord[i][0]-inter_street_coord[0][0])**2 + (liste_coord[i][1]-inter_street_coord[0][1])**2
if d > dist[i] + d_1:
liste_coord_admissibles.append(liste_coord[i])
d_1_2.append(d)
dist2.append(dist[i])
while len(inter_street)<2 :
candidat=liste_coord[dist.index(min(dist))]
dist_1_2= (candidat[0]-inter_street_coord[0][0])**2 + (candidat[1]-inter_street_coord[0][1])**2
dist_main_2= min(dist)
if dist_1_2<dist_main_2 :
indice=dist.index(min(dist))
dist.pop(indice)
liste_coord.pop(indice)
candidat=liste_coord_admissibles[d_1_2.index(min(d_1_2))]
nom_de_rue=circular_research(candidat[1], candidat[0], main_street)
if nom_de_rue== None :
indice=d_1_2.index(min(d_1_2))
d_1_2.pop(indice)
liste_coord_admissibles.pop(indice)
dist2.pop(indice)
elif nom_de_rue==inter_street[0]:
indice=d_1_2.index(min(d_1_2))
d_1_2.pop(indice)
liste_coord_admissibles.pop(indice)
dist2.pop(indice)
else :
inter_street.append(nom_de_rue)
inter_street_coord.append(candidat)
indice=d_1_2.index(min(d_1_2))
d_2 = dist2[indice]
liste_coord_admissibles.pop(indice)
print(inter_street)
liste_coord_admissibles2 = []
d_2_1 = []
#dist = fct_dist(liste_coord, lat, long)
for i in range(len(liste_coord)):
#On prend la liste des intersection situé du premier coté de l'arbe
d=(liste_coord[i][0]-inter_street_coord[1][0])**2 + (liste_coord[i][1]-inter_street_coord[1][1])**2
print(liste_coord[i])
print(d - dist[i] - d_2)
if d > dist[i] + d_2: #+ 2* 10**(-12)
liste_coord_admissibles2.append(liste_coord[i])
d_1_2.append(d)
inter_street2 = ['', '']
c = 0
while inter_street != inter_street2:
if c % 2 == 0:
liste_coord_admissibles2 += [inter_street_coord[0]]
d_2_1 = fct_d_2_1(liste_coord_admissibles2, inter_street_coord)
#print(liste_coord_admissibles2)
#print(d_2_1)
else:
liste_coord_admissibles += [inter_street_coord[1]]
d_1_2 = fct_d_2_1(liste_coord_admissibles, inter_street_coord)
print(d_1_2)
inter_street2 = deepcopy(inter_street)
inter_street, inter_street_coord = opti_inter_street(c, main_street, liste_coord_admissibles, liste_coord_admissibles2, d_1_2, d_2_1, inter_street, inter_street_coord)
c +=1
return inter_street+inter_street_coord
def opti_inter_street(c, main_street, liste_coord_admissibles, liste_coord_admissibles2, d_1_2, d_2_1, inter_street_init, inter_street_coord_init):
p = c % 2
if p == 0:
liste_coord = liste_coord_admissibles2
dist = d_2_1
else:
liste_coord = liste_coord_admissibles
dist = d_1_2
inter_street = deepcopy(inter_street_init)
inter_street_coord = deepcopy(inter_street_coord_init)
found = False
while not(found):
candidat=liste_coord[dist.index(min(dist))]
nom_de_rue=circular_research(candidat[1], candidat[0], main_street)
if nom_de_rue== None :
indice=dist.index(min(dist))
dist.pop(indice)
liste_coord.pop(indice)
elif nom_de_rue==inter_street[0]:
elif nom_de_rue==inter_street[p]:
indice=dist.index(min(dist))
dist.pop(indice)
liste_coord.pop(indice)
found = True
else :
inter_street.append(nom_de_rue)
inter_street_coord.append(candidat)
inter_street[p] = nom_de_rue
inter_street_coord[p] = candidat
indice=dist.index(min(dist))
dist.pop(indice)
liste_coord.pop(indice)
return inter_street+inter_street_coord
found = True
return inter_street, inter_street_coord
def fct_d_1_2(liste_coord, inter_street_coord):
d_1_2 = []
for i in range(len(liste_coord)):
#On prend la liste des intersection situé du premier coté de l'arbe
d=(liste_coord[i][0]-inter_street_coord[0][0])**2 + (liste_coord[i][1]-inter_street_coord[0][1])**2
d_1_2.append(d)
return d_1_2
def fct_d_2_1(liste_coord, inter_street_coord):
d_2_1 = []
for i in range(len(liste_coord)):
#On prend la liste des intersection situé du premier coté de l'arbe
d=(liste_coord[i][0]-inter_street_coord[1][0])**2 + (liste_coord[i][1]-inter_street_coord[1][1])**2
d_2_1.append(d)
return d_2_1
def fct_dist(liste_coord, lat, long):
dist=[]
for inter in liste_coord:
d=(inter[0]-long)**2 + (inter[1]-lat)**2
dist.append(d)
return dist
......
from request import requete_osm
from coord_to_intersections import coord_to_inter
from request2 import search_osm, all_intersect
def tree_position(lat, lon):
req = requete_osm(lat, lon)
main_street = req['address']['road']
city = req['address']['town']
intersections = req['geojson']['coordinates']
country = req['address']['country']
json = search_osm(main_street, city, country)
intersections = all_intersect(json)
[begin,end,coord_begin, coord_end] = coord_to_inter(intersections, lat, lon, main_street)
return {'lat':lat, 'lon':lon, 'ville':city, 'rue':main_street, 'début tronçon': begin, 'fin tronçon':end, 'coordonées début tronçon': coord_begin, 'coordonnées fin tronçon': coord_end}
if __name__=="__main__":
<<<<<<< HEAD
lat = 48.89394122
lon = 2.247959188
=======
lat = 48.89227652
lon = 2.253773690
>>>>>>> 813f0fa0998be24636500d74894a86f50c568431
print(tree_position(lat, lon))
\ No newline at end of file
......@@ -22,13 +22,14 @@ if __name__=="__main__":
# 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')
params = {
'lat':48.894998,
'lon':2.247467,
'lat':48.89394122,
'lon':2.247959188,
'format':'json',
'zoom': 17,
'polygon_geojson' : 1
}
req = requests.get("https://nominatim.openstreetmap.org/reverse",params)
print(req.headers)
reqJson = req.json()
print(reqJson) #['geojson']['coordinates']
\ No newline at end of file
#print(reqJson) #['geojson']['coordinates']
import requests
import json
def search_osm(main_street, city, country):
params = {
'street' : main_street,
'city' : city,
'country' : country,
'polygon_geojson' : 1,
'format' : 'json',
'dedupe':0
}
req = requests.get("https://nominatim.openstreetmap.org/search?",params)
reqJson = req.json()
return reqJson
def all_intersect(json):
intersection = []
for road in json:
try:
inter = road['geojson']['coordinates']
intersection += inter
except KeyError:
pass
return intersection
if __name__=="__main__":
params = {
'street' : 'Avenue Gambetta',
'city' : 'Courbevoie',
'country' : 'France',
#'q' : '8 Avenue Gambetta, Courbevoie, France',
'polygon_geojson' : 1,
'format' : 'json',
'dedupe':0
}
req = requests.get("https://nominatim.openstreetmap.org/search?",params)
#print(req.text)
reqJson = req.json()
print(reqJson)
#
\ No newline at end of file
......@@ -6,7 +6,7 @@ def circular_research(lat, lon, main_street):
if not(street == main_street) and not(street == ''):
return street
step = 10**(-5)
while step < 10**(-4):
while step < 4*10**(-5):
for i in range(8):
street = check_position(lat, lon, step, main_street, i)
if not(street == main_street) and not(street == ''):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment