leaflet icon indicating copy to clipboard operation
leaflet copied to clipboard

Simple features with ZM dimensions fail to map

Open kent37 opened this issue 8 years ago • 4 comments

Leaflet will not render linestrings with Z or ZM dimensions. Instead it gives an obscure error with an obscure traceback. It would be helpful if leaflet removed or ignored the ZM dimensions or at least gave a helpful error message.

library(leaflet)
library(magrittr)
library(sf)
#> Linking to GEOS 3.6.1, GDAL 2.1.3, proj.4 4.9.3

s1 <- rbind(c(0,3,1),c(0,4,1),c(1,5,1),c(2,5,1))
(ls <- st_linestring(s1))
#> LINESTRING Z (0 3 1, 0 4 1, 1 5 1, 2 5 1)

leaflet(ls) %>% addPolylines()
#> 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

# Works
leaflet(st_zm(ls)) %>% addPolylines()

kent37 avatar Dec 02 '17 22:12 kent37

Looks like there's no harm in calling st_zm() on a linestring that already doesn't have ZM, should we just do that always? @bhaskarvk @timelyportfolio

jcheng5 avatar Dec 03 '17 05:12 jcheng5

Yip, it doesn't hurt. We do this in mapview in addFeatures

tim-salabim avatar Dec 03 '17 10:12 tim-salabim

I just ran into this issue today. Any chance you are going to implement the fix of calling st_zm()? It seems to work if I do that in advance

see24 avatar Apr 08 '25 18:04 see24

I just ran into this issue too, after hearing from someone trying to use a web app of ours that's been in the wild without problems for more than a year. st_zm() fixed this for me, but I would have saved an hour if it had been done in leaflet.

bwcompton avatar Oct 08 '25 19:10 bwcompton