Updated

In Nairobi National Park, lions, rhinos and other animals roam just six miles (10 kilometers) from downtown Nairobi, but the carefully managed co-existence of wildlife and city life is constantly vulnerable to the pressures of urban expansion.

Sometimes the threats are posed by wildlife. As a boy, this reporter attended school across a street from the park and once had to wait in a bus until a lion was shooed away from the parking lot. But more often, the threat is intrusion by humans.

That encroachment has blocked animals' migratory paths along the only unfenced side of the 45-square-mile (117-square-kilometer) park, where tourists can photograph striking images of animals in tall grass with city high-rises in the background.

Now, the government has announced plans to build a railway that will traverse part of the reserve. The railway for cargo and passengers will go from Kenya's Mombasa port to Nairobi as part of a regional plan to upgrade rail links, replacing a track originally built under British rule more than a century ago.

The Kenyan railway, which would reduce travel time and costs and relieve pressure on roads, is expected to be operational by 2018, according to Kenya Railways.

A Chinese-made highway was also supposed to cut into the park, to ease Nairobi's traffic gridlock. That plan stalled in 2013 after environmentalists opposed it in court.

The warden of Nairobi National Park said compromise is often the only way to deal with development projects.

"Sometimes, you must accept what cannot be changed," Senior Warden Nelly Palmeris said in an interview with The Associated Press in her office at the park's main entrance. "Many times, you are just trying to see how to mitigate and how to reduce."

Still, the park has benefited from its cheek-by-jowl existence alongside Kenya's seat of political power. Over the years, Kenyan presidents have burned confiscated ivory here in a show of anti-poaching resolve. The headquarters of the national Kenya Wildlife Service sits at the entrance (a road sign there reads: "Warthogs and children have right of way.")

Palmeris, whose annual operating budget is about $370,000, said the Nairobi park has sometimes had easier access to helicopters and other resources than other parks, and that poaching incidents here often get more publicity. One park rhino was poached for its horns in 2014, but there has been no poaching of the park's "flagship species" so far this year, according to Palmeris. A unit of 60 rangers keeps close tabs on rhinos by assigning them names and specific guardians, she said.

Park fees range from $50 for non-resident adults to about $5 for adult Kenyans. Numerous signs around government offices near the entrance warn against taking bribes.

Esmond Martin, a Nairobi-based conservationist, described the park as a "success story," partly because it has a significant rhino population and there is relatively little poaching. But he said animals that leave the park are sometimes poached and noted that local communities do not get a share of park revenue, meaning there is less incentive to protect wildlife.

Martin said some national parks in other countries are close to big cities, but the "big game" in Nairobi National Park, which also has leopards and buffalos, makes it unique.

Sometimes there are incidents because the park borders an airport and is so near to Kenya's capital, whose population is more than 3 million.

Herders have killed lions that wandered out of the park.

"You go and pick up a leopard from the runway and the next minute it's a monkey in somebody's house," Palmeris said.

Aliya Habib, who heads a group called Friends of Nairobi National Park, acknowledged that there are development needs but pointed out that the park is a "massive selling point for Kenya" that is becoming more vulnerable. Her group organizes park cleanups and other activities.

Under the railway plan, a stretch of about 7.5 miles (12 kilometers) of track would slice into the park because compensating residents and businesses to build outside the park is too costly, the government said. The park boundary will remain intact, animals will be able to roam underneath elevated sections of the railway and the Kenya Wildlife Service will be compensated under a pact announced by state agencies.

Conservation and development "can move together," Jeremiah Kianga, chairman of Kenya Railways, told reporters.

Richard Leakey, head of the Kenya Wildlife Service, described the deal as a "pragmatic alternative which this country needs to try."

Though he said that "ideally there should be no transport in the national park."