Skip to content

Instantly share code, notes, and snippets.

@davidstrategicaci
Last active October 23, 2018 18:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidstrategicaci/91082a00ef32ad8dd372331cc8ce4a0e to your computer and use it in GitHub Desktop.
Save davidstrategicaci/91082a00ef32ad8dd372331cc8ce4a0e to your computer and use it in GitHub Desktop.
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