I can think of two possible solutions:
You build some kind of rig similair to a selfie stick. Mount it somewhere on the locomotive and try to not get it in the shot or digitally remove it
Choose a place where a road is next to the traintrack, mount the camera to a car (Or other vehicle) and drive along the track.
I see a few difficulties with both tho.
For the first one, you will need to buy/create the rig which could be rather difficult, especially if you have a bigger camera. You also won't be able to control the camera, expect if you have wireless control. You would also need to look with a camera hanging out quite a bit from the locomotive, that there are no other trains, trees, signals, tunnels... which are in the range of the camera.
For the second option, you would need to first find that road which could be difficult especially if you can't change the track where the train drives.
Depending on the road, you would also need to get some stabilisation system, so that the image doesn't shake to much. This might be needed for the train as well.