Instantly share code, notes, and snippets.

Embed
What would you like to do?
sampleGraphQuery = """
-- Forwards, from start to end
SELECT start_node as node1, end_node as node2, split_way_id,
CASE
WHEN json_extract(tags, '$.oneway') == '-1' THEN 10000000000.0
ELSE length_m
END as cost
FROM osm_network_graph
WHERE start_node = 49370759 AND end_node = 49170395
UNION
-- Backwards, from end to start
SELECT end_node as node1, start_node as node2, split_way_id,
CASE
WHEN json_extract(tags, '$.oneway') == 'yes' THEN 10000000000.0
ELSE length_m
END as cost
FROM osm_network_graph
WHERE end_node = 49170395 or start_node = 49370759;
"""
cursor.execute(sampleGraphQuery)
costTable = tabulate(tabular_data=[list(value) for value in cursor.fetchall()],headers=['From','To','Way','Cost'],tablefmt='html')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment