Add method to get nodes in extent
This commit is contained in:
@@ -27,6 +27,20 @@ def get_node_coord(name: str, node: str) -> dict[str, float]:
|
|||||||
return {'x': 0.0, 'y': 0.0}
|
return {'x': 0.0, 'y': 0.0}
|
||||||
return from_postgis_point(row['coord_geom'])
|
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:
|
def node_has_coord(name: str, node: str) -> bool:
|
||||||
return try_read(name, f"select node from coordinates where node = '{node}'") != None
|
return try_read(name, f"select node from coordinates where node = '{node}'") != None
|
||||||
|
|||||||
6
main.py
6
main.py
@@ -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']}")
|
result.append(f"{node_id}:{coord['type']}:{coord['x']}:{coord['y']}")
|
||||||
return result
|
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
|
# DingZQ, 2024-12-08, get all links' start and end node
|
||||||
# link_id:link_type:node_id1:node_id2
|
# link_id:link_type:node_id1:node_id2
|
||||||
@app.get("/getnetworklinknodes/")
|
@app.get("/getnetworklinknodes/")
|
||||||
|
|||||||
@@ -856,6 +856,11 @@ def get_major_node_coords(name: str, diameter: int) -> dict[str, dict[str, float
|
|||||||
result[node_id] = coord
|
result[node_id] = coord
|
||||||
return result
|
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
|
# DingZQ, 2024-12-08, get all links' start and end node
|
||||||
# link_id:link_type:node_id1:node_id2
|
# link_id:link_type:node_id1:node_id2
|
||||||
def get_network_link_nodes(name: str) -> list[str]:
|
def get_network_link_nodes(name: str) -> list[str]:
|
||||||
|
|||||||
Reference in New Issue
Block a user