GPS 3D visualization

rgl package for 3D plotting

The sample route on Google map

I use the same data that I posted before. The sample test route looks like a square as follows:

However, it is a 2d plot; it does not show the altitude information. The reason why I choose this route is that the course has turns, flat road, and inclined path at the same time.

To show this, I decide to use rgl R package which can draw the 3D plot of GPS path.

Load package

library(rgl)

Load data

mytelematics <- read.csv("https://raw.githubusercontent.com/issactoast/theissacleedotcom/master/static/data/sampletrip.csv", header = TRUE, fill = TRUE)

gps_data <- subset(mytelematics, select = c(Timestamp, Long, Lat, Alt.m.))
colnames(gps_data) <- c("Timestamp", "x", "y", "z")

GPS data includes location information such as longitude, latitude, and altitude at each time step.

Timestamp x y z
24-May-2019 18:11:23.018 -91.53799 41.66253 197.2922
24-May-2019 18:11:23.056 -91.53799 41.66253 197.2922
24-May-2019 18:11:23.097 -91.53799 41.66253 197.2821
24-May-2019 18:11:23.138 -91.53799 41.66253 197.2821
24-May-2019 18:11:23.171 -91.53799 41.66253 197.2821
24-May-2019 18:11:23.212 -91.53799 41.66253 197.2821
24-May-2019 18:11:23.258 -91.53799 41.66253 197.2821
24-May-2019 18:11:23.290 -91.53799 41.66253 197.2821
24-May-2019 18:11:23.328 -91.53799 41.66253 197.2821
24-May-2019 18:11:23.366 -91.53799 41.66253 197.2821
24-May-2019 18:11:23.405 -91.53799 41.66253 197.2821
24-May-2019 18:11:23.449 -91.53799 41.66253 197.2821
24-May-2019 18:11:23.485 -91.53799 41.66253 197.2821
24-May-2019 18:11:23.530 -91.53799 41.66253 197.2821
24-May-2019 18:11:23.558 -91.53799 41.66253 197.2821
24-May-2019 18:11:23.598 -91.53799 41.66253 197.2821
24-May-2019 18:11:23.636 -91.53799 41.66253 197.2821
24-May-2019 18:11:23.679 -91.53799 41.66253 197.2821
24-May-2019 18:11:23.720 -91.53799 41.66253 197.2821
24-May-2019 18:11:23.756 -91.53799 41.66253 197.2821
24-May-2019 18:11:23.792 -91.53799 41.66253 197.2821
24-May-2019 18:11:23.831 -91.53799 41.66253 197.2821
24-May-2019 18:11:23.869 -91.53799 41.66253 197.2821
24-May-2019 18:11:23.908 -91.53799 41.66253 197.2821
24-May-2019 18:11:23.949 -91.53799 41.66253 197.2821
24-May-2019 18:11:23.985 -91.53799 41.66253 197.2821
24-May-2019 18:11:24.027 -91.53799 41.66253 197.2821
24-May-2019 18:11:24.062 -91.53799 41.66253 197.2821
24-May-2019 18:11:24.111 -91.53799 41.66253 197.2597
24-May-2019 18:11:24.140 -91.53799 41.66253 197.2597
24-May-2019 18:11:24.178 -91.53799 41.66253 197.2597
24-May-2019 18:11:24.219 -91.53799 41.66253 197.2597
24-May-2019 18:11:24.256 -91.53799 41.66253 197.2597
24-May-2019 18:11:24.296 -91.53799 41.66253 197.2597
24-May-2019 18:11:24.326 -91.53799 41.66253 197.2597
24-May-2019 18:11:24.366 -91.53799 41.66253 197.2597
24-May-2019 18:11:24.404 -91.53799 41.66253 197.2597
24-May-2019 18:11:24.444 -91.53799 41.66253 197.2597
24-May-2019 18:11:24.483 -91.53799 41.66253 197.2597
24-May-2019 18:11:24.521 -91.53799 41.66253 197.2597
24-May-2019 18:11:24.562 -91.53799 41.66253 197.2597
24-May-2019 18:11:24.596 -91.53799 41.66253 197.2597
24-May-2019 18:11:24.639 -91.53799 41.66253 197.2597
24-May-2019 18:11:24.682 -91.53799 41.66253 197.2597
24-May-2019 18:11:24.715 -91.53799 41.66253 197.2597
24-May-2019 18:11:24.753 -91.53799 41.66253 197.2597
24-May-2019 18:11:24.802 -91.53799 41.66253 197.2597
24-May-2019 18:11:24.830 -91.53799 41.66253 197.2597
24-May-2019 18:11:24.870 -91.53799 41.66253 197.2597
24-May-2019 18:11:24.909 -91.53799 41.66253 197.2597
24-May-2019 18:11:24.947 -91.53799 41.66253 197.2597
24-May-2019 18:11:24.985 -91.53799 41.66253 197.2597
24-May-2019 18:11:25.024 -91.53799 41.66253 197.2597
24-May-2019 18:11:25.066 -91.53799 41.66253 197.2597
24-May-2019 18:11:25.104 -91.53799 41.66253 197.3375
24-May-2019 18:11:25.140 -91.53799 41.66253 197.3375
24-May-2019 18:11:25.179 -91.53799 41.66253 197.3375
24-May-2019 18:11:25.217 -91.53799 41.66253 197.3375
24-May-2019 18:11:25.256 -91.53799 41.66253 197.3375
24-May-2019 18:11:25.299 -91.53799 41.66253 197.3375
24-May-2019 18:11:25.335 -91.53799 41.66253 197.3375
24-May-2019 18:11:25.376 -91.53799 41.66253 197.3375
24-May-2019 18:11:25.413 -91.53799 41.66253 197.3375
24-May-2019 18:11:25.461 -91.53799 41.66253 197.3375
24-May-2019 18:11:25.491 -91.53799 41.66253 197.3375
24-May-2019 18:11:25.532 -91.53799 41.66253 197.3375
24-May-2019 18:11:25.571 -91.53799 41.66253 197.3375
24-May-2019 18:11:25.607 -91.53799 41.66253 197.3375
24-May-2019 18:11:25.645 -91.53799 41.66253 197.3375
24-May-2019 18:11:25.684 -91.53799 41.66253 197.3375
24-May-2019 18:11:25.722 -91.53799 41.66253 197.3375
24-May-2019 18:11:25.765 -91.53799 41.66253 197.3375
24-May-2019 18:11:25.800 -91.53799 41.66253 197.3375
24-May-2019 18:11:25.839 -91.53799 41.66253 197.3375
24-May-2019 18:11:25.877 -91.53799 41.66253 197.3375
24-May-2019 18:11:25.916 -91.53799 41.66253 197.3375
24-May-2019 18:11:25.957 -91.53799 41.66253 197.3375
24-May-2019 18:11:25.996 -91.53799 41.66253 197.3375
24-May-2019 18:11:26.034 -91.53799 41.66253 197.3375
24-May-2019 18:11:26.070 -91.53799 41.66253 197.3375
24-May-2019 18:11:26.110 -91.53799 41.66253 197.2889
24-May-2019 18:11:26.149 -91.53799 41.66253 197.2889
24-May-2019 18:11:26.186 -91.53799 41.66253 197.2889
24-May-2019 18:11:26.231 -91.53799 41.66253 197.2889
24-May-2019 18:11:26.266 -91.53799 41.66253 197.2889
24-May-2019 18:11:26.305 -91.53799 41.66253 197.2889
24-May-2019 18:11:26.343 -91.53799 41.66253 197.2889
24-May-2019 18:11:26.388 -91.53799 41.66253 197.2889
24-May-2019 18:11:26.422 -91.53799 41.66253 197.2889
24-May-2019 18:11:26.460 -91.53799 41.66253 197.2889
24-May-2019 18:11:26.499 -91.53799 41.66253 197.2889
24-May-2019 18:11:26.537 -91.53799 41.66253 197.2889
24-May-2019 18:11:26.576 -91.53799 41.66253 197.2889
24-May-2019 18:11:26.619 -91.53799 41.66253 197.2889
24-May-2019 18:11:26.653 -91.53799 41.66253 197.2889
24-May-2019 18:11:26.692 -91.53799 41.66253 197.2889
24-May-2019 18:11:26.732 -91.53799 41.66253 197.2889
24-May-2019 18:11:26.781 -91.53799 41.66253 197.2889
24-May-2019 18:11:26.809 -91.53799 41.66253 197.2889
24-May-2019 18:11:26.847 -91.53799 41.66253 197.2889

Route in 3D space

rgl R package is a useful tool for visualizing 3D data. To draw the graph, we need to open a pallet as like par() in the base plot as follows:

library(rgl)
open3d()
>> glX 
>>   1
mfrow3d(1, 1, sharedMouse = TRUE)

If you want to draw multiple 3d plots, you can adjust mfrow3d just like mfrow in the base plot. Plotting is also very straight forward; the same syntax but adds the suffix 3d to the plot function.

plot3d(gps_data[,2:4], col = "red", size = 5, type = "l")

You must enable Javascript to view this page properly.

The generated plot is 3d and also you can rotate the object using your mouse; drag it! Note, this function is not available in the mobile environment.

As we can see, the route looks like a square from the top, but we can see that it has uphill and down-hill from the side. If you magnify it, we can see the beginning, and the endpoint of the route does not match, which I conclude that the GPS altitude information is not that accurate than the latitude and longitude information.

Do not forget to clear the plot after drawing the plot.

clear3d()

For more information, you should check out the vignettes:

https://cran.r-project.org/web/packages/rgl/vignettes/rgl.html

Avatar
Issac Lee
PhD candidate

I believe anyone can learn anything with a proper education process.

comments powered by Disqus