Skip to content

Commit d509aa2

Browse files
committed
Initial version
1 parent fba6248 commit d509aa2

13 files changed

+2611
-0
lines changed

.gitignore

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
Skip to content
2+
Search or jump to…
3+
4+
Pull requests
5+
Issues
6+
Marketplace
7+
Explore
8+
9+
@JensWinter
10+
code-for-magdeburg
11+
/
12+
streetnames-md
13+
3
14+
00
15+
Code Issues 0 Pull requests 0 Actions Projects 0 Wiki Security Insights Settings
16+
streetnames-md/.gitignore
17+
@JensWinter JensWinter Initial commit
18+
fba6248 now
19+
104 lines (76 sloc) 1.57 KB
20+
121
# Logs
222
logs
323
*.log
@@ -102,3 +122,20 @@ dist
102122

103123
# TernJS port file
104124
.tern-port
125+
© 2020 GitHub, Inc.
126+
Terms
127+
Privacy
128+
Security
129+
Status
130+
Help
131+
Contact GitHub
132+
Pricing
133+
API
134+
Training
135+
Blog
136+
About
137+
138+
.idea/
139+
140+
/output/*
141+
!/**/.gitkeep

01_get_osm_data.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/bash
2+
3+
# Extract highways from OSM data that are within the boundary of the
4+
# city of Karlsruhe. The data is stored in `highways.osm`.
5+
#
6+
# Requires the `osmosis` tool.
7+
8+
9+
#
10+
# Download data if necessary
11+
#
12+
13+
DIR=http://download.geofabrik.de/europe/germany
14+
OUTPUT_DIR=output
15+
BASE=sachsen-anhalt-latest.osm.pbf
16+
17+
if [ -f "${OUTPUT_DIR}/${BASE}" ]; then
18+
# Download MD5 file to see if file is up-to-date
19+
echo "${OUTPUT_DIR}/${BASE} exists, downloading MD5 to check whether it's up to date."
20+
wget -q -N ${DIR}/${BASE}.md5 -O ${OUTPUT_DIR}/${BASE}.md5
21+
LATEST_MD5=$(<${OUTPUT_DIR}/${BASE}.md5)
22+
FILE_MD5=`md5sum ${OUTPUT_DIR}/${BASE}`
23+
if [ "$LATEST_MD5" == "$FILE_MD5" ]; then
24+
echo "File is up to date."
25+
else
26+
echo "File is outdated, downloading latest version."
27+
wget ${DIR}/${BASE} -O ${OUTPUT_DIR}/${BASE}
28+
fi
29+
else
30+
echo "${BASE} doesn't exist, downloading it."
31+
wget ${DIR}/${BASE} -O ${OUTPUT_DIR}/${BASE}
32+
fi
33+
34+
35+
#
36+
# Extract coordinates for things
37+
#
38+
39+
osmosis --read-pbf file=${OUTPUT_DIR}/${BASE} \
40+
--bounding-polygon file=magdeburg.poly \
41+
--write-xml ${OUTPUT_DIR}/highways-magdeburg.osm
42+

02_extract-coordinates.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
const osmread = require('osm-read');
2+
const fs = require('fs');
3+
const GeoJSON = require('geojson');
4+
5+
6+
const nodes = [];
7+
const osmStreets = [];
8+
const osm = osmread.parse({
9+
format: 'xml',
10+
filePath: './output/highways-magdeburg.osm',
11+
12+
endDocument: function () {
13+
const geoJson = GeoJSON.parse(osmStreets, { 'MultiLineString': 'entries' });
14+
fs.writeFileSync('./output/coordinates-magdeburg.geojson', JSON.stringify(geoJson));
15+
console.log('Done.');
16+
},
17+
18+
node: function (node) {
19+
nodes.push({ id: node.id, coords: [node.lon, node.lat] });
20+
},
21+
22+
way: function (way) {
23+
if (way.tags && way.tags.highway && way.tags.name) {
24+
25+
const osmStreet = osmStreets.find(s => s.name === way.tags.name);
26+
if (osmStreet) {
27+
osmStreet.entries.push(way.nodeRefs.map(nodeRef => {
28+
const node = nodes.find(n => n.id === nodeRef);
29+
if (node) {
30+
return node.coords;
31+
}
32+
return null;
33+
}).filter(node => !!node));
34+
} else {
35+
osmStreets.push({
36+
name: way.tags.name,
37+
entries: [way.nodeRefs.map(nodeRef => {
38+
const node = nodes.find(n => n.id === nodeRef);
39+
if (node) {
40+
return node.coords;
41+
}
42+
return null;
43+
}).filter(node => !!node)]
44+
});
45+
}
46+
47+
}
48+
},
49+
50+
});

