SymbolixAU / mapdeck

R interface to Deck.gl and Mapbox
https://symbolixau.github.io/mapdeck/articles/mapdeck.html
362 stars 40 forks source link

binary path layer #276

Open dcooley opened 4 years ago

dcooley commented 4 years ago

working fiddle

TODO


List columns

the call to sfheaders::api::sf_to_df( data, sfc, sfc_column, sfc_coordinates, true ) will need to supply the list columns. Which can be worked out by seeing if any of the fill / stroke / etc. properties reference a list-column (in R)


df <- data.frame(
    x = 1:10
    , y = 10:1
    , z = letters[1:10]
    , a = rnorm(10)
    , id = c(1,1,1,1,1,2,2,2,2,2)
)

sf <- sfheaders::sf_linestring(
  x = "x"
  , y = "y"
  , obj = df
  , list_columns = c("z","a")
  , keep = T
  , linestring_id = "id"
)

mapdeck() %>%
  add_path(
    data = sf
    , stroke_width = "id"
  )
dcooley commented 4 years ago

A couple of benchmarks showing listing and colouring

n <- 1e6
df <- data.frame(
    id = rep(1:(n/10), each = 10)
    , x = rnorm( n )
    , y = rnorm( n )
    , z = rnorm( n )
    , val = rnorm( n )
)

sf <- sfheaders::sf_linestring(
    obj = df
    , x = "x"
    , y = "y"
    , linestring_id = "id"
    , keep = TRUE 
)

sf2 <- sf

microbenchmark(
    one = {
                ## colouring a list, then unnesting
        sf2$col <- colourvalues::colour_values( sf$val )
        df2 <- sfheaders::sf_to_df( sf = sf2, fill = TRUE, unlist = "col")
    },
    two = {
                ## unnesting, then colouring
        df3 <- sfheaders::sf_to_df( sf = sf, fill = TRUE, unlist = "val" )
        df3$val <- colourvalues::colour_values( df3$val )
    },
    times = 25
)

# Unit: milliseconds
# expr       min        lq     mean   median       uq      max neval
#  one 1107.2474 1185.0316 1538.977 1244.534 1500.936 4105.763    25
#  two  900.0465  937.2211 1115.096 1000.710 1217.072 1632.342    25
dcooley commented 4 years ago
microbenchmark(
    one = {
                ## colouring a vector, then "unnesting" the vector
        sf2$col <- colourvalues::colour_values( sf$z )
        df2 <- sfheaders::sf_to_df( sf = sf2, fill = TRUE, unlist = "col")
    },
    two = {
                ## "unnesting" the vector, then colouring
        df3 <- sfheaders::sf_to_df( sf = sf, fill = TRUE, unlist = "z" )
        df3$val <- colourvalues::colour_values( df3$z )
    },
    times = 25
)

# Unit: milliseconds
# expr      min       lq     mean   median        uq      max neval
#  one 574.2571 603.5079  725.375 619.6853  783.5886 1286.826    25
#  two 855.9342 903.8275 1018.179 934.8218 1047.9458 1600.117    25