Refactor coord

This commit is contained in:
WQY\qiong
2023-04-29 14:26:49 +08:00
parent 12150ef57e
commit a278335bbe

View File

@@ -15,7 +15,7 @@ def sql_delete_coord(node: str) -> str:
return f"delete from coordinates where node = '{node}';" return f"delete from coordinates where node = '{node}';"
def _to_client_point(coord: str) -> dict[str, float]: def from_postgis_point(coord: str) -> dict[str, float]:
xy = coord.lower().removeprefix('point(').removesuffix(')').split(' ') xy = coord.lower().removeprefix('point(').removesuffix(')').split(' ')
return { 'x': float(xy[0]), 'y': float(xy[1]) } return { 'x': float(xy[0]), 'y': float(xy[1]) }
@@ -25,7 +25,7 @@ def get_node_coord(name: str, node: str) -> dict[str, float]:
if row == None: if row == None:
write(name, sql_insert_coord(node, 0.0, 0.0)) write(name, sql_insert_coord(node, 0.0, 0.0))
return {'x': 0.0, 'y': 0.0} return {'x': 0.0, 'y': 0.0}
return _to_client_point(row['coord_geom']) return from_postgis_point(row['coord_geom'])
#-------------------------------------------------------------- #--------------------------------------------------------------
@@ -47,7 +47,7 @@ def inp_out_coord(name: str) -> list[str]:
objs = read_all(name, 'select node, st_astext(coord) as coord_geom from coordinates') objs = read_all(name, 'select node, st_astext(coord) as coord_geom from coordinates')
for obj in objs: for obj in objs:
node = obj['node'] node = obj['node']
coord = _to_client_point(obj['coord_geom']) coord = from_postgis_point(obj['coord_geom'])
x = coord['x'] x = coord['x']
y = coord['y'] y = coord['y']
lines.append(f'{node} {x} {y}') lines.append(f'{node} {x} {y}')