YOU have to get out of the way. Many railroad routes are though older, often poorer sections of town. Venturing into these areas, alone, carrying valuable photo equipment is just asking for trouble. Bring a buddy, go during the day, and don't get out of your car if you are uncomfortable with the setting. Fortunately, this was rarely an issue for my Old Main Line project, because most of the route is through decent neighborhoods and state parks.
Lighting is the most important factor.
Shooting fast moving objects in dim light, or shadows, rarely produces good results. Keep the sun at your back. A polarizing filter will help bring out the sky color. Around here, I'd estimate that just one day per month is very good for train photos. To produce the Old Main Line Tour, I captured several hundred photos, then weeded them down to what you see posted.