Archived
1
0
Fork 0

Näherste Stationen

This commit is contained in:
Lukas Winkler 2016-06-02 06:39:58 +02:00
parent b03d5fac8e
commit 8575268269
2 changed files with 67 additions and 9 deletions

View file

@ -1,34 +1,41 @@
#Näherste / fernste Stationen
SELECT id,length,s.name,g.name FROM connections
LEFT JOIN stationen as s ON start=s.ref
LEFT JOIN stationen as g ON goal=g.ref
ORDER BY length ASC
SELECT
id,
length,
s.name,
g.name
FROM connections
LEFT JOIN stationen AS s ON start = s.ref
LEFT JOIN stationen AS g ON goal = g.ref
ORDER BY length ASC;
# Suche nach Namen
SELECT *
FROM stationen WHERE name LIKE "%Spitt%";
FROM stationen
WHERE name LIKE "%Spitt%";
#gpsprune
SELECT
name,
length,
group_concat(id,".gpx" SEPARATOR " ")
group_concat(id, ".gpx" SEPARATOR " ")
FROM connections
LEFT JOIN stationen ON (start = ref OR goal = ref)
WHERE ref = 906
ORDER BY length
ORDER BY length;
#(vermutlich) abgelegenste Stationen
SELECT *
FROM (SELECT
name,
length,ref
length,
ref
FROM connections
LEFT JOIN stationen ON (start = ref OR goal = ref)
ORDER BY length ASC ) as x
ORDER BY length ASC) AS x
GROUP BY ref
ORDER BY length ASC

51
nearest.py Executable file
View file

@ -0,0 +1,51 @@
#!/usr/bin/python3
import subprocess
import json
from pprint import pprint
import MySQLdb
db = MySQLdb.connect(host="localhost", # your host, usually localhost
user="root", # your username
passwd="Findus", # your password
db="citybike") # name of the data base
cur = db.cursor()
cur.execute("SELECT ref FROM stationen ORDER BY ref DESC")
list = cur.fetchall()
geojsonFeatures = []
ways = set()
for station in list:
sql = '''
SELECT
id, start, goal
FROM connections
LEFT JOIN stationen ON (start = ref OR goal = ref)
WHERE ref = {ref}
ORDER BY length
LIMIT 3
'''.format(ref=station[0])
cur.execute(sql)
nearest = cur.fetchall()
for way in nearest:
if not way[0] in ways:
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))
feature = geojson["features"][0]
del feature["properties"]["desc"], feature["properties"]["name"] # Überreste von GPX entfernen
feature["properties"]["nodes"] = [way[1], way[2]]
geojsonFeatures.append(feature)
else:
print(str(way[0]) + ": Dup")
geojsonComplete = {}
geojsonComplete["type"] = "FeatureCollection"
geojsonComplete["features"] = geojsonFeatures
with open('test.json', 'w') as outfile:
json.dump(geojsonComplete, outfile, indent=4)