MATLAB Answers

How to calculate the slope from geopraphical coordinates?

79 views (last 30 days)
Serbring
Serbring on 18 Jan 2020
Commented: Jim Riggs on 19 Jan 2020
Hi all,
I have installed a GPS logger on a vehicle, so I have extracted the geographcal coordinates in degree (longitude, latitude and elevation). I need to calculate the slope encountered by the vehicle. I came up with the following code, that is far from being good as you can see in the attached plot. How may I improve the results?
wgs84 = wgs84Ellipsoid('meters');
[gpsx,gpsy,gpsz] = geodetic2ecef(wgs84,Latitude,Longitude,Altitude);
slope=atand(diff(gpsz)./sqrt(diff(gpsx).^2+diff(gpsy).^2));
Thank you.
Best regards.

  0 Comments

Sign in to comment.

Accepted Answer

Jim Riggs
Jim Riggs on 19 Jan 2020
Edited: Jim Riggs on 19 Jan 2020
First of all, you should consider the relationship between the WGS84 lat/lon/alt and the ECEF frame. Altitude is perpendicular to the reference ellipsoid, so it is effectively parallel to "down". I would assume that if you want to know the slope encounrered by a vehicle, that implies the rate of change of "down" over the horizontal displacement. So when you tranform your data to ECEF, you lose the "down" reference.
Matlab Answers 20200118a.JPG
Rather, you should be working in a local level frame, such as North/East/Down (NED).
You can transform ECEF to NED using;
In this (NED) frame, X points to the north, Y points east, and Z points down (i.e positive z is down) . Now if you calculate delta Z over the X-Y distance (in the NED frame), it should come out as the parameter you are seeking; the change in height over the change in horizontal distance. This would be the tangent of the local slope angle.

  2 Comments

Serbring
Serbring on 19 Jan 2020
Hi Jim,
thank you so much for your answer. So the code should be something like, right? I set up the origin of the frame as the initial point of the vehicle.
[xNorth,yEast,zDown] = geodetic2ned(Latitude,Longitude,Altitude,Latitude(1),Longitude(1),Altitude(1),wgs84);
slope=atand(diff(zDown)./sqrt(diff(xNorth).^2+diff(yEast).^2));
The plot is still confusing....
Cheers,
Michele
Jim Riggs
Jim Riggs on 19 Jan 2020
Yes, very good. (Note that Matlab also has a function geodetic2enu which transforms the lat/lon/alt to ENU which is East, North, Up. In this case, X is to the east, Y is to the north, and Z is up. So you can chose to work in a local-level system with Z up or down, whichever you prefer)
Unless you show me your plot, I can't comment on it, but why do you say it is confusing? Apparently, you did not see what you were expecting.
A few thoughts:
1) Keep in mind that GPS position measurements are subject to error, and these errors will be larger or smaller based on the sattelite contellation geometry - that means the relative position of the sattelites as they move across the sky. Each of the GPS sattelites is in a different orbit, so their relative positions are constantly changing. When the satellites are spread over the sky, you get more precise measurements, but sometimes several of them are close to each other, and the measurement precision is reduced. Also, when the sattelites are high in the sky, you get more precise altitude measurements, and when they are low on the horizon, the altitude measurements have more error. So, you data may have different amounts of error given the same vehicle running over the same road, but at different times of the day. So put some thought into how measurement errors will effect the calculations that you are making. Note that the size of the altitude errors can be somewhat independent from the size of the lat/lon errors. If you have an operators manual for your GPS receiver, there may be some discussion of how to obtain error information (e.g. VDOP and HDOP), and some of these will have map data which will show you the local ground topography.
2) When you say "I need to calculate the slope encountered by the vehicle", I assume that this means the slope of the road that the vehicle is traveling on, and not the local topography. The calculation you are doing will give the slope of the road (subject to measurement errors), but if you are trying to deduce the geographical topography, this is more complicated.

Sign in to comment.

More Answers (0)

Tags

Products


Release

R2019b

Translated by