Skip to content

Instantly share code, notes, and snippets.

@loleg
Created November 13, 2021 08:12
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save loleg/23c6f63670ded8a8a1e778830c5027c5 to your computer and use it in GitHub Desktop.
Combine geodata referenced by EGID (building identifier) #DataHackdaysBE
import csv, io
# Configuration
input_addresses = "Gebaeudeadressen_1636760957021_53445 - Gebäudeadressen.csv"
egidcol_addresses = "Eidg. Gebäude-ID (EGID)"
input_opendata = "V20211111.csv"
egidcol_opendata = "egid"
output_filename = "combined.csv"
# Preload address file
with open(input_addresses, 'r') as csvfile:
reader = csv.DictReader(csvfile)
places = [dict(row) for row in reader]
# Process the open data
rowcount = 0
firstbase = False
with open(output_filename, 'w') as outfile:
outwriter = csv.writer(outfile)
with open(input_opendata, 'r') as bigfile:
reader = csv.DictReader(bigfile, delimiter=";")
for row in reader:
egid = row[egidcol_opendata]
for p in places:
if p[egidcol_addresses] == egid:
for o in p:
row[o] = p[o]
if not firstbase:
outwriter.writerow(row)
firstbase = True
rowcount = rowcount + 1
outwriter.writerow([row[r] for r in row])
print('.', end="")
# Write a brief summary
print()
print("%d rows processed" % rowcount)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment