diff --git a/backend/app/get_centreline_node.py b/backend/app/get_centreline_node.py index 2cefb85..0ff51ba 100644 --- a/backend/app/get_centreline_node.py +++ b/backend/app/get_centreline_node.py @@ -1,6 +1,7 @@ import json from app.db import getConnection from app.get_nearest_here_nodes import get_here_nodes_within +from app.get_px_node import get_px_node SQL = ''' SELECT @@ -9,10 +10,9 @@ FROM gis_core.intersection_latest WHERE intersection_id = %(node_id)s GROUP BY geom; - ''' -def get_centreline_node(node_id, conflate_with_here=False): +def get_centreline_node(node_id, doConflation=False): """fetch a specific centreline node by it's ID""" node = {} with getConnection() as connection: @@ -27,13 +27,13 @@ def get_centreline_node(node_id, conflate_with_here=False): 'street_names': street_names, 'geometry': json.loads(geojson) } - if conflate_with_here: + if doConflation: lon = node['geometry']['coordinates'][0] lat = node['geometry']['coordinates'][1] + node['conflated'] = {} + node['conflated']['px'] = get_px_node(node_id) try: - node['conflated'] = { - 'here': get_here_nodes_within(50, lon, lat, 1)[0] - } + node['conflated']['here'] = get_here_nodes_within(50, lon, lat, 1)[0] except: pass connection.close() diff --git a/backend/app/get_px_node.py b/backend/app/get_px_node.py new file mode 100644 index 0000000..ad2d512 --- /dev/null +++ b/backend/app/get_px_node.py @@ -0,0 +1,25 @@ +import json +from app.db import getConnection + +SQL = ''' +SELECT + px, + ST_AsGeoJSON(geom) AS geojson +FROM traffic.traffic_signal +WHERE "centrelineId" = %(centreline_id)s; +''' + +def get_px_node(centreline_id): + node = {} + with getConnection() as connection: + with connection.cursor() as cursor: + cursor.execute(SQL, {"centreline_id": centreline_id}) + if cursor.rowcount != 1: + return None + px, geojson = cursor.fetchone() + node = { + 'node_id': px, + 'network': 'px', + 'geometry': json.loads(geojson) + } + return node \ No newline at end of file