Support database region

This commit is contained in:
WQY\qiong
2023-04-29 17:51:34 +08:00
parent a3e8f693d9
commit d66087225f
5 changed files with 224 additions and 2 deletions

15
api/s32_region_util.py Normal file
View File

@@ -0,0 +1,15 @@
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]}))'