adapt BDD tests for new postcode table structure

This commit is contained in:
Sarah Hoffmann
2025-12-23 22:26:43 +01:00
parent 354aa07cad
commit 3bcd1aa721
11 changed files with 167 additions and 230 deletions

View File

@@ -8,6 +8,7 @@
A grid describing node placement in an area.
Useful for visually describing geometries.
"""
import re
class Grid:
@@ -44,3 +45,28 @@ class Grid:
def parse_line(self, value):
return [self.parse_point(p) for p in value.split(',')]
def geometry_to_wkt(self, value):
""" Parses the given value into a geometry and returns the WKT.
The value can either be a WKT already or a geometry shortcut
with coordinates or grid points.
"""
if re.fullmatch(r'([A-Z]+)\((.*)\)', value) is not None:
return value # already a WKT
# points
if ',' not in value:
x, y = self.parse_point(value)
return f"POINT({x} {y})"
# linestring
if '(' not in value:
coords = ','.join(' '.join(f"{p:.7f}" for p in pt)
for pt in self.parse_line(value))
return f"LINESTRING({coords})"
# simple polygons
coords = ','.join(' '.join(f"{p:.7f}" for p in pt)
for pt in self.parse_line(value[1:-1]))
return f"POLYGON(({coords}))"