Is there any R data structure that supports spatial lines that include height information? I'm looking for something like SpatialLinesDataFrame with support for altitude in the lines. Associating a time with each point would be nice but not essential.

My data is airplane flight tracks. I want to be able to do spatial analysis such as finding the ground distance and altitude at the closest point of approach to a fixed point on the ground, and visualizations such as maps where the segments are coloured by altitude.

The data is supplied as KML files. Currently I am using rgdal::readOGR to read the lat/lon data and metadata, and maptools::getKMLcoordinates to read the same data as a data.frame containing lat/lon/altitude. This works but it is awkward to use two data structures to contain pieces of the same data.

Any suggestions?

(I originally posted this on StackOverflow but no answers there...)

  • Are the elevations defined at the nodes of the lines, or are line segments at a constant defined height, or does the height change along line segments? I can see various ways of doing it depending on how the elevation is related to the lines... – Spacedman Nov 1 '15 at 15:02
  • The elevations are defined at the nodes - I have a sequence of lat / lon / altitude points. The points are close enough that I can assume straight lines between them. – Kent Johnson Nov 1 '15 at 22:28

I'd denormalise it into a data frame of x, y, z, time, id columns. Then a path is simply the 3d set of x,y,z locations, ordered by time, within the same id value.

If you need the altitude info in a "linesy" object then you'll need to construct line segments with an initial elevation and final elevation attribute.

  • Yes, that sounds better than the list of dataframes I am using. – Kent Johnson Nov 1 '15 at 23:21

No, there is no such thing for elevation, so you need to indeed to read this in separately and make it an attribute. However, you can do time. See the spacetime package.

  • Thanks, without the altitude data spacetime and trajectories are not really helpful. – Kent Johnson Nov 1 '15 at 22:38

In addition to spacetime you may want to look at package trajectories, it has a vignette with some plots with colored line segments.


With the advent of the simple features for R package, this is straighforward. LINESTRING objects may have four dimensions x, y, z, t. Sometimes the st_zm function is needed to strip z, t for use in e.g. mapping.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.