I am preparing a routing function with pgrouting with the travel model in public transport (bus).
I already have all the stops related to the table of ways (downloaded by osm2pgrouting) I have my table with the stops and the source and target of the segment of the line in which they are.
But my question is how to prepare a query where you can find the closest stop at the beginning of the route and at the end of the route and also start at that stop that will be the closest and end at the stop closest to the destination.
The only thing I have achieved is to represent the bus route, going through all its stops, but of course, when I launch my query it represents the entire bus route, and I don't want that. As I said before, what I want is that the beginning and end of the route be the segment of the line where the stops are, but not that the entire bus line represents me.