From d9190fa2f7df53038788315072e4c5cfd1056761 Mon Sep 17 00:00:00 2001 From: Anthony North Date: Wed, 31 Jan 2024 06:26:45 +0000 Subject: [PATCH] check conforming geom columns on arc/line layers --- R/layer_table.R | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/R/layer_table.R b/R/layer_table.R index 84f8346..a196b30 100644 --- a/R/layer_table.R +++ b/R/layer_table.R @@ -38,11 +38,11 @@ deckgl_table <- function(object, dims = "xy", ...) { # deckgl flattened coords flat_geoms <- lapply(geom_coords, function(x) deckgl_geom(x, dims)) - # TODO: check all geometry vectors have equal number of primitive geometries per feature - # how many primitive geoms per feature feature_sizes <- if (length(geom_cols) != 0) { - wk_primitive_count(geom_coords[[1]]) + counts <- lapply(geom_coords, wk_primitive_count) + assert_equal_primitive_counts(counts) + counts[[1]] } # drop rows with empty geometries @@ -190,3 +190,18 @@ get_used_colnames <- function(layer) { unique(c(accessor_cols, tooltip_cols)) } + + +# do all geometry columns have the same number of primitive geometries per feature? +assert_equal_primitive_counts <- function(primitive_counts) { + if (vctrs::vec_size(primitive_counts) < 2L || + all(vlapply(primitive_counts, identical, primitive_counts[[1]]))) { + return(invisible()) + } + + nms <- paste0("`", names(primitive_counts), "`", collapse = ", ") + rlang::abort(c( + "Geometry columns must have equal count of primitive geometries per feature", + `x` = sprintf("Columns %s have differing primitive geometries counts", nms) + )) +}