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

+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'])