I use this series of queries to get all nodes that should represent motorway_junction
nodes:
-- create temp table to store all motorway nodes
create table motorway_nodes as (select (st_dump(st_points(linestring))).geom geom, id from ways where tags->'highway' = 'motorway');
-- create temp table to store all motorway_link start nodes
create table motorway_link_start_nodes as (select st_pointn(linestring, 1) geom, id from ways where tags->'highway' = 'motorway_link');
-- create temp table with the intersection between these two
create table offramp_starts as (select l.id lid, m.id mid, l.geom from motorway_nodes m, motorway_link_start_nodes l where st_equals(m.geom, l.geom));
-- select the OSM nodes at these locations
create table exit_nodes as (select n.* from nodes n, offramp_starts s where st_equals(n.geom, s.geom));
Not sure if there is a more optimal way...?
CTE version,