Mon, 17 Apr 2017 22:56:39 +0300
Aluemuotoja
1 | 1 | #!/usr/bin/env python3 |
2 | from pprint import pprint | |
3 | with open('alueet.gmp') as file: | |
4 | data = file.read() | |
5 | ||
6 | shapes = {} | |
7 | polygons = data.split('@')[1] | |
8 | for polygon in polygons.splitlines(): | |
9 | polygon = polygon.split('^') | |
10 | nimi = polygon[2].rsplit('>', 1)[1] | |
11 | coordinates = [] | |
12 | for point in polygon[3].split('~'): | |
13 | x, y = point.split(',') | |
14 | coordinates.append((float(x), float(y))) | |
15 | shapes[nimi.strip().replace('\u200b', '')] = coordinates | |
16 | ||
17 | pprint(shapes) |