forked from mdornseif/pyGeoDb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plz2python.py
46 lines (37 loc) · 1.27 KB
/
plz2python.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# parse old style OpenGeoDB data files and generate a python data structure form it
from pprint import pprint
import sys
geodata = {}
for line in open(sys.argv[1], 'rb'):
line = line.decode('utf-8').strip()
if line[0] == "#" or not line:
continue
values = line.split(";")
# Feld 1: eindeutiger Schlüssel (Primary Key)
# Felder 2 bis 8: hierarchische Verwaltungsgliederung, hier:
# Feld 2: Staat (DE == Deutschland)
# Feld 3: Bundesland, s.o.
# Feld 4: Regierungsbezirk
# Feld 5: Landkreis
# Feld 6: Verwaltungszusammenschluss
# Feld 7: Ort
# Felder 8 und 9: Koordinaten:
# Feld 8: Längengrad
# Feld 9: Breitengrad
# Feld 10: Postleitzahl
zipcode = str(values[9])
city = values[6]
country = str(values[1]).upper()
longitude = float(values[7])
latitude = float(values[8])
if not country in geodata:
geodata[country] = {}
geodata[country][zipcode] = (longitude, latitude, city)
import pygeodb.plzdata
geodata.update(pygeodb.plzdata)
outfile = open(sys.argv[2], 'wb')
outfile.write("# autogenerated - do not edit\n".encode('utf-8'))
outfile.write("geodata = ".encode('utf-8'))
pprint(geodata, outfile)