nearest.py überarbeitet
This commit is contained in:
parent
159978a650
commit
e86ca8e61f
2 changed files with 13 additions and 13 deletions
20
nearest.py
20
nearest.py
|
@ -10,32 +10,32 @@ db = MySQLdb.connect(database["host"],
|
||||||
database["user"],
|
database["user"],
|
||||||
database["passwd"],
|
database["passwd"],
|
||||||
database["db"])
|
database["db"])
|
||||||
|
|
||||||
cur = db.cursor()
|
cur = db.cursor()
|
||||||
|
|
||||||
cur.execute("SELECT ref FROM stationen ORDER BY ref DESC")
|
cur.execute("SELECT ref FROM stationen ORDER BY ref DESC")
|
||||||
list = cur.fetchall()
|
stationList = cur.fetchall()
|
||||||
geojsonFeatures = []
|
geojsonFeatures = []
|
||||||
ways = set()
|
ways = set()
|
||||||
for station in list:
|
limit = 5
|
||||||
|
for station in stationList:
|
||||||
sql = '''
|
sql = '''
|
||||||
SELECT
|
SELECT
|
||||||
id, start, goal
|
id, start, goal
|
||||||
FROM connections
|
FROM connections_test
|
||||||
LEFT JOIN stationen ON (start = ref OR goal = ref)
|
LEFT JOIN stationen ON (start = ref OR goal = ref)
|
||||||
WHERE ref = {ref}
|
WHERE ref = {ref}
|
||||||
ORDER BY length
|
ORDER BY length
|
||||||
LIMIT 3
|
LIMIT {limit}
|
||||||
'''.format(ref=station[0])
|
'''.format(ref=station[0], limit=limit)
|
||||||
cur.execute(sql)
|
cur.execute(sql)
|
||||||
nearest = cur.fetchall()
|
nearest = cur.fetchall()
|
||||||
for way in nearest:
|
for way in nearest:
|
||||||
if not way[0] in ways:
|
if not way[0] in ways: # Wenn nicht schon hinzugefügt
|
||||||
ways.add(way[0])
|
ways.add(way[0])
|
||||||
print(str(way[0]))
|
print(str(way[0]))
|
||||||
filename = str(way[0]) + ".gpx"
|
filename = str(way[0]) + ".gpx"
|
||||||
geojsonString = subprocess.check_output(["togeojson", "file/" + filename]).decode('UTF-8')
|
geojsonString = subprocess.check_output(["togeojson", "file/" + filename]).decode('UTF-8')
|
||||||
geojson = json.loads(str(geojsonString))
|
geojson = json.loads(geojsonString)
|
||||||
feature = geojson["features"][0]
|
feature = geojson["features"][0]
|
||||||
del feature["properties"]["desc"], feature["properties"]["name"] # Überreste von GPX entfernen
|
del feature["properties"]["desc"], feature["properties"]["name"] # Überreste von GPX entfernen
|
||||||
feature["properties"]["nodes"] = [way[1], way[2]]
|
feature["properties"]["nodes"] = [way[1], way[2]]
|
||||||
|
@ -49,5 +49,5 @@ geojsonComplete = {
|
||||||
"features": geojsonFeatures
|
"features": geojsonFeatures
|
||||||
}
|
}
|
||||||
|
|
||||||
with open('www/test.json', 'w') as outfile:
|
with open('www/nearest.json', 'w') as outfile:
|
||||||
json.dump(geojsonComplete, outfile, indent=4)
|
json.dump(geojsonComplete, outfile)
|
||||||
|
|
|
@ -21,10 +21,10 @@ cursor = db.cursor()
|
||||||
cursor.execute("SELECT lat, lon,ref FROM stationen ORDER BY ref DESC") # Liste der Stationen
|
cursor.execute("SELECT lat, lon,ref FROM stationen ORDER BY ref DESC") # Liste der Stationen
|
||||||
stations = cursor.fetchall()
|
stations = cursor.fetchall()
|
||||||
routeID = 1
|
routeID = 1
|
||||||
totalCombinations = 7260 # 212 über 2
|
totalCombinations = 14641 # 212 über 2
|
||||||
pbar = tqdm(total=totalCombinations)
|
pbar = tqdm(total=totalCombinations)
|
||||||
|
|
||||||
for way in itertools.combinations(stations, 2):
|
for way in itertools.product(stations, repeat=2):
|
||||||
command = [
|
command = [
|
||||||
"routino-router",
|
"routino-router",
|
||||||
"--dir=/home/lukas/routino/data",
|
"--dir=/home/lukas/routino/data",
|
||||||
|
@ -44,7 +44,7 @@ for way in itertools.combinations(stations, 2):
|
||||||
gpxNode = dom.firstChild
|
gpxNode = dom.firstChild
|
||||||
length = round(getTrackLength(gpxNode.getElementsByTagName("trk")[0]), 0) # Länge aus gpx auslesen
|
length = round(getTrackLength(gpxNode.getElementsByTagName("trk")[0]), 0) # Länge aus gpx auslesen
|
||||||
|
|
||||||
cursor.execute("REPLACE INTO connections (id, start, goal, length) VALUES (%s,%s,%s,%s)",
|
cursor.execute("REPLACE INTO connections_test (id, start, goal, length) VALUES (%s,%s,%s,%s)",
|
||||||
(routeID, way[0][2], way[1][2], length)) # in db eintragen
|
(routeID, way[0][2], way[1][2], length)) # in db eintragen
|
||||||
except subprocess.CalledProcessError as exception:
|
except subprocess.CalledProcessError as exception:
|
||||||
print() # Neue Zeile
|
print() # Neue Zeile
|
||||||
|
|
Reference in a new issue