Skip to content

Commit

Permalink
conflate px with centreline nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
Nate-Wessel committed Jan 7, 2025
1 parent d15c6a6 commit 3872cd3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
12 changes: 6 additions & 6 deletions backend/app/get_centreline_node.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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:
Expand All @@ -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()
Expand Down
25 changes: 25 additions & 0 deletions backend/app/get_px_node.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 3872cd3

Please sign in to comment.