Refine code

This commit is contained in:
WQY\qiong
2023-06-09 21:24:16 +08:00
parent 2b424e4710
commit a4f477f8eb

View File

@@ -147,7 +147,7 @@ class Topology:
return self._link_list
def _calculate_boundary(name: str, cursor: str, t_nodes: dict[str, Any], t_links: dict[str, Any]) -> tuple[list[str], dict[str, list[str]], list[tuple[float, float]]]:
def _calculate_boundary(cursor: str, t_nodes: dict[str, Any], t_links: dict[str, Any]) -> tuple[list[str], dict[str, list[str]], list[tuple[float, float]]]:
in_angle = 0
vertices: list[str] = []
@@ -241,14 +241,15 @@ def calculate_boundary(name: str, nodes: list[str]) -> list[tuple[float, float]]
t_nodes = topology.nodes()
t_links = topology.links()
vertices, path, boundary = _calculate_boundary(name, topology.max_x_node(), t_nodes, t_links)
vertices, path, boundary = _calculate_boundary(topology.max_x_node(), t_nodes, t_links)
#return boundary
api = 'calculate_boundary'
write(name, f"delete from temp_region where id = '{api}'")
# use linestring instead of polygon to reduce strict limitation
write(name, f"insert into temp_region (id, boundary) values ('{api}', '{to_postgis_linestring(boundary)}')")
# TODO: linestring can not work well
write(name, f"insert into temp_region (id, boundary) values ('{api}', '{to_postgis_polygon(boundary)}')")
write(name, f'delete from temp_node')
for node in nodes:
@@ -325,6 +326,7 @@ def calculate_boundary(name: str, nodes: list[str]) -> list[tuple[float, float]]
path[link1].append(new_node)
boundary_links[link2].append(new_node)
# no intersection, return
if not has_intersection:
write(name, "delete from temp_link_1")
write(name, "delete from temp_link_2")
@@ -339,7 +341,7 @@ def calculate_boundary(name: str, nodes: list[str]) -> list[tuple[float, float]]
new_nodes[values['node1']]['links'].append(link)
new_nodes[values['node2']]['links'].append(link)
_, _, boundary = _calculate_boundary(name, topology.max_x_node(), new_nodes, new_links)
_, _, boundary = _calculate_boundary(topology.max_x_node(), new_nodes, new_links)
write(name, "delete from temp_link_1")
write(name, "delete from temp_link_2")