Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

addPolygons fails when the polygon has 3 dimensions, even if the 3rd dimension is all zero. #877

Open
warnes opened this issue Aug 23, 2023 · 0 comments

Comments

@warnes
Copy link

warnes commented Aug 23, 2023

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())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant