regions.py

changeset 2
7378b802ddf8
parent 1
f9788970fa46
child 4
ac067a42b00f
--- a/regions.py	Wed Jul 29 23:45:53 2020 +0300
+++ b/regions.py	Thu Jul 30 21:52:31 2020 +0300
@@ -33,11 +33,10 @@
 				return None # we're not interested in it!
 	if shape[-1] != shape[0]:
 		raise ValueError('polygon is not closed: %r' % result)
-	if 'boundary' not in result:
-		raise ValueError('polygon not tagged as a boundary: %r' % result)
-	shape = [nodes[ref] for ref in shape[:-1]]
-	choose_shapes(result, result['boundary']).append(Polygon(*shape))
-	return result
+	if 'boundary' in result:
+		shape = [nodes[ref] for ref in shape[:-1]]
+		choose_shapes(result, result['boundary']).append(Polygon(*shape))
+		return result
 
 def parse_boundaries(root, *, nodes):
 	for child in root:
@@ -54,22 +53,23 @@
 	regions = dict()
 	extra_shapes = list()
 	for way in parse_boundaries(root, nodes = nodes):
-		if 'boundary' in way and way['boundary'] != 'subregion' and 'name' in way:
+		if 'boundary' in way and 'ref' in way:
 			# defines a region
 			way['via_factor'] = int(way.get('via_factor', 1))
-			if way['name'] in regions:
+			if way['ref'] in regions:
 				raise ValueError(str.format(
-					'Region {name} defined twice',
-					name = repr(way['name']),
+					'Region {ref} defined twice',
+					ref = repr(way['ref']),
 				))
-			regions[way['name']] = way
+			regions[way['ref']] = way
 			del way['boundary']
 			if 'external' in way:
 				way['boundary'] = 'minor_region'
 			for prefix in ['', 'short_', 'internal_']:
-				name_key = prefix + 'name'
-				if name_key in way and way[name_key] and name_key + ':ja' not in way:
-					way[name_key + ':ja'] = transliterate_katakana(way[name_key])
+				name_key = prefix + 'name:fi'
+				ja_name_key = prefix + 'name:ja'
+				if name_key in way and way[name_key] and ja_name_key not in way:
+					way[ja_name_key] = transliterate_katakana(way[name_key])
 		elif 'boundary' in way and 'is_in' in way:
 			# adds an extra shape to an existing region
 			extra_shapes.append(way)

mercurial