Building rail is a good way to hedge against an unknown time period for peak oil in securing natural resources for the future. Especially with coal expected to last several hundred years, coal powered trains could once again be the dominant form of cross-continental shipping in the future.
Actually the railroads sole purpose is to supplement it's sea shipping as the Panama Canal gets to full capacity and ships continue to get bigger than it can support. Even the expansion of the Canal, supposed to be finished in mid 2016, and the larger "New Panamax" size limitations have already been far exceeded by container ships (among others). The ship unloads containers on the Pacific side, the railroad carries them to the Atlantic side and another ship picks them up (and vice versa of course). I'm sure they'd rather a new and improved bigger canal but this is far cheaper and once you have the initial rail laid it's infinitely easier to expand it's capacity than a canal. I'd bet that it's a metric shitload better environmentally too.
If I was Peru and Brazil I would jump on this Chinese money with the quickness before the Northwest Passage becomes more and more feasible and open longer throughout the year but their are other issues with that so who knows if it will ever be a feasible contender to the Canal.
Unlike us, China actually plans long term and understands that infrastructure investment pays for itself over the long term. The days of America doing awesome infrastructure programs like that are long gone, we can barely keep our existing infrastructure structurally sound.