16 lines
475 B
Python
16 lines
475 B
Python
|
|
def from_postgis_polygon(polygon: str) -> list[tuple[float, float]]:
|
|
boundary = polygon.lower().removeprefix('polygon((').removesuffix('))').split(',')
|
|
xys = []
|
|
for pt in boundary:
|
|
xy = pt.split(' ')
|
|
xys.append((float(xy[0]), float(xy[1])))
|
|
return xys
|
|
|
|
|
|
def to_postgis_polygon(boundary: list[tuple[float, float]]) -> str:
|
|
polygon = ''
|
|
for pt in boundary:
|
|
polygon += f'{pt[0]} {pt[1]},'
|
|
return f'polygon(({polygon[:-1]}))'
|