leaflet
leaflet copied to clipboard
`addPolygons` fails when the polygon has 3 dimensions, even if the 3rd dimension is all zero.
At the moment, addPolygons fails with an unhelpful message when the polygon has 3 dimensions, even if the 3rd dimension is all zero.
It's reasonable that addPolygons doesn't handle 3-d polygons, but it would be helpful if it detected this and generated a more helpful error message, perhaps something like:
Objects with Z or M dimensions are not supported. Retry after removing the M or Z dimension (e.g. using
sf::st_zm).
Example:
A simple 2-D Polygon renders fine:
> pl_2d = list(
+ rbind(
+ c(0,0),
+ c(1,0),
+ c(1,1),
+ c(0,1),
+ c(0,0)
+ )
+ )
> mp_2d = sf::st_multipolygon(list(pl_2d))
> leaflet() %>%
+ addTiles() %>%
+ addPolygons(data=mp_2d)
But adding a (constant) 3rd dimension yields an error with an unhelpful message:
> pl_3d <- list(
+ rbind(
+ c(0,0,0),
+ c(1,0,0),
+ c(1,1,0), .... [TRUNCATED]
> mp_3d = sf::st_multipolygon(list(pl_3d))
> leaflet() %>%
+ addTiles() %>%
+ addPolygons(data=mp_3d)
Error in if (length(nms) != n || any(nms == "")) stop("'options' must be a fully named list, or have no names (NULL)") :
missing value where TRUE/FALSE needed
Of course, Explicitly removing the third dimension (e.g. using sf::st_zm()) resolves the issue.
> leaflet() %>%
+ addTiles() %>%
+ addPolygons(data=mp_3d %>% sf::st_zm())