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:


# 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) %>% 

#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)

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 agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.