I would like to plot a floor plan in 3d but my attempt creates traces for every line, which is unnecessary and results in lag when plotting floor plans with many linestrings. Is there a way to plot the floor plan in 3d using a single trace?
The floor plan from a simple plot_ly()
call:
Using plotly’s split
argument:
Without split
:
The .dxf file is in this repo.
library(tidyverse)
library(plotly)
library(shiny)
library(reactable)
library(sf)
library(lwgeom)
library(bslib)
dxf <- st_read(here('d3map/giraffe360_demo_residential.dxf'))
dxf_gp <- dxf |>
group_by(geometry_type = st_geometry_type(dxf)) |>
nest()
dxf_lns <- dxf_gp |>
filter(geometry_type == "LINESTRING") |>
unnest(cols = c(data)) |>
mutate(
geometry = st_zm(geometry, "LINESTRING"),
ini = st_startpoint(geometry),
end = st_endpoint(geometry)
)
dxf_lns <- dxf_lns |>
mutate(
across(
c(ini, end),
list(
x = (point) st_coordinates(point)[,1],
y = (point) st_coordinates(point)[,2]
),
.names = "{.fn}{.col}"
)
) |>
st_as_sf()
df <- dxf_lns |>
st_coordinates() |>
as_tibble() |>
mutate(Z = 0)
df |>
plot_ly(type = "scatter3d", mode = "lines",
x = ~X, y = ~Y, z = ~Z, split = ~L1,
line = list(color = '#1f77b4', width = 1))