Taking pictures should never be a problem, but at times and in certain areas it is (and it is ashame it is that way in some cases). And it depends on who has their eyes on you. So stay off railroad property period! If you must be there most of all try to there for the business purpose! If you are there for enjoyment, then be in a public area, or a private area made public such as a station, etc. It is best to make your presence known to the authority figure who is manning that area if possible. If you are on other private property, then respect that property owner. If asked to leave, then do so immediately. Simply put, find a better spot! Railroads have traditionally been harsh on trespassers due to juries ordering them to pay out settlements for people who were hurt while trespassing on railroad property. If you are on the property without a business purpose, then you are looked at as a liability. Railroads tend not to be very tolerant of that.
I have found, though, if you do your watching at a public place, grade crossing, or a station, you will likely have very little problems. Stay visible, stay off the right away, and keep moving by not loitering around. Many cities have loitering laws on the books, and you could wind up in trouble in that respect. I usually have very little problems. I stay visible or make myself know, and I stay out of sensitive areas. And if I am asked to leave I do immediately!!!!