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

#!/usr/bin/env python3
from pprint import pprint
with open('alueet.gmp') as file:
	data = file.read()

shapes = {}
polygons = data.split('@')[1]
for polygon in polygons.splitlines():
	polygon = polygon.split('^')
	nimi = polygon[2].rsplit('>', 1)[1]
	coordinates = []
	for point in polygon[3].split('~'):
		x, y = point.split(',')
		coordinates.append((float(x), float(y)))
	shapes[nimi.strip().replace('\u200b', '')] = coordinates

pprint(shapes)

mercurial