1

How can an intersection of 3D object with 3D object be done in R, for example a 3D line with 3D polygon ? Saw that "sf" provides some possibilities but didn't get the desired result. What was accomplished:

library(dplyr)
library(sf)

# create 3D polygon
pol1 <- data.frame(lon = c(6,6,6,6,6),
                   lat = c(3,1,1,3,3),
                   alt = c(2,2,4,4,2)) %>% 
st_as_sf(coords = c("lon", "lat", "alt"), dim = "XYZ") %>% 
summarise(do_union = FALSE) %>% 
st_cast("POLYGON")

#create 3D line
lns1 <- matrix(c(5,8,2,2,2,4), ,  3) %>% st_linestring(dim = "XYZ")

# trying to find the point where they intersect
>st_intersection(lns1, pol1)
GEOMETRYCOLLECTION EMPTY

Is there a better way to do this ? Thankful for any suggestions

  • Is what you've tried consistent with intersections ignoring the 3rd dimension and doing only 2D geometry on the X and Y coordinates? Because I suspect that's the limits of its capabilities. – Spacedman Sep 23 '18 at 22:23
  • @Spacedman the code works for 2D objects. I thought "sf" should be able to handle 3D operations since there is a possibility to define 3D objects with it. For example an intersection between a 3D line and another 3D line is done correctly. Could there be an alternative for 3D line - 3D polygon intersection ? – adl Sep 23 '18 at 22:27

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.