How to design a secure foot or car pathway across railroads in Factorio?
Solution 1:
You can do this with rail signals and gates. Rail signals output their state to the circuit network, and can be controlled by the circuit network. Similarly, gates output a signal when a player or vehicle tries to open them, and can be forced open or closed with circuit network signals.
So, if you have an area of your railroad surrounded by gates with rail signals where a train would enter the area, then you can lock the gates when the signal turns red or yellow, and you can force the signal red when a player approaches the crossing. This won't lock the gate with no train because rail signals don't output anything to the network if they are being set to red by the network. If you have a rail system with multiple rails you may need additional gates in between the rails to make sure that you are detecting the player throughout the whole crossing area.
For a visual indicator, lights can be turned on and off and set to different colors by the circuit network. You can, for example, have indicator lights to show the network signal that is forcing the rail signal state, and the network signal that would lock the gate.