Baird Street Police Station in Glasgow – the location of a Strathclyde Police firearms unit – was locked down yesterday as detectives began an investigation.
It is understood Mr Gellatly, of Glasgow, was the only person involved in the incident and a police spokeswoman said they were not seeking anyone else in connection with the death.
An independent force, Lothian and Borders Police, has been appointed to oversee the investigation.
Assistant Chief Constable Bernard Higgins said: "It is with great sadness I have to tell you that a serving Strathclyde Police officer died in an incident where a firearm was discharged at Baird Street Police Office.
"Our thoughts are with the officer's family and friends at this difficult time."
Strathclyde Police identified the officer last night after his family was informed.
An ambulance was called to the station in the north of the city at around 11am following reports of the shooting. A force chaplain was also seen in attendance.
Scaffolder Neil McCuaigs, 38, was working nearby at the time of the incident.
He said: "It was all quiet then all of a sudden the police dogs at the back of the station started going mad.
"They were barking really loudly. I've never heard anything like it. It was a hell of a noise.
"I knew that something terrible had happened straight away."
Sighthill resident Patricia Rooney, 41, added: "It's really shocking. It's the officer's family I feel sorry for."
The circumstances of the incident remain unclear but the Scottish Police Federation (SPF) said that officers who handle firearms have got to follow strict guidelines and also undergo regular assessments.
SPF chairman Brian Docherty said: "It is too early to speculate as to the circumstances surrounding the tragic death and our thoughts turn immediately to his family who have lost their loved one and colleagues who have lost a friend.
"There's a regular regime of fitness and checks taken in relation to firearms officers.
"Officers are subject to national police and firearms guidance and they are assessed on a regular basis, taking in everything from their BMI and any health problems they may have, to their personal life.
"They have quite a strict regime to follow before they go through to the unit and the type of assessment they go through depends on the type of licence they're going to hold and what types of firearms they will use."
An officer can be temporarily removed from the unit if they suffer a bereavement or a change in personal circumstances, which could happen to the dead officer's colleagues.
Mr Docherty added: "It could result in firearms officers being assessed in relation to the incident and a decision taken on whether or not they're suitable to continue in the unit."
A Strathclyde Police spokeswoman said: "A full investigation into the circumstances is under way and a report will be submitted to the procurator-fiscal."