data transform first approach

This commit is contained in:
concierge committed 2026-10-19 22:19:20 +02:00
1 parent 638102d095
commit 0ce24cabe1
8 files changed
+64131 -28

No files matched your search

+56
View File
@@ -34,6 +34,50 @@
<div id="map" style="width: 600px; height: 400px;"></div> <div id="map" style="width: 600px; height: 400px;"></div>
<script> <script>
var Kennedyallee_18 = [
[50.7024044, 7.1522011],
[50.7024193, 7.152445],
[50.7025108, 7.152652],
[50.7026283, 7.1529199],
[50.7027407, 7.1532263],
[50.7028256, 7.1534808],
[50.7029354, 7.1538683],
[50.7030046, 7.1541476],
[50.703052, 7.1543684],
[50.7030948, 7.1545908],
[50.7031075, 7.1546643],
[50.7031221, 7.1547482],
[50.7031414, 7.1548639],
[50.7031773, 7.1550791],
[50.7032251, 7.155402],
[50.7032586, 7.1556214],
[50.7032865, 7.1558294],
[50.7033214, 7.1561731],
[50.7033291, 7.1562563],
[50.7033347, 7.1563181],
[50.7033544, 7.1565642],
[50.7033639, 7.1567531],
[50.7033734, 7.1570199],
[50.7033753, 7.1572494],
[50.7033735, 7.1576616],
[50.7033566, 7.1580302],
[50.703345, 7.1582227],
[50.7033307, 7.158379],
[50.7033174, 7.1585524],
[50.7032707, 7.1589466],
[50.7032079, 7.1593587],
[50.7031844, 7.1594936],
[50.7031701, 7.1596051],
[50.7031391, 7.1597899],
[50.7030517, 7.1602379],
[50.7029535, 7.1607034],
[50.7028796, 7.1610266],
[50.7028348, 7.1612158],
[50.7028103, 7.1613202],
[50.7027092, 7.1617351],
[50.7026355, 7.1619778],
];
function getPixelsFor10Meters(map, latlng) { function getPixelsFor10Meters(map, latlng) {
var meters = 10; var meters = 10;
@@ -56,6 +100,7 @@
attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>' attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
}).addTo(map); }).addTo(map);
/**
const marker = L.marker([51.5, -0.09]).addTo(map) const marker = L.marker([51.5, -0.09]).addTo(map)
.bindPopup('<b>Hello world!</b><br />I am a popup.').openPopup(); .bindPopup('<b>Hello world!</b><br />I am a popup.').openPopup();
@@ -87,14 +132,25 @@
map.on('click', onMapClick); map.on('click', onMapClick);
**/
// 2. Create the polyline and style it
var polyline = L.polyline(Kennedyallee_18, {
color: 'yellow',
weight: 10,
opacity: 0.7
}).addTo(map);
function onZoom(e) { function onZoom(e) {
// Anwendung: // Anwendung:
console.log("10 m in pixel:"); console.log("10 m in pixel:");
var pixelCount = getPixelsFor10Meters(map, map.getCenter()); var pixelCount = getPixelsFor10Meters(map, map.getCenter());
console.log(pixelCount); console.log(pixelCount);
polyline.setStyle( { weight: 5*pixelCount });
} }
map.on('zoom', onZoom); map.on('zoom', onZoom);
map.fitBounds(polyline.getBounds());
</script> </script>
+15
View File
@@ -16,3 +16,18 @@
[Speichern Dialog mit den passenden Optionen](/doc/SaveCVS.png) [Speichern Dialog mit den passenden Optionen](/doc/SaveCVS.png)
Das sollte die Datei _Godesberg.csv_ erstellt haben. Das sollte die Datei _Godesberg.csv_ erstellt haben.
3) Transformieren der CSV Datei in JSON 3) Transformieren der CSV Datei in JSON
`
cd data
. ./venv/bin/activate
./transform_osm-csv.py
`
## Datengrundlage: Hausnummern-Geokoordinaten
zur Suche
1) Download unter
https://opendata.bonn.de/dataset/strassenliste-stra%C3%9Fennamen-stra%C3%9Fenverzeichnis-hausnummern-georeferenziert
[Screenshot](/doc/BonnOpendata.png)
File diff suppressed because it is too large. Load diff
@@ -0,0 +1 @@
{"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"Point","coordinates":[7.1018346922,50.7043404145]},"properties":{"amtlicher_gemeinde_schluessel":"05314000","verwaltungseinheit":"Stadt","gemeinde_name":"Bonn","ortsteil_id":48,"ortsteil_name":"Venusberg","objekt":"1001-2","strassen_schluessel":1001,"stassen_langname":"Ernst-Abbe-Straße","hnr":"2","hnr_ohne_zusatz":"2","hnr_zusatz":null,"rechtswert_25832":365966.6265685934,"hochwert_25832":5618665.738158053}},{"type":"Feature","geometry":{"type":"Point","coordinates":[7.1009139774,50.7352064421]},"properties":{"amtlicher_gemeinde_schluessel":"05314000","verwaltungseinheit":"Stadt","gemeinde_name":"Bonn","ortsteil_id":6,"ortsteil_name":"Bonn-Zentrum","objekt":"1002-10","strassen_schluessel":1002,"stassen_langname":"Acherstraße","hnr":"10","hnr_ohne_zusatz":"10","hnr_zusatz":null,"rechtswert_25832":365989.69979965594,"hochwert_25832":5622099.286594456}},{"type":"Feature","geometry":{"type":"Point","coordinates":[7.1008360439,50.7351451472]},"properties":{"amtlicher_gemeinde_schluessel":"05314000","verwaltungseinheit":"Stadt","gemeinde_name":"Bonn","ortsteil_id":6,"ortsteil_name":"Bonn-Zentrum","objekt":"1002-11","strassen_schluessel":1002,"stassen_langname":"Acherstraße","hnr":"11","hnr_ohne_zusatz":"11","hnr_zusatz":null,"rechtswert_25832":365984.02579965076,"hochwert_25832":5622092.6125944555}},{"type":"Feature","geometry":{"type":"Point","coordinates":[7.1008294378,50.7352261195]},"properties":{"amtlicher_gemeinde_schluessel":"05314000","verwaltungseinheit":"Stadt","gemeinde_name":"Bonn","ortsteil_id":6,"ortsteil_name":"Bonn-Zentrum","objekt":"1002-12","strassen_schluessel":1002,"stassen_langname":"Acherstraße","hnr":"12","hnr_ohne_zusatz":"12","hnr_zusatz":null,"rechtswert_25832":365983.79079965083,"hochwert_25832":5622101.627594458}},{"type":"Feature","geometry":{"type":"Point","coordinates":[7.1006991753,50.7351775617]},"properties":{"amtlicher_gemeinde_schluessel":"05314000","verwaltungseinheit":"Stadt","gemeinde_name":"Bonn","ortsteil_id":6,"ortsteil_name":"Bonn-Zentrum","objekt":"1002-13","strassen_schluessel":1002,"stassen_langname":"Acherstraße","hnr":"13","hnr_ohne_zusatz":"13","hnr_zusatz":null,"rechtswert_25832":365974.4607996424,"hochwert_25832":5622096.464594455}},{"type":"Feature","geometry":{"type":"Point","coordinates":[7.1011593607,50.7350505257]},"properties":{"amtlicher_gemeinde_schluessel":"05314000","verwaltungseinheit":"Stadt","gemeinde_name":"Bonn","ortsteil_id":6,"ortsteil_name":"Bonn-Zentrum","objekt":"1002-1-3","strassen_schluessel":1002,"stassen_langname":"Acherstraße","hnr":"1-3","hnr_ohne_zusatz":"1-3","hnr_zusatz":null,"rechtswert_25832":366006.569204654,"hochwert_25832":5622081.506320518}},{"type":"Feature","geometry":{"type":"Point","coordinates":[7.1005626798,50.7352070591]},"properties":{"amtlicher_gemeinde_schluessel":"05314000","verwaltungseinheit":"Stadt","gemeinde_name":"Bonn","ortsteil_id":6,"ortsteil_name":"Bonn-Zentrum","objekt":"1002-13a","strassen_schluessel":1002,"stassen_langname":"Acherstraße","hnr":"13a","hnr_ohne_zusatz":"13","hnr_zusatz":"a","rechtswert_25832":365964.91379963374,"hochwert_25832":5622099.991594457}},{"type":"Feature","geometry":{"type":"Point","coordinates":[7.1004513264,50.7352305804]},"properties":{"amtlicher_gemeinde_schluessel":"05314000","verwaltungseinheit":"Stadt","gemeinde_name":"Bonn","ortsteil_id":6,"ortsteil_name":"Bonn-Zentrum","objekt":"1002-13b","strassen_schluessel":1002,"stassen_langname":"Acherstraße","hnr":"13b","hnr_ohne_zusatz":"13","hnr_zusatz":"b","rechtswert_25832":365957.1237996273,"hochwert_25832":5622102.808594455}},{"type":"Feature","geometry":{"type":"Point","coordinates":[7.1007476929,50.7352439716]},"properties":{"amtlicher_gemeinde_schluessel":"05314000","verwaltungseinheit":"Stadt","gemeinde_name":"Bonn","ortsteil_id":6,"ortsteil_name":"Bonn-Zentrum","objekt":"1002-14","strassen_schluessel":1002,"stassen_langname":"Acherstraße","hnr":"14","hnr_ohne_zusatz":"14","hnr_zusatz":null,"rechtswert_25832":365978.0737996459,"hochwert_25832":5622103.760594455}},{"type":"Feature","geometry":{"type":"Point","coordinates":[7.1003244321,50.7352560518]},"properties":{"amtlicher_gemeinde_schluessel":"05314000","verwaltungseinheit":"Stadt","gemeinde_name":"Bonn","ortsteil_id":6,"ortsteil_name":"Bonn-Zentrum","objekt":"1002-15","strassen_schluessel":1002,"stassen_langname":"Acherstraße","hnr":"15","hnr_ohne_zusatz":"15","hnr_zusatz":null,"rechtswert_25832":365948.2427996192,"hochwert_25832":5622105.870594457}},{"type":"Feature","geometry":{"type":"Point","coordinates":[7.100644846,50.7352674158]},"properties":{"amtlicher_gemeinde_schluessel":"05314000","verwaltungseinheit":"Stadt","gemeinde_name":"Bonn","ortsteil_id":6,"ortsteil_name":"Bonn-Zentrum","objekt":"1002-16","strassen_schluessel":1002,"stassen_langname":"Acherstraße","hnr":"16","hnr_ohne_zusatz":"16","hnr_zusatz":null,"rechtswert_25832":365970.88379963965,"hochwert_25832":5622106.Line truncated
+71
View File
@@ -0,0 +1,71 @@
#!/usr/bin/env python3
import pyproj
import csv
source_crs = 'epsg:25832' # übriges Europa/Deutschland EPSG:25832 (ETRS89 / UTM zone 32N)
# war früher mal 'epsg:31467' GK3
target_crs = 'epsg:4326' # Global lat-lon coordinate system
to_latlon = pyproj.Transformer.from_crs(source_crs, target_crs)
## lat, lon = to_latlon.transform(369987.527702127, 5618360.96429005)
ortsteile = []
all_ortsteile = ['Schwarzrheindorf / Vilich-Rheindorf', 'Lengsdorf', 'Mehlem',
'Südstadt', 'Beuel-Mitte', 'Pennenfeld', 'Holzlar', 'Friesdorf',
'Lannesdorf', 'Küdinghoven', 'Godesberg-Villenviertel', 'Gronau',
'Schweinheim', 'Alt-Godesberg', 'Bonn-Zentrum', 'Bonn-Castell',
'Endenich', 'Ippendorf', 'Dransdorf', 'Dottendorf', 'Nordstadt',
'Röttgen', 'Duisdorf', 'Graurheindorf', 'Ramersdorf', 'Rüngsdorf',
'Holtorf', 'Poppelsdorf', 'Geislar', 'Venusberg', 'Auerberg', 'Kessenich',
'Buschdorf', 'Ückesdorf', 'Heiderhof', 'Tannenbusch', 'Oberkassel',
'Vilich- Müldorf', 'Hoholz', 'Vilich', 'Muffendorf', 'Weststadt',
'Plittersdorf', 'Lessenich/Meßdorf', 'Godesberg-Nord', 'Hochkreuz',
'Pützchen/Bechlinghoven', 'Limperich', '', 'Beuel-Ost', 'Brüser Berg', 'Hardthöhe']
godesberg = ['Mehlem', 'Pennenfeld', 'Friesdorf', 'Lannesdorf', 'Godesberg-Villenviertel',
'Schweinheim', 'Alt-Godesberg', 'Rüngsdorf', 'Heiderhof', 'Muffendorf',
'Plittersdorf', 'Godesberg-Nord', 'Hochkreuz', ]
streets = []
max_hnr = {}
latN = {}
latS = {}
lonW = {}
lonE = {}
with open('bonn-opendata/BonnHausnummern.csv', newline='') as csvfile:
a_reader = csv.DictReader(csvfile, delimiter=';', quotechar='#')
for row in a_reader:
x = row['rechtswert_25832']
y = row['hochwert_25832']
lat, lon = to_latlon.transform(x, y)
s = row['stassen_langname']
if not s in streets:
streets.append(s)
hnr = int(row['hnr_ohne_zusatz'].split('-')[-1:][0])
max_hnr[s] = hnr
latN[s] = lat
latS[s] = lat
lonW[s] = lon
lonE[s] = lon
else:
hnr = int(row['hnr_ohne_zusatz'].split('-')[-1:][0])
if max_hnr[s] < hnr:
max_hnr[s] = hnr
if latN[s] < lat:
latN[s] = lat
if latS[s] > lat:
latS[s] = lat
if lonW[s] > lon:
lonW[s] = lon
if lonE[s] < lon:
lonE[s] = lon
if row['ortsteil_name'] in godesberg:
print("%s: %s %d - %d %s (%f, %f)" %
(row['ortsteil_name'], s, hnr,
int(row['hnr_ohne_zusatz'].split('-')[-1:][0]),
row['hnr_zusatz'],
lat, lon)
)
for s in streets:
print("%s: max=%d, (%f,%f) - (%f,%f)" %
(s, max_hnr[s], latN[s], lonW[s], latS[s], lonE[s]))
+57
View File
@@ -0,0 +1,57 @@
#!/usr/bin/env python3
import csv
STREETS_CSV="OSM/Godesberg.csv"
#
# wrap the CSV reader in a function that returns a generator (via the yield statement)
#
def read_osm_data(path):
with open(path, 'r') as data:
reader = csv.DictReader(data)
for row in reader:
yield row
def str2latlong(s):
points = s.split(",")
latlon = []
for p in points:
(lon, lat) = p.split(" ")
latlon.append([lat, lon])
return latlon
def wkt2polylines(street, wkt_lines):
i = 1
for line in wkt_lines:
latlon = str2latlong(line)
print("var %s_%d = [" % (street, i))
for p in latlon:
print(" [%s, %s]," % (p[0], p[1]))
i = i+1
print("];")
if __name__ == "__main__":
streets = {}
for idx, row in enumerate(read_osm_data(STREETS_CSV)):
if row['name'] != "":
print("ID %(full_id)s : %(name)s = %(WKT)s" % row)
# !!! TOO SIMPLE, more than 1 row !!!!
#streets[row['full_id']] = {row['name']: row['WKT'][12:-1]}
streets.setdefault(row['name'], [])
#e.g. WKT: "LINESTRING (7.1752343 50.6625148,7.1752247 50.6624694,7.1749479 50.6623222)"
# ^ ^ ^
# 0 12 -1
wkt_line = row['WKT'][12:-1]
streets[row['name']].append(wkt_line)
print("")
print("--------------------------------")
print("KENNEDYALLEE")
#print(streets['Kennedyallee'])
wkt2polylines("Kennedyallee", streets['Kennedyallee'])
print("")
print("--------------------------------")
print("AUSTRASSE")
#print(streets['Austraße'])
wkt2polylines("Austraße", streets['Austraße'])
Binary file not shown.

After

Width:  |  Height:  |  Size: 302 KiB

-28
View File
@@ -1,28 +0,0 @@
#!/usr/bin/env python3
import csv
STREETS_CSV="Godesberg.csv"
#
# wrap the CSV reader in a function that returns a generator (via the yield statement)
#
def read_osm_data(path):
with open(path, 'r') as data:
reader = csv.DictReader(data)
for row in reader:
yield row
if __name__ == "__main__":
streets = {}
for idx, row in enumerate(read_osm_data(STREETS_CSV)):
if row['name'] != "":
print("ID %(full_id)s : %(name)s = %(WKT)s" % row)
# !!! TOO SIMPLE, more than 1 row !!!!
#streets[row['full_id']] = {row['name']: row['WKT'][12:-1]}
streets.setdefault(row['name'], [])
streets[row['name']].append(row['WKT'][12:-1])
print(streets['Kennedyallee'])
print(streets['Austraße'])