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["passwd"],
|
||||
database["db"])
|
||||
|
||||
cur = db.cursor()
|
||||
|
||||
cur.execute("SELECT ref FROM stationen ORDER BY ref DESC")
|
||||
list = cur.fetchall()
|
||||
stationList = cur.fetchall()
|
||||
geojsonFeatures = []
|
||||
ways = set()
|
||||
for station in list:
|
||||
limit = 5
|
||||
for station in stationList:
|
||||
sql = '''
|
||||
SELECT
|
||||
id, start, goal
|
||||
FROM connections
|
||||
FROM connections_test
|
||||
LEFT JOIN stationen ON (start = ref OR goal = ref)
|
||||
WHERE ref = {ref}
|
||||
ORDER BY length
|
||||
LIMIT 3
|
||||
'''.format(ref=station[0])
|
||||
LIMIT {limit}
|
||||
'''.format(ref=station[0], limit=limit)
|
||||
cur.execute(sql)
|
||||
nearest = cur.fetchall()
|
||||
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])
|
||||
print(str(way[0]))
|
||||
filename = str(way[0]) + ".gpx"
|
||||
geojsonString = subprocess.check_output(["togeojson", "file/" + filename]).decode('UTF-8')
|
||||
geojson = json.loads(str(geojsonString))
|
||||
geojson = json.loads(geojsonString)
|
||||
feature = geojson["features"][0]
|
||||
del feature["properties"]["desc"], feature["properties"]["name"] # Überreste von GPX entfernen
|
||||
feature["properties"]["nodes"] = [way[1], way[2]]
|
||||
|
@ -49,5 +49,5 @@ geojsonComplete = {
|
|||
"features": geojsonFeatures
|
||||
}
|
||||
|
||||
with open('www/test.json', 'w') as outfile:
|
||||
json.dump(geojsonComplete, outfile, indent=4)
|
||||
with open('www/nearest.json', 'w') as outfile:
|
||||
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
|
||||
stations = cursor.fetchall()
|
||||
routeID = 1
|
||||
totalCombinations = 7260 # 212 über 2
|
||||
totalCombinations = 14641 # 212 über 2
|
||||
pbar = tqdm(total=totalCombinations)
|
||||
|
||||
for way in itertools.combinations(stations, 2):
|
||||
for way in itertools.product(stations, repeat=2):
|
||||
command = [
|
||||
"routino-router",
|
||||
"--dir=/home/lukas/routino/data",
|
||||
|
@ -44,7 +44,7 @@ for way in itertools.combinations(stations, 2):
|
|||
gpxNode = dom.firstChild
|
||||
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
|
||||
except subprocess.CalledProcessError as exception:
|
||||
print() # Neue Zeile
|
||||
|
|
Reference in a new issue