Archived
1
0
Fork 0
This commit is contained in:
Lukas Winkler 2016-06-02 15:14:51 +02:00
parent e1c1f86235
commit 95495bd189
6 changed files with 180 additions and 1875 deletions

View file

@ -14,12 +14,12 @@ db = MySQLdb.connect(database["host"],
database["passwd"],
database["db"])
cur = db.cursor()
cursor = db.cursor()
cur.execute("SELECT lat, lon,ref FROM stationen ORDER BY ref DESC")
list = cur.fetchall()
i = 1
for way in itertools.combinations(list, 2):
cursor.execute("SELECT lat, lon,ref FROM stationen ORDER BY ref DESC")
stations = cursor.fetchall()
id = 1
for way in itertools.combinations(stations, 2):
command = "routino-router --dir=/home/lukas/router/data" \
" --lat1={}".format(way[0][0]) + \
" --lon1={}".format(way[0][1]) + \
@ -28,16 +28,15 @@ for way in itertools.combinations(list, 2):
" --quickest --transport=bicycle --output-gpx-track --quiet"
success = os.system(command)
if success == 0:
os.rename("quickest-track.gpx", "file/" + str(i) + ".gpx")
dom = xml.dom.minidom.parse("file/" + str(i) + ".gpx")
os.rename("quickest-track.gpx", "file/" + str(id) + ".gpx")
dom = xml.dom.minidom.parse("file/" + str(id) + ".gpx")
gpxNode = dom.firstChild
length = round(getTrackLength(gpxNode.getElementsByTagName("trk")[0]), 0)
cur.execute("REPLACE INTO connections (id, start, goal, length) VALUES (%s,%s,%s,%s)",
(i, way[0][2], way[1][2], length))
db.commit()
cursor.execute("REPLACE INTO connections (id, start, goal, length) VALUES (%s,%s,%s,%s)",
(id, way[0][2], way[1][2], length))
else:
print(" " + str(way[0][2]) + " " + str(way[1][2]))
print(i)
i += 1
print(id)
id += 1
db.commit()

View file

@ -39,13 +39,15 @@ LIMIT 3
feature = geojson["features"][0]
del feature["properties"]["desc"], feature["properties"]["name"] # Überreste von GPX entfernen
feature["properties"]["nodes"] = [way[1], way[2]]
feature["properties"]["id"] = way[0]
geojsonFeatures.append(feature)
else:
print(str(way[0]) + ": Dup")
geojsonComplete = {}
geojsonComplete["type"] = "FeatureCollection"
geojsonComplete["features"] = geojsonFeatures
geojsonComplete = {
"type": "FeatureCollection",
"features": geojsonFeatures
}
with open('test.json', 'w') as outfile:
with open('www/test.json', 'w') as outfile:
json.dump(geojsonComplete, outfile, indent=4)

42
stationExport.py Normal file
View file

@ -0,0 +1,42 @@
#!/usr/bin/python3
import json
from pprint import pprint
import MySQLdb
from config import database
db = MySQLdb.connect(database["host"],
database["user"],
database["passwd"],
database["db"])
cursor = db.cursor()
cursor.execute("SELECT lon, lat,ref,name FROM stationen ORDER BY ref DESC")
stations = cursor.fetchall()
features = []
for station in stations:
feature = {
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
station[0],
station[1]
]
},
"properties": {
"name": station[3],
"ref": station[2]
}
}
features.append(feature)
geojsonComplete = {
"type": "FeatureCollection",
"features": features
}
# print(json.dumps(geojsonComplete, indent=4))
with open('stations.json', 'w') as outfile:
json.dump(geojsonComplete, outfile, indent=4)

File diff suppressed because it is too large Load diff

BIN
www/citybike.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1,014 B

121
www/map.html Normal file
View file

@ -0,0 +1,121 @@
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<title>CityBikes</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0-rc.1/leaflet.css"/>
<style>
body {
margin: 0;
}
html, body, #map {
height: 100%;
}
</style>
</head>
<body>
<div id="map"></div>
</body>
<script src="https://code.jquery.com/jquery-2.2.4.min.js"
integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>
<script src="leaflet-src.js"></script>
<script>
var map = L.map('map').setView([48.51579416571888, 15.6255304813385], 16);
var layer = L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 19,
attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a>',
}).addTo(map);
var LeafIcon = L.Icon.extend({
options: {
iconUrl: "citybike.png",
// shadowUrl: 'leaf-shadow.png',
// // iconSize: [38, 95],
// shadowSize: [50, 64],
iconAnchor: [16, 16],
popupAnchor: [0, -16]
}
});
function highlightFeature(e) {
var layer = e.target;
layer.setStyle({
weight: 10,
color: '#666'
});
if (!L.Browser.ie && !L.Browser.opera) {
layer.bringToFront();
}
}
function resetHighlight(e) {
lines.resetStyle(e.target);
}
function onEachFeature(feature, layer) {
layer.on({
mouseover: highlightFeature,
mouseout: resetHighlight
});
// layer._leaflet_id = feature.properties.id;
}
var style = {
weight: 5
};
var lines = L.geoJson(null, {
onEachFeature: function (feature, layer) {
layer.bindPopup(feature.properties.nodes[0] + " - " + feature.properties.nodes[1]);
onEachFeature(feature, layer);
},
style: style
});
var mapLayers = {
'Standard': layer
};
$.ajax({
dataType: "json",
url: "test.json",
success: function (data) {
lines.addData(data);
lines.addTo(map);
}
});
var stations = L.geoJson(null, {
pointToLayer: function (feature, latlng) {
return L.marker(latlng, {icon: new LeafIcon()});
},
onEachFeature: function (feature, layer) {
// layer._leaflet_id = feature.properties.ref;
// console.log(feature.properties.ref);
layer.bindPopup(feature.properties.name);
}
});
$.ajax({
dataType: "json",
url: "stations.json",
success: function (data) {
stations.addData(data);
stations.addTo(map);
map.fitBounds(stations.getBounds());
}
});
var overlays = {
"Wege": lines,
"Stationen": stations
};
var control = L.control.layers(mapLayers, overlays, {collapsed: false}).addTo(map);
</script>
</html>