I had a zealous county mountie do that to me while I was set up beside the BNSF north of my home town. I was specifically hoping to catch a train being run by a friend so I could get his pic in the cab as he passed by.
Anyway, the county deputy pulls up and informs me I can't take pictures there. I look around, I'm on public right of way, I'm not obstructing traffic, and I smiled and said "I am within my constitutional rights to photograph here." He threatens to arrest me for "violating state security laws". I said "By all means, please do so if you think you have a case." He says "Don't think I won't." I replied "I'm sure you will, if you think you can make it stick."
So off we go for a nice ride in his brand new cruiser to the courthouse/jail, handcuffs and all. We go in and the sheriff comes out and says "Hey Kevin, what's up?" I explain (NOT the overzealous deputy) and the sheriff nods and tells the deputy to take off the cuffs. He goes to a phone and makes a call. About two minutes later the states attorney comes in and greets me, "Hey Kev, causing trouble again?"
Then I got to stand and listen while the states attorney read the riot act to the deputy for bringing me in when I was engaged in constitutionally protected activity. After which I got taken to lunch and then driven back to my car. BTW I don't actually think he should have done that in front of me, but it was good entertainment.
I told the story on the air the following Saturday (I do weekend news for a local radio cluster).
I don't suggest this course of action if you don't have friends in the courthouse, BTW.

And yes, I missed my friend's train but caught it a few days later--he loved his "portrait".