05_merge.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
const fs = require('fs');
3+
const csv = require('csv-parser');
4+
5+
const coordinates_geojson = fs.readFileSync('./output/coordinates-magdeburg.geojson', 'utf-8');
6+
const streets = JSON.parse(coordinates_geojson);
7+
8+
const streetnames = [];
9+
fs.createReadStream('./names-magdeburg.csv')
10+
.pipe(csv())
11+
.on('data', data => streetnames.push(data))
12+
.on('end', () => {
13+
14+
streets.features.forEach(feature => {
15+
const streetname = streetnames.find(s => s.Name === feature.properties.name);
16+
if (streetname && streetname.Name && streetname.Zuordnung) {
17+
feature.id = streetname.Name;
18+
feature.properties['gender'] = streetname.Zuordnung;
19+
} else {
20+
console.log('Nicht gefunden: ' + feature.properties.name);
21+
}
22+
});
23+
24+
fs.writeFileSync('./output/streetnames-magdeburg.geojson', JSON.stringify(streets));
25+
26+
});

06_prepare-datasets.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const fs = require('fs');
2+
3+
const streetnames_geojson = fs.readFileSync('./output/streetnames-magdeburg.geojson');
4+
const streetnames = JSON.parse(streetnames_geojson);
5+
6+
const streetnames_female = streetnames.features.filter(feature => feature.id && feature.properties && feature.properties.gender === 'f');
7+
const streetnames_male = streetnames.features.filter(feature => feature.id && feature.properties && feature.properties.gender === 'm');
8+
//const streetnames_none = streetnames.features.filter(feature => !feature.id || !feature.properties || (feature.properties.gender !== 'w' && feature.properties.gender !== 'm'));
9+
10+
const gender = [
11+
{
12+
color: '#ff7f00',
13+
label: 'männlich',
14+
features: streetnames_male
15+
},
16+
{
17+
color: '#007fff',
18+
label: 'weiblich',
19+
features: streetnames_female
20+
}
21+
];
22+
23+
fs.writeFileSync('./output/gender.json', JSON.stringify(gender));

docs/gender.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

