mirror of
https://github.com/osm-search/Nominatim.git
synced 2026-02-16 15:47:58 +00:00
adapt BDD tests for new postcode table structure
This commit is contained in:
@@ -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}))"
|
||||
|
||||
Reference in New Issue
Block a user