Tmap: Plotting LINESTRING with z values

Created on 14 Jan 2019  ·  4Comments  ·  Source: mtennekes/tmap

This doesn't work for me:

route = sf::read_sf("https://git.io/fhnA2")
tm_shape(route) +
  tm_lines(col = "blue")

This - with no Z component, works:

route = sf::read_sf("https://git.io/fhnAr")
tm_shape(route) +
  tm_lines(col = "blue") +
  tm_shape(location$osm_polygons) +
  tm_polygons(fill = "red")

Hope this is of use - apologies if I've missed something.

Most helpful comment

In mapview I use the equivalent of leaflet() %>% addPolygons(data=sf::st_zm(route)) which effectively removes all z and/or m values from the coordinates.

See:
https://github.com/r-spatial/mapview/blob/develop/R/extensions.R#L675

All 4 comments

Hmm, both examples give

image

Did you get errors or the wrong output?

Aha - it's only when in view mode. Reprex this time:

library(tmap)
route = sf::read_sf("https://git.io/fhnA2")
tm_shape(route) +
    tm_lines(col = "blue")
#> Linking to GEOS 3.5.1, GDAL 2.1.2, PROJ 4.9.3

ttm()
#> tmap mode set to interactive viewing
tm_shape(route) +
    tm_lines(col = "blue")
#> 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

Created on 2019-01-14 by the reprex package (v0.2.1)

Session info

devtools::session_info()
#> ─ Session info ──────────────────────────────────────────────────────────
#>  setting  value                       
#>  version  R version 3.5.1 (2018-07-02)
#>  os       Debian GNU/Linux 9 (stretch)
#>  system   x86_64, linux-gnu           
#>  ui       X11                         
#>  language (EN)                        
#>  collate  en_US.UTF-8                 
#>  ctype    en_US.UTF-8                 
#>  tz       Etc/UTC                     
#>  date     2019-01-14                  
#> 
#> ─ Packages ──────────────────────────────────────────────────────────────
#>  package      * version   date       lib
#>  assertthat     0.2.0     2017-04-11 [1]
#>  backports      1.1.2     2017-12-13 [1]
#>  base64enc      0.1-3     2015-07-28 [1]
#>  callr          3.0.0     2018-08-24 [1]
#>  class          7.3-14    2015-08-30 [2]
#>  classInt       0.2-3     2018-04-16 [1]
#>  cli            1.0.1     2018-09-25 [1]
#>  codetools      0.2-15    2016-10-05 [2]
#>  colorspace     1.3-2     2016-12-14 [1]
#>  crayon         1.3.4     2017-09-16 [1]
#>  crosstalk      1.0.0     2016-12-21 [1]
#>  curl           3.2       2018-03-28 [1]
#>  DBI            1.0.0     2018-05-02 [1]
#>  desc           1.2.0     2018-05-01 [1]
#>  devtools       2.0.1     2018-10-26 [1]
#>  dichromat      2.0-0     2013-01-24 [1]
#>  digest         0.6.18    2018-10-10 [1]
#>  e1071          1.7-0     2018-07-28 [1]
#>  evaluate       0.12      2018-10-09 [1]
#>  fs             1.2.6     2018-08-23 [1]
#>  glue           1.3.0     2018-07-17 [1]
#>  htmltools      0.3.6     2017-04-28 [1]
#>  htmlwidgets    1.3       2018-09-30 [1]
#>  httpuv         1.4.5     2018-07-19 [1]
#>  httr           1.3.1     2017-08-20 [1]
#>  KernSmooth     2.23-15   2015-06-29 [2]
#>  knitr          1.20      2018-02-20 [1]
#>  later          0.7.5     2018-09-18 [1]
#>  lattice        0.20-35   2017-03-25 [2]
#>  leaflet        2.0.2     2018-08-27 [1]
#>  lwgeom         0.1-4     2018-01-28 [1]
#>  magrittr       1.5       2014-11-22 [1]
#>  mapview        2.6.0     2018-09-16 [1]
#>  memoise        1.1.0     2017-04-21 [1]
#>  mime           0.6       2018-10-05 [1]
#>  munsell        0.5.0     2018-06-12 [1]
#>  pillar         1.3.0     2018-07-14 [1]
#>  pkgbuild       1.0.2     2018-10-16 [1]
#>  pkgload        1.0.2     2018-10-29 [1]
#>  png            0.1-7     2013-12-03 [1]
#>  prettyunits    1.0.2     2015-07-13 [1]
#>  processx       3.2.1     2018-12-05 [1]
#>  promises       1.0.1     2018-04-13 [1]
#>  ps             1.2.1     2018-11-06 [1]
#>  R6             2.3.0     2018-10-04 [1]
#>  raster         2.8-4     2018-11-03 [1]
#>  RColorBrewer   1.1-2     2014-12-07 [1]
#>  Rcpp           1.0.0     2018-11-07 [1]
#>  remotes        2.0.2     2018-10-30 [1]
#>  rgdal          1.3-6     2018-10-16 [1]
#>  rgeos          0.4-2     2018-11-08 [1]
#>  rlang          0.3.0.1   2018-10-25 [1]
#>  rmarkdown      1.10      2018-06-11 [1]
#>  rprojroot      1.3-2     2018-01-03 [1]
#>  satellite      1.0.1     2017-10-18 [1]
#>  scales         1.0.0     2018-08-09 [1]
#>  sessioninfo    1.1.1     2018-11-05 [1]
#>  sf           * 0.7-1     2018-10-24 [1]
#>  shiny          1.2.0     2018-11-02 [1]
#>  sp             1.3-1     2018-06-05 [1]
#>  spData         0.2.9.6   2018-12-03 [1]
#>  spDataLarge    0.3.0     2018-12-10 [1]
#>  stringi        1.2.4     2018-07-20 [1]
#>  stringr        1.3.1     2018-05-10 [1]
#>  testthat       2.0.1     2018-10-13 [1]
#>  tibble         1.4.2     2018-01-22 [1]
#>  tmap         * 2.1-1     2018-08-09 [1]
#>  tmaptools      2.0-1     2018-08-07 [1]
#>  units          0.6-2     2018-12-05 [1]
#>  usethis        1.4.0     2018-08-14 [1]
#>  viridisLite    0.3.0     2018-02-01 [1]
#>  webshot        0.5.1     2018-09-28 [1]
#>  withr          2.1.2     2018-03-15 [1]
#>  XML            3.98-1.16 2018-08-19 [1]
#>  xml2           1.2.0     2018-01-24 [1]
#>  xtable         1.8-3     2018-08-29 [1]
#>  yaml           2.2.0     2018-07-25 [1]
#>  source                              
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  Github (nowosad/spDataLarge@76c2e02)
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#>  CRAN (R 3.5.1)                      
#> 
#> [1] /usr/local/lib/R/site-library
#> [2] /usr/local/lib/R/library

I partly traced back the problem:

route = sf::read_sf("https://git.io/fhnA2")

# works
mapview(route)

# doesn't work
leaflet() %>% addPolygons(data=route)

It seems mapview fixes some problem, similar the to issue of having a named sfc. (@tim-salabim)

In mapview I use the equivalent of leaflet() %>% addPolygons(data=sf::st_zm(route)) which effectively removes all z and/or m values from the coordinates.

See:
https://github.com/r-spatial/mapview/blob/develop/R/extensions.R#L675

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hbermeo picture hbermeo  ·  8Comments

mtennekes picture mtennekes  ·  8Comments

PauGallesClara picture PauGallesClara  ·  8Comments

jarsc568 picture jarsc568  ·  8Comments

mtennekes picture mtennekes  ·  4Comments