PHOTOGRAPHERS and walkers have been warned by police not to stand on railway lines after a man narrowly escaped being hit by a steam engine while taking a picture of a viaduct featured in the Harry Potter films.

The driver of a steam train travelling from Fort William had to brake hard to avoid hitting the man, who was standing between the railway lines with a camera on a tripod taking photos of the Glenfinnan Viaduct.

The 115-year-old viaduct above Loch Sheil in Lochaber is one of the most famous railway landmarks in the world.

The 21-arch crossing is part of the Mallaig extension of the West Highland line, built between 1897 and 1901.

It has featured in films and TV series, including Charlotte Gray, Monarch of the Glen, and most famously Harry Potter and the Chamber of Secrets, in which a crucial sequence revolves around the Hogwarts Express crossing it. It has also appeared in other Potter films.

A British Transport Police (BTP) spokesman said that around 11am on Wednesday the driver braked after seeing two elderly women at the side of the line near the viaduct.

He added: "Even more shockingly, he reported that a man was standing between the lines taking a photograph with a camera on a tripod. It is believed the man only narrowly escaped being struck by the train."

BTP Constable Matt O'Neill, based in Inverness, said: "There may be some iconic scenery and wonderful vistas in this part of the world, and while we don't want to spoil anyone's pleasure, people must be aware that trespassing on the railway line remains a criminal offence and the potential consequences do not bear thinking about."

A Network Rail spokesman described the incidents as "worrying" and added: "Trespassing on the railway line is not only a criminal offence, it can be extremely dangerous.

"Walkers and others could find themselves in the path of a train, even on a line they believe is not used regularly."

There have been a number of incidents of people trespassing over railways in the Highlands.

Earlier this week a man was reported trespassing on the line between Edderton and Ardgay, north of Inverness, as a train approached. Police believe that local people have been using the railway line as a shortcut.