add_z <- function(x, z_name){ st_geometry(x) <- st_sfc(st_multipoint(cbind(st_coordinates(x), x[[z_name]]))) %>% st_cast("POINT") return(x) }