Browse files

have build_paths annotate the rail_segments table with the path ID

  • Loading branch information...
1 parent 51f63a8 commit 4ee71af0364a0b238e6a58a9931411b5727b0bf6 @gasman gasman committed Oct 29, 2012
Showing with 13 additions and 7 deletions.
  1. +12 −6 build_paths.py
  2. +1 −1 graph_reduction.txt
View
18 build_paths.py
@@ -13,7 +13,7 @@
FROM junctions
INNER JOIN rail_segments ON (
(junctions.id = node1_id OR junctions.id = node2_id)
- AND visited = 'f'
+ AND path_id IS NULL
)
WHERE unfollowed_neighbour_count > 0
LIMIT 1
@@ -29,18 +29,13 @@
while True:
# continue walking the graph until we encounter another node with more than one exit
cur.execute("""
- UPDATE rail_segments
- SET visited = 't'
- WHERE node1_id = %s AND node2_id = %s;
-
SELECT
(CASE WHEN node1_id = %s THEN node2_id ELSE node1_id END) AS next_node
FROM rail_segments
WHERE
(node1_id = %s AND node2_id <> %s)
OR (node2_id = %s AND node1_id <> %s)
""", (
- min(last_node, current_node), max(last_node, current_node),
current_node,
current_node, last_node,
current_node, last_node,
@@ -77,6 +72,17 @@
)
""", (node, i))
+ if i != 0:
+ # annotate rail_segments with the path id to mark them as visited
+ cur.execute("""
+ UPDATE rail_segments
+ SET path_id = CURRVAL('seq_path_id')
+ WHERE node1_id = %s AND node2_id = %s
+ """, (
+ min(nodes[i - 1], nodes[i]),
+ max(nodes[i - 1], nodes[i]),
+ ))
+
conn.commit()
cur.close()
View
2 graph_reduction.txt
@@ -40,7 +40,7 @@ SELECT DISTINCT
-- order nodes such that node1_id < node2_id
LEAST(way_node1.node_id, way_node2.node_id) AS node1_id,
GREATEST(way_node1.node_id, way_node2.node_id) AS node2_id,
- BOOL(0) AS visited -- will be set to 't' by the build_paths script
+ NULL AS path_id -- will be populated by the build_paths script
INTO rail_segments
FROM way_nodes AS way_node1
INNER JOIN way_nodes AS way_node2 ON (way_node1.way_id = way_node2.way_id AND way_node1.sequence_id + 1 = way_node2.sequence_id)

0 comments on commit 4ee71af

Please sign in to comment.