Yes, it's called eminent domain. But if the government attempts to do so you can file a lawsuit and argue that they don't have a right to purchase your property from you. These lawsuits are expensive and take a lot of time/effort, which makes building a railway impractical by this method. To "solve" this politically would require a constitutional amendment, which is obviously not going to happen for this issue.