Add method to get nodes in extent

This commit is contained in:
DingZQ
2025-01-04 10:35:43 +08:00
parent ff83c9a974
commit cf2c90d5f9
3 changed files with 25 additions and 0 deletions

View File

@@ -27,6 +27,20 @@ def get_node_coord(name: str, node: str) -> dict[str, float]:
return {'x': 0.0, 'y': 0.0}
return from_postgis_point(row['coord_geom'])
# DingZQ 2025-01-03, get nodes in extent
# return node id list
def get_nodes_in_extent(name: str, x1: float, y1: float, x2: float, y2: float) -> list[str]:
nodes = []
objs = read_all(name, 'select node, st_astext(coord) as coord_geom from coordinates')
for obj in objs:
node_id = obj['node']
coord = from_postgis_point(obj['coord_geom'])
x = coord['x']
y = coord['y']
if x1 <= x <= x2 and y1 <= y <= y2:
nodes.append(node_id)
return nodes
def node_has_coord(name: str, node: str) -> bool:
return try_read(name, f"select node from coordinates where node = '{node}'") != None

View File

@@ -1424,6 +1424,12 @@ async def fastapi_get_major_node_coords(network: str, diameter: int) -> list[str
result.append(f"{node_id}:{coord['type']}:{coord['x']}:{coord['y']}")
return result
# DingZQ, 2025-01-03, get network in extent
@app.get("/getnetworkinextent/")
async def fastapi_get_network_in_extent(network: str, x1: float, y1: float, x2: float, y2: float) -> dict[str, Any] | None:
# TODO
pass
# DingZQ, 2024-12-08, get all links' start and end node
# link_id:link_type:node_id1:node_id2
@app.get("/getnetworklinknodes/")

View File

@@ -856,6 +856,11 @@ def get_major_node_coords(name: str, diameter: int) -> dict[str, dict[str, float
result[node_id] = coord
return result
def get_network_in_extent(name: str, x1: float, y1: float, x2: float, y2: float) -> dict[str, Any]:
pass
# DingZQ, 2024-12-08, get all links' start and end node
# link_id:link_type:node_id1:node_id2
def get_network_link_nodes(name: str) -> list[str]: