alueet.py

Mon, 17 Apr 2017 22:56:39 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Mon, 17 Apr 2017 22:56:39 +0300
changeset 1
22c22ff63e66
child 2
48efa8ca14dd
permissions
-rwxr-xr-x

Aluemuotoja

1
22c22ff63e66 Aluemuotoja
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
1 #!/usr/bin/env python3
22c22ff63e66 Aluemuotoja
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
2 from pprint import pprint
22c22ff63e66 Aluemuotoja
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
3 with open('alueet.gmp') as file:
22c22ff63e66 Aluemuotoja
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
4 data = file.read()
22c22ff63e66 Aluemuotoja
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
5
22c22ff63e66 Aluemuotoja
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
6 shapes = {}
22c22ff63e66 Aluemuotoja
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
7 polygons = data.split('@')[1]
22c22ff63e66 Aluemuotoja
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
8 for polygon in polygons.splitlines():
22c22ff63e66 Aluemuotoja
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
9 polygon = polygon.split('^')
22c22ff63e66 Aluemuotoja
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
10 nimi = polygon[2].rsplit('>', 1)[1]
22c22ff63e66 Aluemuotoja
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
11 coordinates = []
22c22ff63e66 Aluemuotoja
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
12 for point in polygon[3].split('~'):
22c22ff63e66 Aluemuotoja
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
13 x, y = point.split(',')
22c22ff63e66 Aluemuotoja
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
14 coordinates.append((float(x), float(y)))
22c22ff63e66 Aluemuotoja
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
15 shapes[nimi.strip().replace('\u200b', '')] = coordinates
22c22ff63e66 Aluemuotoja
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
16
22c22ff63e66 Aluemuotoja
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
17 pprint(shapes)

mercurial