Search code examples
rkmlshapefiler-spplotkml

Is it possible to create a SpatialPolygonsDataFrame with three dimensions?


I'm using the plotKML package to write a number of shapefiles to a KML file. The shapefiles only contain coordinates in two dimensions (longitude & latitude). The plotKML package has support for reading a third dimension (elevation or altitude) from the spatial object and writing this to the KML file.

My plan is to iterate through the shapefiles and create new SpatialPolygonsDataFrames with the missing third dimension (the altitude data is contained in the 'data' slot) but the Polygon() function specifically states that the coords argument must be a "2-column numeric matrix with coordinates".

How is it possible to create a Polygon with a three column coords matrix?


Solution

  • This is not supported by sp, by design. Package sf has support for three-dimensional coordinates in polygon nodes (POLYGON Z) but this is, afaict, not (yet) supported by plotKML.