From a4f477f8eb8cc795fec10850d82d3d1e228930dc Mon Sep 17 00:00:00 2001 From: "WQY\\qiong" Date: Fri, 9 Jun 2023 21:24:16 +0800 Subject: [PATCH] Refine code --- api/s32_region_util.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/api/s32_region_util.py b/api/s32_region_util.py index d5ec1c0..7970343 100644 --- a/api/s32_region_util.py +++ b/api/s32_region_util.py @@ -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")