-
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.
Add endpoint for fetching centreline nodes by ID (#174)
* rename function to specify network * add route with network specified * add node/centreline/id endpoint with error message * preemptively update docstring * add centreline endpoint return network name with nodes * add node_id field to centreline node for compatibility * return conflated here nodes also rename file, function for cosnsitency * consistently define "network" property of nodes * switch frontend to network-specific endpoint * do docstring properly
- Loading branch information
1 parent
9f769be
commit d15c6a6
Showing
6 changed files
with
73 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import json | ||
from app.db import getConnection | ||
from app.get_nearest_here_nodes import get_here_nodes_within | ||
|
||
SQL = ''' | ||
SELECT | ||
ST_AsGeoJSON(geom) AS geojson, | ||
ARRAY_AGG(DISTINCT linear_name_full_from) AS street_names | ||
FROM gis_core.intersection_latest | ||
WHERE intersection_id = %(node_id)s | ||
GROUP BY geom; | ||
''' | ||
|
||
def get_centreline_node(node_id, conflate_with_here=False): | ||
"""fetch a specific centreline node by it's ID""" | ||
node = {} | ||
with getConnection() as connection: | ||
with connection.cursor() as cursor: | ||
cursor.execute(SQL, {"node_id": node_id}) | ||
if cursor.rowcount != 1: | ||
return None | ||
geojson, street_names = cursor.fetchone() | ||
node = { | ||
'node_id': node_id, | ||
'network': 'centreline', | ||
'street_names': street_names, | ||
'geometry': json.loads(geojson) | ||
} | ||
if conflate_with_here: | ||
lon = node['geometry']['coordinates'][0] | ||
lat = node['geometry']['coordinates'][1] | ||
try: | ||
node['conflated'] = { | ||
'here': get_here_nodes_within(50, lon, lat, 1)[0] | ||
} | ||
except: | ||
pass | ||
connection.close() | ||
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
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
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