Skip to content

Commit

Permalink
check conforming geom columns on arc/line layers
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonynorth committed Jan 31, 2024
1 parent b154f81 commit d9190fa
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions R/layer_table.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
))
}

0 comments on commit d9190fa

Please sign in to comment.