I have one shapefile with train stations (points) from a region in the UK and another shapefile with railroad tracks (lines) between these stations. Problem is, in the latter I don't have a unique line from one station to the next, but multiple connected segments. The only thing that I was able to do was to add another shapefile with junction points, to just visualize where the segment endpoints are.
How can I merge these multiple lines together, so that from station A to station B there is only one line? This is intended to be repeated for any pair of connected stations.
I would also be keen on using Python to do this, making sure there is a way for me to tell the script to merge all the lines between two stations, ignoring the junction points.
I have already tried both Unsplit lines and Dissolve, but the resulting lines are longer than they should be, e.g. they incorporate one too many segments, thus going past their intended endpoint. Unsplit lines seems to be the closest match, but I'd need to be able to restrict the merging so that it is only performed when junction points stand in the way (see image below), thus stopping at station points. If someone came up with a manual procedure, that'd be ok as well, as my dataset is not massive and I could handle it.
For purposes of clarity, see the image below. Currently, I have a number of segments and junction points in between two consecutive stations. The desired output is, instead, a unique object (line) connecting the two stations.
Dissolve does not work as the segments composing the A-to-B route do not share any common field value.