Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

have build_paths annotate the rail_segments table with the path ID

  • Loading branch information...
commit 4ee71af0364a0b238e6a58a9931411b5727b0bf6 1 parent 51f63a8
Matt Westcott gasman authored

Showing 2 changed files with 13 additions and 7 deletions. Show diff stats Hide diff stats

  1. +12 6 build_paths.py
  2. +1 1  graph_reduction.txt
18 build_paths.py
@@ -13,7 +13,7 @@
13 13 FROM junctions
14 14 INNER JOIN rail_segments ON (
15 15 (junctions.id = node1_id OR junctions.id = node2_id)
16   - AND visited = 'f'
  16 + AND path_id IS NULL
17 17 )
18 18 WHERE unfollowed_neighbour_count > 0
19 19 LIMIT 1
@@ -29,10 +29,6 @@
29 29 while True:
30 30 # continue walking the graph until we encounter another node with more than one exit
31 31 cur.execute("""
32   - UPDATE rail_segments
33   - SET visited = 't'
34   - WHERE node1_id = %s AND node2_id = %s;
35   -
36 32 SELECT
37 33 (CASE WHEN node1_id = %s THEN node2_id ELSE node1_id END) AS next_node
38 34 FROM rail_segments
@@ -40,7 +36,6 @@
40 36 (node1_id = %s AND node2_id <> %s)
41 37 OR (node2_id = %s AND node1_id <> %s)
42 38 """, (
43   - min(last_node, current_node), max(last_node, current_node),
44 39 current_node,
45 40 current_node, last_node,
46 41 current_node, last_node,
@@ -77,6 +72,17 @@
77 72 )
78 73 """, (node, i))
79 74
  75 + if i != 0:
  76 + # annotate rail_segments with the path id to mark them as visited
  77 + cur.execute("""
  78 + UPDATE rail_segments
  79 + SET path_id = CURRVAL('seq_path_id')
  80 + WHERE node1_id = %s AND node2_id = %s
  81 + """, (
  82 + min(nodes[i - 1], nodes[i]),
  83 + max(nodes[i - 1], nodes[i]),
  84 + ))
  85 +
80 86 conn.commit()
81 87
82 88 cur.close()
2  graph_reduction.txt
@@ -40,7 +40,7 @@ SELECT DISTINCT
40 40 -- order nodes such that node1_id < node2_id
41 41 LEAST(way_node1.node_id, way_node2.node_id) AS node1_id,
42 42 GREATEST(way_node1.node_id, way_node2.node_id) AS node2_id,
43   - BOOL(0) AS visited -- will be set to 't' by the build_paths script
  43 + NULL AS path_id -- will be populated by the build_paths script
44 44 INTO rail_segments
45 45 FROM way_nodes AS way_node1
46 46 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.
Something went wrong with that request. Please try again.