docs/index.html

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
5+
<meta charset="UTF-8">
6+
<title>Magdeburger Straßennamen</title>
7+
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css"
8+
integrity="sha512-xwE/Az9zrjBIphAcBb3F6JVqxf46+CDLwfLMHloNu6KEQCAWi6HcDUbeOfBIptF7tcCzusKFjFw2yuvEpDL9wQ=="
9+
crossorigin=""/>
10+
<style>
11+
html, body, #map {
12+
height: 100%;
13+
width: 100%;
14+
padding: 0;
15+
margin: 0;
16+
}
17+
18+
.leaflet-label {
19+
font-weight: normal;
20+
}
21+
22+
div.info {
23+
width: 40em;
24+
white-space: normal;
25+
}
26+
27+
.legend {
28+
margin: 3em;
29+
border: 1px solid #555;
30+
background-color: #eee;
31+
padding: 1em;
32+
border-radius: 6px;
33+
-o-border-radius: 6px;
34+
-moz-border-radius: 6px;
35+
-webkit-border-radius: 6px;
36+
color: #555;
37+
width: 22em;
38+
}
39+
40+
.legend h1 {
41+
margin-top: 0;
42+
font-size: 120%;
43+
}
44+
45+
.legend ul {
46+
list-style: none;
47+
padding: 0;
48+
font-weight: bold;
49+
margin: 0;
50+
}
51+
52+
.legend ul li {
53+
background-color: #e6e6e6;
54+
margin: 0.25em 0.5em 0 0;;
55+
padding: 0.1em 0.5em 0.1em 0.5em;
56+
border-radius: 4px;
57+
-o-border-radius: 4px;
58+
-moz-border-radius: 4px;
59+
-webkit-border-radius: 4px;
60+
border: 1px solid #aaa;
61+
display: inline;
62+
float: left;
63+
}
64+
</style>
65+
66+
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"
67+
integrity="sha512-gZwIG9x3wUXg2hdXF6+rVkLF/0Vi9U8D2Ntg4Ga5I5BZpVkVxlJWbSQtXPSiUTtC0TjtGOmxa1AJPuV0CPthew=="
68+
crossorigin=""></script>
69+
70+
</head>
71+
<body>
72+
73+
<div id="map"></div>
74+
75+
<script src="jquery-3.4.1.min.js"></script>
76+
77+
<script>
78+
let TILES_URL = 'http://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png';
79+
let INITIAL_LOCATION = [52.1259661, 11.6418369];
80+
let INITIAL_ZOOM = 12;
81+
let ATTRIBUTION = 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> ' +
82+
'contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">' +
83+
'CC-BY-SA</a>. Tiles &copy; <a href="http://cartodb.com/attributions">' +
84+
'CartoDB</a>';
85+
let WEIGHT = 5;
86+
let OPACITY = 0.75;
87+
88+
let map;
89+
90+
function onEachFeature(feature, layer) {
91+
let label = '<div><strong>' + feature.id + '</strong></div>';
92+
if (feature.properties.gender === 'f') {
93+
label += 'weiblich';
94+
}
95+
if (feature.properties.gender === 'm') {
96+
label += 'männlich';
97+
}
98+
if (feature.properties.info) {
99+
label += '<div class="info">' + feature.properties.info + '</div>';
100+
}
101+
layer.bindTooltip(label);
102+
}
103+
104+
$(document).ready(function () {
105+
106+
let tiles = new L.TileLayer(TILES_URL, { attribution: ATTRIBUTION });
107+
map = L.map('map').addLayer(tiles).setView(INITIAL_LOCATION, INITIAL_ZOOM);
108+
109+
$.getJSON('gender.json', function (json) {
110+
111+
let legendHTML = '<h1>Geschlechterverhältnisse Magdeburger Straßennamen</h1>' +
112+
'<p>Ein Projekt des <a href="http://codefor.de/magdeburg">' +
113+
'Open Knowledge Lab Magdeburg</a>. Inspiriert durch das <a href="http://codefor.de/karlsruhe">OK Lab Karlsruhe</a>. ' +
114+
'Daten vom <a href="https://www.magdeburg.de/Start/B%C3%BCrger-Stadt/Verwaltung-Service/Statistik-Geodaten">' +
115+
'Statistikamt der Stadt Magdeburg</a> und <a href="https://www.wikipedia.de/">Wikipedia</a>. ' +
116+
'<a href="https://github.com/CodeforKarlsruhe/streetnames">Code</a> ' +
117+
'auf GiHub.</p>';
118+
119+
legendHTML += '<ul>';
120+
json.forEach(function (dataset) {
121+
let style = { color: dataset['color'], weight: WEIGHT, opacity: OPACITY };
122+
L.geoJson(dataset['features'], { style: style, onEachFeature: onEachFeature }).addTo(map);
123+
legendHTML += '<li style="color:' + dataset['color'] + ';"/>' + dataset['label'] + ' (' + dataset['features'].length + ')</li>';
124+
});
125+
legendHTML += '</ul>';
126+
127+
let legend = L.control({ position: 'bottomright' });
128+
legend.onAdd = function (m) {
129+
let div = L.DomUtil.create('div', 'legend');
130+
div.innerHTML = legendHTML;
131+
return div;
132+
};
133+
134+
legend.addTo(map);
135+
136+
});
137+
});
138+
139+
</script>
140+
141+
</body>
142+
</html>

docs/jquery-3.4.1.min.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)