Last active
August 29, 2015 14:04
-
-
Save pnorman/049ddc237caf389d92d2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
SELECT | |
w1.id AS link_id | |
FROM ways w1 | |
JOIN nodes n ON (w1.nodes[1] = n.id) | |
JOIN ( | |
SELECT wn.node_id, wn.way_id, tags, nodes FROM way_nodes wn JOIN ways w ON (wn.way_id = w.id) | |
WHERE w.tags @> hstore('highway','motorway') | |
) AS wn1 ON (wn1.node_id = n.id) | |
LEFT JOIN ( | |
SELECT wn.node_id, wn.way_id, tags, nodes FROM way_nodes wn JOIN ways w ON (wn.way_id = w.id) | |
WHERE w.tags @> hstore('highway','motorway') | |
) AS wn2 ON (wn2.node_id = n.id AND wn2.way_id != wn1.way_id) | |
LEFT JOIN ( | |
SELECT wn.node_id, wn.way_id, tags, nodes FROM way_nodes wn JOIN ways w ON (wn.way_id = w.id) | |
WHERE w.tags @> hstore('highway','motorway') | |
) AS wn3 ON (wn3.node_id = n.id AND wn3.way_id != wn1.way_id AND wn3.way_id != wn2.way_id) | |
WHERE w1.tags @> hstore('highway','motorway_link') | |
AND n.tags ? 'exit_to' | |
AND w1.linestring && ST_MakeEnvelope(-125, 40, 50, -120, 4326) | |
AND ( | |
(wn2.node_id IS NULL AND NOT (n.id = wn2.nodes[1] OR n.id = wn2.nodes[array_upper(wn2.nodes,1)])) | |
OR ( | |
wn2.node_id IS NOT NULL AND wn3.node_id IS NULL | |
AND (n.id = wn2.nodes[1] OR n.id = wn2.nodes[array_upper(wn2.nodes,1)]) | |
AND (n.id = wn3.nodes[1] OR n.id = wn3.nodes[array_upper(wn3.nodes,1)]) | |
) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment