A You saw what is known as a “split-rail derail” – a device designed to keep errant railcars from fouling main tracks. The switch stand with the prominent “D” marks it as such. The basic premise is safety: Should one or more cars roll freely, it will be much safer to have them derail on the siding away from the main track at low speed than to possibly have a collision with a train on the main line.
The derail comes in many varieties, but they all serve the same purpose. Some are portable, for temporary use, and some are built-in, like the split-rail variety shown here, for long-term securement. Others fit between ties, also shown below. On those, the flange is forced up and over the rail.
Derails appear where unsignaled tracks join main lines. They are frequently placed on industry spur tracks, especially when hazardous materials are involved or when a customer does its own switching. Some are even controlled directly by the dispatcher, like on an interchange between two railroads, but the majority are crew-operated. – Brian Schmidt