I have a dataset from flights. The airplane communicates with a ground station and through GPS I have the distance between the current airplane location and the ground station location, alongside with the respective longitude, latitude and altitude. What I need to do now is convert the long, lat, alt position data into a x,y,z coordinate system.
Since the ground station is at a static position I want to have it in the origin (0,0,0) of the coordinate system. I'm in search of a python module that can handle this transformation.
As an example I provide the actual data from the ground station alongside 1 position of the airplane which needs to be converted:
Ground Station [should be (0, 0, 0)]
Latitude: 41.947.694
Longitude: 3.209.083
Altitude(m): 379.41
Airplane Position: Lat.: 419.763.015.750 Long.: 34.890.851.772 Alt.[m]: 971.32
Moving the ground station to the origin I would have to subtract its position from the airplane position if I understand correctly which would mean:
Ground Station: Latitude: 0 Longitude: 0 Altitude(m): 0
Airplane Position:
Lat.: 419.721.068.056
Long.: 34.887.642.689
Alt.[m]: 591.91
Since I'm new to working with such data and tried some simple solutions and did not find anything that was converting this data I hope you can help me find a solution.
I need the converted data to simulate ellipsoids in 3D to find possible intersections. This could also be done with a different approach than python. So matlab would be fine too eve if I have never worked with that.
Transforming latitude, longitude and altitude GPS coordinates, which are geodetic coordinates (the vertical direction is the normal to the ellipsoid and not the direction to the center of the Earth) based on WGS84 reference ellipsoid, to "xyz" coordinates, geocentric, in the so-called Earth-Centered Earth-Fixed frame is a function implemented in several libraries, in several languages. Since Matlab was mentioned, it is implemented as
geodetic2ecef.It is also described in several texts and web sites, even on wikipedia, so we can safely implement it from scratch.
If you transform both the station and the plane coordinates to this ECEF x,y,z coordinate, you may compute their difference, and you already have an XYZ coordinate sistem that is (0, 0, 0) at the station.
Note, that, indeed, as mentioned in the comments, you cannot perform the differences of the latitudes or longitudes themselves with any meaningful interpretation. To find the distance between two points we can only subtract sizes, as vectors or cartesian coordinates; latitudes and longitudes don't depend linearly on those.
Now, the xyz differences computed as described before are not very significant in themselves, because their reference directions are global - the z-axis is oriented parallel to the axis of rotation of the Earth and the xz plane is parallel to the prime meridian.
For that, I propose to "localize" these differences by adding a (double) rotation of those global directions to bring them to point to directions relevant for the reference station: the new z-axis to be the geodetic vertical (towards Zenith), the new x-axis towards North from the station and the y-axis towards East.
Again, these calculations are well documented in the literature, and online and it is safe to implement them from scratch here.
Here's an example, a possible implementation in python, not very efficient since it repeats the computation of the trigonometric functions for the base, but my intention was to make it as clear as possible rather than efficient.
Since the altitudes are given in meters, I used the WGS84 semi major axis also in meters, and the results are in meters: this plane is 3215m to the North, 23210m to the East, and 549m high (measured from the plane tangent to Earth that passes through the reference station, BGR)
Although I thoroughly verified this code in several ways, I still hope nobody will fly a plane based on it :)