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

tm_basemap() tiles in plot mode are flipped. #2480

Closed
ar-puuk opened this issue Nov 20, 2024 · 2 comments
Closed

tm_basemap() tiles in plot mode are flipped. #2480

ar-puuk opened this issue Nov 20, 2024 · 2 comments

Comments

@ar-puuk
Copy link

ar-puuk commented Nov 20, 2024

Describe the bug
When using tm_basemap() function after a tmap plot, the basemap seems to be flipped/mirrored(?) and does not align with the sf object. This is just an issue with the plot mode and works fine in the view mode. This also does not seem to be the issue with basemap provider as well.

To Reproduce

library(sf)
#> Linking to GEOS 3.12.2, GDAL 3.9.3, PROJ 9.4.1; sf_use_s2() is TRUE
library(tmap)
#> 
#> Attaching package: 'tmap'
#> The following object is masked from 'package:datasets':
#> 
#>     rivers

tmap_mode("plot")
#> ℹ tmap mode set to "plot".

nc <- st_read(system.file("shape/nc.shp", package="sf"))
#> Reading layer `nc' from data source 
#>   `C:\Users\pukar\AppData\Local\R\win-library\4.4\sf\shape\nc.shp' 
#>   using driver `ESRI Shapefile'
#> Simple feature collection with 100 features and 14 fields
#> Geometry type: MULTIPOLYGON
#> Dimension:     XY
#> Bounding box:  xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965
#> Geodetic CRS:  NAD27

qtm(
  nc,
  fill = NA,
  col = "red"
) +
  tm_basemap()

qtm(
  nc,
  fill = NA,
  col = "red"
) +
  # changing provider still has the same issue
  tm_basemap("Esri.WorldImagery")

sf::sf_extSoftVersion()
#>           GEOS           GDAL         proj.4 GDAL_with_GEOS     USE_PROJ_H 
#>       "3.12.2"        "3.9.3"        "9.4.1"         "true"         "true" 
#>           PROJ 
#>        "9.4.1"

Created on 2024-11-20 with reprex v2.1.1

Session info

sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value
#>  version  R version 4.4.2 (2024-10-31 ucrt)
#>  os       Windows 11 x64 (build 22631)
#>  system   x86_64, mingw32
#>  ui       RTerm
#>  language (EN)
#>  collate  English_United States.utf8
#>  ctype    English_United States.utf8
#>  tz       America/New_York
#>  date     2024-11-20
#>  pandoc   3.5 @ C:/PROGRA~1/Pandoc/ (via rmarkdown)
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package           * version    date (UTC) lib source
#>  abind               1.4-8      2024-09-12 [1] CRAN (R 4.4.1)
#>  base64enc           0.1-3      2015-07-28 [1] CRAN (R 4.3.0)
#>  class               7.3-22     2023-05-03 [2] CRAN (R 4.4.2)
#>  classInt            0.4-10     2023-09-05 [1] CRAN (R 4.3.1)
#>  cli                 3.6.3      2024-06-21 [1] CRAN (R 4.4.1)
#>  codetools           0.2-20     2024-03-31 [1] CRAN (R 4.3.3)
#>  colorspace          2.1-1      2023-07-13 [1] R-Forge (R 4.3.1)
#>  cols4all            0.8        2024-10-16 [1] CRAN (R 4.4.1)
#>  crosstalk           1.2.1      2023-11-23 [1] CRAN (R 4.3.2)
#>  curl                6.0.1      2024-11-12 [1] https://ar-puuk.r-universe.dev (R 4.4.2)
#>  data.table          1.16.99    2024-09-25 [1] https://ar-puuk.r-universe.dev (R 4.4.1)
#>  DBI                 1.2.3.9016 2024-11-18 [1] https://ar-puuk.r-universe.dev (R 4.4.2)
#>  dichromat           2.0-1      2016-12-23 [1] R-Forge (R 4.3.1)
#>  digest              0.6.37     2024-08-19 [1] CRAN (R 4.4.1)
#>  e1071               1.7-16     2024-09-16 [1] CRAN (R 4.4.1)
#>  evaluate            1.0.1      2024-10-10 [1] CRAN (R 4.4.1)
#>  fastmap             1.2.0      2024-05-15 [1] CRAN (R 4.4.0)
#>  fs                  1.6.5      2024-10-30 [1] CRAN (R 4.4.1)
#>  glue                1.8.0      2024-09-30 [1] CRAN (R 4.4.1)
#>  htmltools           0.5.8.1    2024-04-04 [1] CRAN (R 4.3.3)
#>  htmlwidgets         1.6.4      2023-12-06 [1] CRAN (R 4.3.2)
#>  KernSmooth          2.23-24    2024-05-17 [1] CRAN (R 4.4.0)
#>  knitr               1.49       2024-11-08 [1] CRAN (R 4.4.2)
#>  lattice             0.22-6     2024-03-20 [1] CRAN (R 4.3.3)
#>  leafem              0.2.3      2023-09-17 [1] CRAN (R 4.3.1)
#>  leaflegend          1.2.1      2024-05-09 [1] CRAN (R 4.4.0)
#>  leaflet             2.2.2      2024-03-26 [1] CRAN (R 4.3.3)
#>  leaflet.providers   2.0.0      2023-10-17 [1] CRAN (R 4.3.1)
#>  leafsync            0.1.0      2019-03-05 [1] CRAN (R 4.3.1)
#>  lifecycle           1.0.4      2023-11-07 [1] CRAN (R 4.3.2)
#>  lwgeom              0.2-14     2024-02-21 [1] CRAN (R 4.3.2)
#>  magrittr            2.0.3      2022-03-30 [1] CRAN (R 4.3.1)
#>  maptiles            0.8.0      2024-10-22 [1] CRAN (R 4.4.1)
#>  microbenchmark      1.5.0      2024-09-04 [1] CRAN (R 4.4.1)
#>  png                 0.1-8      2022-11-29 [1] CRAN (R 4.3.0)
#>  proxy               0.4-27     2022-06-09 [1] CRAN (R 4.3.1)
#>  purrr               1.0.2      2023-08-10 [1] CRAN (R 4.3.1)
#>  R6                  2.5.1      2021-08-19 [1] CRAN (R 4.3.1)
#>  raster              3.6-30     2024-10-02 [1] CRAN (R 4.4.1)
#>  RColorBrewer        1.1-3      2022-04-03 [1] CRAN (R 4.3.0)
#>  Rcpp                1.0.13-1   2024-11-02 [1] CRAN (R 4.4.2)
#>  reprex              2.1.1      2024-07-06 [1] CRAN (R 4.4.1)
#>  rlang               1.1.4      2024-06-04 [1] CRAN (R 4.4.0)
#>  rmarkdown           2.29       2024-11-04 [1] CRAN (R 4.4.2)
#>  rstudioapi          0.17.1     2024-10-22 [1] CRAN (R 4.4.1)
#>  s2                  1.1.7      2024-07-17 [1] CRAN (R 4.4.1)
#>  sessioninfo         1.2.2      2021-12-06 [1] CRAN (R 4.3.1)
#>  sf                * 1.0-19     2024-11-11 [1] Github (r-spatial/sf@7dd4173)
#>  slippymath          0.3.1      2019-06-28 [1] CRAN (R 4.3.2)
#>  sp                  2.1-4      2024-04-30 [1] CRAN (R 4.3.3)
#>  spacesXYZ           1.3-0      2024-01-23 [1] CRAN (R 4.3.3)
#>  stars               0.6-7      2024-11-07 [1] CRAN (R 4.4.2)
#>  terra               1.7-83     2024-10-14 [1] CRAN (R 4.4.1)
#>  tmap              * 3.99.9003  2024-11-13 [1] https://ar-puuk.r-universe.dev (R 4.4.2)
#>  tmaptools           3.1-1      2024-09-10 [1] Github (mtennekes/tmaptools@7e42da8)
#>  units               0.8-5      2023-11-28 [1] CRAN (R 4.3.2)
#>  vctrs               0.6.5      2023-12-01 [1] CRAN (R 4.3.2)
#>  viridisLite         0.4.2      2023-05-02 [1] CRAN (R 4.3.1)
#>  withr               3.0.2      2024-10-28 [1] CRAN (R 4.4.1)
#>  wk                  0.9.4      2024-10-11 [1] CRAN (R 4.4.1)
#>  xfun                0.49       2024-10-31 [1] CRAN (R 4.4.1)
#>  XML                 3.99-0.17  2024-06-25 [1] CRAN (R 4.4.1)
#>  xml2                1.3.6      2023-12-04 [1] CRAN (R 4.3.1)
#>  yaml                2.3.10     2024-07-26 [1] CRAN (R 4.4.1)
#> 
#>  [1] C:/Users/pukar/AppData/Local/R/win-library/4.4
#>  [2] C:/Program Files/R/R-4.4.2/library
#> 
#> ──────────────────────────────────────────────────────────────────────────────

Additional context
This is how it used to look like before.

Paste the output of your `sessionInfo()` and `sf::sf_extSoftVersion()`
@ar-puuk ar-puuk changed the title tm_basemap() projection does not look correct. tm_basemap() tiles in plot mode are flipped. Nov 20, 2024
@rCarto
Copy link
Contributor

rCarto commented Nov 21, 2024

This is a terra issue. See rspatial/terra#1627.
See also riatelab/maptiles#34.

@ar-puuk
Copy link
Author

ar-puuk commented Nov 21, 2024

Thanks @rCarto. Updating to the build version of terra fixed the issue.

@ar-puuk ar-puuk closed this as completed Nov 21, 2024
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

2 participants