I would say that you need to be very careful about three things: if they use electrified rails in your country, the area where you plan to do it - trains tend to go slower near train stations and, crucially, the distance between the wheel guards or the cowcatcher/pilot(the device in front of a locomotive that pushes obstacles away).
Firstly, here is a little bit more information about the third (electrified) rail in the UK:
We have the largest third rail network in the world, powering electric trains, and it’s mostly found on tracks in...
www.networkrail.co.uk
Secondly, depending on which country you are in there might or might not be a cap in the maximum speed a passenger train can travel at near a train station, so do choose the location carefully. If you happen to somehow find the itineraries of freight/cargo trains it might be worth considering planning around one of those as not only you minimise the amount of people having to witness the event taking place, but they might not have complicated restrictions around them, the downside is that they are slower in general compared to passenger trains, so I think it is a trade-off to be made.
Lastly, and perhaps most importantly, you need to find what is the distance between the cowcatcher/pilot and the rails for the trains used in your country and if there are other types of wheel guards used since you would not want to just be pushed aside(especially since it won't be gentle), but instead you would want your neck to actually be able to make contact with the wheel.