forked from mdornseif/pyGeoDb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plz2python2013.py
67 lines (53 loc) · 1.92 KB
/
plz2python2013.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# parse new style OpenGeoDB data files
from pprint import pprint
import sys
geodata = {}
country = 'DE'
geodata[country] = {}
for line in open(sys.argv[1], 'rb'):
line = line.decode('utf-8').strip()
if line[0] == "#" or not line:
continue
values = line.split('\t')
# #loc_id ags ascii name lat lon amt plz vorwahl einwohner flaeche kz typ level of i
# 105 D DEUTSCHLAND Bundesrepublik Deutschland 51.16766 10.42498 82169000
# 80076 16076087 KLEINWOLSCHENDORF Kleinwolschendorf 8 26599 0
# sys.stderr.write("%r\n" % values)
# Feld 1: eindeutiger Schlüssel (Primary Key)
# Felder 2 bis 8: hierarchische Verwaltungsgliederung, hier:
# Feld 2: ?
# Feld 3: NAME
# Feld 4: name
# Feld 5: lat
# Feld 6: lon
# Feld 7: Verwaltungsbezirk
# Feld 8: Postleitzahl
# Feld 9: vorwahl
# Feld 10: einwohner
# Feld 11: flaeche
# Feld 12: kz
# Feld 13: typ
# Feld 14: level
# Feld 15: of
# Feld 16: i
if len(values) < 10:
continue
if not values[4]: # keine koordinaten
continue
zipline = str(values[7])
zip_codes = zipline.split(',')
longitude = float(values[5])
latitude = float(values[4])
city = values[3]
for zip_code in zip_codes:
if not zip_code:
continue
geodata[country][zip_code] = (longitude, latitude, city)
# import pygeodb.plzdata
# geodata.update(pygeodb.plzdata.geodata)
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)