-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extend node conflation to
px
traffic signals (#175)
* conflate px with centreline nodes * organize node-fetching functions in folders * organize nearby node searches into folders * put all conflation logic in one place * get street names for `px` * measure distance to conflated nodes * use try block
- Loading branch information
1 parent
d15c6a6
commit 4d3bbba
Showing
8 changed files
with
96 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import json | ||
from app.db import getConnection | ||
|
||
SQL = ''' | ||
SELECT | ||
tts.px, | ||
ST_AsGeoJSON(tts.geom) AS geojson, | ||
array_remove( | ||
ARRAY[ | ||
InitCap(gts.main_street), | ||
InitCap(gts.side1_street), | ||
InitCap(gts.side2_street) | ||
], | ||
NULL | ||
) AS street_names | ||
FROM traffic.traffic_signal AS tts | ||
JOIN gis.traffic_signal AS gts ON tts.px = gts.px::int | ||
WHERE tts."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, street_names = cursor.fetchone() | ||
node = { | ||
'node_id': px, | ||
'network': 'px', | ||
'street_names': street_names, | ||
'geometry': json.loads(geojson) | ||
} | ||
return node |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from app.nodes.nearby.here import get_here_nodes_within | ||
from app.nodes.byID.px import get_px_node | ||
from app.nodes.nearby.centreline import get_nearest_centreline_node | ||
from haversine import haversine | ||
|
||
def add_conflated_nodes(node): | ||
"""adds "conflated" field to node objects""" | ||
|
||
node['conflated'] = {} | ||
lon = node['geometry']['coordinates'][0] | ||
lat = node['geometry']['coordinates'][1] | ||
|
||
if node['network'] == 'centreline': | ||
# adds px and here nodes | ||
# px search is based on the centreline_id | ||
node['conflated']['px'] = get_px_node(node['node_id']) | ||
try: | ||
# here search is based on distance | ||
node['conflated']['here'] = get_here_nodes_within(50, lon, lat, 1)[0] | ||
except: | ||
pass | ||
elif node['network'] == 'here': | ||
# adds centreline and px nodes | ||
# get centreline by nearest | ||
node['conflated']['centreline'] = get_nearest_centreline_node(lon, lat) | ||
# get px from Id of nearest centreline | ||
node['conflated']['px'] = get_px_node(node['conflated']['centreline']['node_id']) | ||
|
||
# now get distances between selected and conflated points | ||
for network, conflatedNode in node['conflated'].items(): | ||
try: | ||
conflatedNode['distance'] = haversine( | ||
(lat, lon), | ||
( | ||
conflatedNode['geometry']['coordinates'][1], | ||
conflatedNode['geometry']['coordinates'][0] | ||
), | ||
unit='m' | ||
) | ||
except: | ||
pass | ||
|
||
return node |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,5 @@ pandas==2.2.2 | |
psycopg==3.1.18 | ||
python-dotenv==0.15.0 | ||
numpy==1.26.0 | ||
git+ssh://[email protected]/Toronto-Big-Data-Innovation-Team/[email protected] | ||
git+ssh://[email protected]/Toronto-Big-Data-Innovation-Team/[email protected] | ||
haversine==2.9.0 |