mapview icon indicating copy to clipboard operation
mapview copied to clipboard

lines not showing in mapview when they show in tmap

Open floswald opened this issue 2 months ago • 3 comments

I have a very odd problem that I cannot get a grip on. tmap correctly displays some linestrings, while mapview does not. I am sharing the dataframe here as object t https://www.dropbox.com/scl/fi/ye672mfbcaja7mx1dioeo/shape.Rds?rlkey=ykf3ftutyxgn17s98bjauhsk1&dl=0

tm_shape(t) +  tm_lines()
Image

mapview:

mapview::mapview(t)
Image

What is really weird is that I can plot the lines if I filter them explicity. See how the blue line well below Bordeaux now is plotted.

t %>% filter(id == "40014") %>% mapview::mapview()
Image

thanks for any help with this!

floswald avatar Oct 04 '25 16:10 floswald

Hi, there's an empty linestring in your data. Apparently, tmap will exclude those while mapview does not, meaning that it will not plot data after the empty linestring:

library(sf)
library(mapview)

t = readRDS("/home/tim/Downloads/shape.Rds")

st_is_empty(t) |>
  sum()

which(st_is_empty(t))

mapview(t[-which(st_is_empty(t)), ])

we should probably have a proper warning about this somewhere...

tim-salabim avatar Oct 05 '25 09:10 tim-salabim

argh! should have thought of that. thanks so much!

floswald avatar Oct 05 '25 11:10 floswald

No worries, I'll leave this open as a reminder to implement some warning at some stage

tim-salabim avatar Oct 05 '25 13:10 tim-salabim