Replace coordinate with postgis geometry

This commit is contained in:
WQY\qiong
2023-04-29 10:09:12 +08:00
parent 089a12e137
commit 0ac4a88295
4 changed files with 39 additions and 28 deletions

View File

@@ -35,7 +35,6 @@ class Junction(object):
self.f_type = f"'{self.type}'"
self.f_id = f"'{self.id}'"
self.f_coord = f"'({self.x}, {self.y})'"
self.f_elevation = self.elevation
def as_dict(self) -> dict[str, Any]:
@@ -57,9 +56,9 @@ def set_junction_cmd(name: str, cs: ChangeSet) -> DbChangeSet:
new = Junction(raw_new)
redo_sql = f"update junctions set elevation = {new.f_elevation} where id = {new.f_id};"
redo_sql += f"\nupdate coordinates set coord = {new.f_coord} where node = {new.f_id};"
redo_sql += f"\n{sql_update_coord(new.id, new.x, new.y)}"
undo_sql = f"update coordinates set coord = {old.f_coord} where node = {old.f_id};"
undo_sql = sql_update_coord(old.id, old.x, old.y)
undo_sql += f"\nupdate junctions set elevation = {old.f_elevation} where id = {old.f_id};"
redo_cs = g_update_prefix | new.as_dict()
@@ -81,9 +80,9 @@ def add_junction_cmd(name: str, cs: ChangeSet) -> DbChangeSet:
redo_sql = f"insert into _node (id, type) values ({new.f_id}, {new.f_type});"
redo_sql += f"\ninsert into junctions (id, elevation) values ({new.f_id}, {new.f_elevation});"
redo_sql += f"\ninsert into coordinates (node, coord) values ({new.f_id}, {new.f_coord});"
redo_sql += f"\n{sql_insert_coord(new.id, new.x, new.y)}"
undo_sql = f"delete from coordinates where node = {new.f_id};"
undo_sql = sql_delete_coord(new.id)
undo_sql += f"\ndelete from junctions where id = {new.f_id};"
undo_sql += f"\ndelete from _node where id = {new.f_id};"
@@ -104,13 +103,13 @@ def add_junction(name: str, cs: ChangeSet) -> ChangeSet:
def delete_junction_cmd(name: str, cs: ChangeSet) -> DbChangeSet:
old = Junction(get_junction(name, cs.operations[0]['id']))
redo_sql = f"delete from coordinates where node = {old.f_id};"
redo_sql = sql_delete_coord(old.id)
redo_sql += f"\ndelete from junctions where id = {old.f_id};"
redo_sql += f"\ndelete from _node where id = {old.f_id};"
undo_sql = f"insert into _node (id, type) values ({old.f_id}, {old.f_type});"
undo_sql += f"\ninsert into junctions (id, elevation) values ({old.f_id}, {old.f_elevation});"
undo_sql += f"\ninsert into coordinates (node, coord) values ({old.f_id}, {old.f_coord});"
undo_sql += f"\n{sql_insert_coord(old.id, old.x, old.y)}"
redo_cs = g_delete_prefix | old.as_id_dict()
undo_cs = g_add_prefix | old.as_dict()