# Calculating distance from a central point in three dimensions and visualising the result

We will shortly be collecting data from our remote systems that track ADS-B signals from Aircraft. This data will provide the lat/lon in epsg:4326 (wgs84) and a height in meters. The station location is known in EPSG:4326 as a lat/lon.

We want to be able to visualize the effective range of the signals for planning additional stations. The 3D is required to visualize LOS (line of Sight) shadows due to mountains, man made obstacles, etc.

How do we do the following using PostGis:

• Calculate the bearing from True North from the station to the aircraft position
• Calculate the distance over the ground between the two points
• Calculate the distance to the point factoring in the height as well.

Assuming that we then store in a PostGis Database the furthermost distance for each radial, how do we do the following using PostGis:

• Create a cool looking polygon that connects the points with curves in 2D for use in OpenLayers
• Create a cool looking polygon that connects the points with curves taking in the height (z) for output to a kml file for use in Google Earth to visualize the range three dimensionally
-
If you want a viewshed analysis you might consider using GRASS. – Jakub Kania Aug 25 '13 at 20:35
Take a look at this Online Google Earth Airspace Awareness Tool kdotapp2.ksdot.org/KDOT_AirSpace/Default.aspx – Mapperz Aug 25 '13 at 21:44
@Mapperz What a NICE Tool. This is what I had in mind for visualizing our data. The idea is to see where the radio reception is good and poor and understand why. often terrain plays a big part in he LOS reception. Then we can site additional receivers to compensate. – Mark C Aug 26 '13 at 1:23

## 1 Answer

For your first two questions, ST_Azimuth and ST_Distance would seem to do the trick. To get the three-space distance you might just have to manually convert the coordinates to geocentric and then just calculate the distance using pythagoras.

-
I'd be wary of using Pythagoras for calulating spheroid distances. First go with the built in PostGIS functions, like this: ST_distance(geometry, geometry) or this: postgis.refractions.net/documentation/manual-1.3/… – Alex Leith Aug 26 '13 at 5:20
You misunderstand. Once the coordinates are converted to geocentric, a pythagorean distance is the distance between the points. – Paul Ramsey Aug 27 '13 at 17:30
If you mean geocentric like this: kartoweb.itc.nl/geometrics/Bitmaps/… then you are calculating a straight line distance through the Earth. You want a distance across the surface of the Earth, with curvature? This article says that you should use the Haversine formula for distances greater than 20 km: movable-type.co.uk/scripts/gis-faq-5.1.html. My point is that if you start goign down to first principles, it gets hard, so use some code someone has already written. – Alex Leith Aug 27 '13 at 22:33