0

I have just recently started using nice and the relatively new library(sf). It's nice to see that points and lines can have Z coordinates. For example:

> st_linestring(rbind(c(0,0,0),c(1,1,1)))
LINESTRINGZ(0 0 0, 1 1 1) 

However, it seems clear that computations using objects with Z information project it all into the XY plane:

# I wish this returned POINTZ(0.5 0.5 0.5)...
> st_centroid(st_linestring(rbind(c(0,0,0),c(1,1,1))))
POINT(0.5 0.5)

# I wish this returned 1.0...
> st_distance(st_linestring(rbind(c(0,0,0),c(1,1,1))), 
st_linestring(rbind(c(2,0,2),c(0,2,2))))
     [,1]
[1,]    0

How can I do operations using the Z coordinate without rolling my own?

(I'm guessing that either I'm missing something through lack of understanding, or that the library is so new these operations simply haven't been implemented yet.)

jtolle
  • 6,803
  • 2
  • 23
  • 49
  • Not sure, but I think you need to set a crs first that describes the 3d projection – yeedle May 22 '17 at 03:25
  • @yeedle, Thanks. If I add a CRS, I get the same thing. I guess operations like centroid and distance are meant to be defined *on the map*, not in 3-D space. – jtolle May 22 '17 at 15:15

1 Answers1

1

Right now you can't without writing (or passing on as argument to st_distance) your own distance function.

Edzer Pebesma
  • 3,474
  • 14
  • 23