[GIS] Connecting points (bus stops), which don’t lie on lines (LINESTRING), to network

Networkpgroutingpostgisqgis-2

I need to connect bus stops (points) to a network layer (OSM data). These bus stops do not lie directly on the lines (see screenshot) nor should their location be moved. I use PostGIS, pgrouting and QGIS and the network is already routable with source and target columns etc.

enter image description here

Mainly I want to do two things afterwards:

  1. Getting the distances between the bus stops using shortest path analysis.
  2. Creating isochrones with walking distances from the bus stop using the OSM network.

To get exact values it is necessary, that the routing 'starts' and 'stops' most closely to the bus stops. In many cases the closest existing node will be too far away to get exact values. But there should not be a routing to the actual point location of the bus stop. In my example on the picture you can see how the routing between stops should look like.

Is there a possibility to insert new nodes automatically into the network (LINESTRING) which are closest to the bus stops or is it possible to start routing on a kind of 'dummy point' which is set just for the query (similar to what the road graph plugin in QGIS does)?

Best Answer

The first part of the solution is this:

SELECT a.id, ST_Closestpoint(ST_Collect(b.geom_way), a.geom) AS geom 
FROM point_table a, line_table b
GROUP BY a.id, a.geom;

This snaps the busstops to the lines of the road network as you can see in the picture and works quite easy.

enter image description here

Next I will try to split the lines at the locations of the points. After splitting the lines I want to use pgr_createTopology again. After that it should be possible to create a query to find out the nearest nodes to the busstops, which will than be my newly generated nodes at the 'splitpoints'.

I would be grateful if somebody had a hint for me how to split linestring with point features in postgis, since after I looked at similar questions there does not seem to be an easy solution for that at the moment.

Related Question