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

First invoking raster::raster() and _then_ write GPKG with terra::writeVector() triggers a GDAL ENCODING warning (on Ubuntu / Linux Mint) #1377

Open
florisvdh opened this issue Dec 19, 2023 · 1 comment

Comments

@florisvdh
Copy link

In Ubuntu / Linux Mint, but not on Windows and macOS systems, there's an odd effect of having called raster::raster() in an R session before writing a GeoPackage with terra::writeVector(). GDAL raises an ENCODING warning in that specific scenario. See reprexes below.

I don't know whether the solution is here or in the raster package; posting it in terra is a wild guess...

> terra::gdal()
[1] "3.6.4"
# Normally no warning appears when writing a GeoPackage
tmp1 <- tempfile(fileext = ".gpkg")
obj <- terra::vect(
  x = c("POINT (7e5 7e5)", "POINT (6e5 6.5e5)"),
  crs = "EPSG:3812"
)
terra::writeVector(obj, tmp1)
unlink(tmp1)

Created on 2023-12-19 with reprex v2.0.2

Session info
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value
#>  version  R version 4.3.2 (2023-10-31)
#>  os       Linux Mint 21.2
#>  system   x86_64, linux-gnu
#>  ui       X11
#>  language nl_BE:nl
#>  collate  nl_BE.UTF-8
#>  ctype    nl_BE.UTF-8
#>  tz       Europe/Brussels
#>  date     2023-12-19
#>  pandoc   3.1.1 @ /usr/lib/rstudio/resources/app/bin/quarto/bin/tools/ (via rmarkdown)
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package     * version date (UTC) lib source
#>  cli           3.6.2   2023-12-11 [3] RSPM (R 4.3.0)
#>  codetools     0.2-19  2023-02-01 [3] RSPM (R 4.2.0)
#>  digest        0.6.33  2023-07-07 [3] RSPM (R 4.2.0)
#>  evaluate      0.23    2023-11-01 [3] RSPM (R 4.3.0)
#>  fastmap       1.1.1   2023-02-24 [3] RSPM (R 4.2.0)
#>  fs            1.6.3   2023-07-20 [3] RSPM (R 4.2.0)
#>  glue          1.6.2   2022-02-24 [3] RSPM (R 4.2.0)
#>  htmltools     0.5.7   2023-11-03 [3] RSPM (R 4.3.0)
#>  knitr         1.45    2023-10-30 [3] RSPM (R 4.3.0)
#>  lifecycle     1.0.4   2023-11-07 [3] RSPM (R 4.3.0)
#>  magrittr      2.0.3   2022-03-30 [3] RSPM (R 4.2.0)
#>  purrr         1.0.2   2023-08-10 [3] RSPM (R 4.2.0)
#>  R.cache       0.16.0  2022-07-21 [3] RSPM (R 4.2.0)
#>  R.methodsS3   1.8.2   2022-06-13 [3] RSPM (R 4.2.0)
#>  R.oo          1.25.0  2022-06-12 [3] RSPM (R 4.2.0)
#>  R.utils       2.12.3  2023-11-18 [3] RSPM (R 4.3.0)
#>  Rcpp          1.0.11  2023-07-06 [3] RSPM (R 4.2.0)
#>  reprex        2.0.2   2022-08-17 [3] RSPM (R 4.2.0)
#>  rlang         1.1.2   2023-11-04 [3] RSPM (R 4.3.0)
#>  rmarkdown     2.25    2023-09-18 [3] RSPM (R 4.3.0)
#>  rstudioapi    0.15.0  2023-07-07 [3] RSPM (R 4.2.0)
#>  sessioninfo   1.2.2   2021-12-06 [3] RSPM (R 4.2.0)
#>  styler        1.10.2  2023-08-29 [3] RSPM (R 4.2.0)
#>  terra         1.7-65  2023-12-15 [1] RSPM (R 4.3.2)
#>  vctrs         0.6.5   2023-12-01 [3] RSPM (R 4.3.0)
#>  withr         2.5.2   2023-10-30 [3] RSPM (R 4.3.0)
#>  xfun          0.41    2023-11-01 [3] RSPM (R 4.3.0)
#>  yaml          2.3.8   2023-12-11 [3] RSPM (R 4.3.0)
#> 
#>  [1] /home/floris/lib/R/library
#>  [2] /usr/local/lib/R/site-library
#>  [3] /usr/lib/R/site-library
#>  [4] /usr/lib/R/library
#> 
#> ──────────────────────────────────────────────────────────────────────────────
# If raster::raster() was called before, a GDAL ENCODING warning appears
tmp2 <- tempfile(fileext = ".gpkg")
obj <- terra::vect(
  x = c("POINT (7e5 7e5)", "POINT (6e5 6.5e5)"),
  crs = "EPSG:3812"
)
raster::raster()
#> class      : RasterLayer 
#> dimensions : 180, 360, 64800  (nrow, ncol, ncell)
#> resolution : 1, 1  (x, y)
#> extent     : -180, 180, -90, 90  (xmin, xmax, ymin, ymax)
#> crs        : +proj=longlat +datum=WGS84 +no_defs
terra::writeVector(obj, tmp2)
#> Warning in x@cpp$write(filename, layer, filetype, insert[1], overwrite[1], :
#> GDAL Message 6: dataset /tmp/RtmpLA62Py/file649273f54794.gpkg does not support
#> layer creation option ENCODING
unlink(tmp2)

Created on 2023-12-19 with reprex v2.0.2

# If raster::raster() was called before, NO warning appears if we don't write GPKG
tmp2 <- tempfile()
obj <- terra::vect(
  x = c("POINT (7e5 7e5)", "POINT (6e5 6.5e5)"),
  crs = "EPSG:3812"
)
raster::raster()
#> class      : RasterLayer 
#> dimensions : 180, 360, 64800  (nrow, ncol, ncell)
#> resolution : 1, 1  (x, y)
#> extent     : -180, 180, -90, 90  (xmin, xmax, ymin, ymax)
#> crs        : +proj=longlat +datum=WGS84 +no_defs
terra::writeVector(obj, tmp2)
unlink(tmp2)

Created on 2023-12-19 with reprex v2.0.2

Session info
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value
#>  version  R version 4.3.2 (2023-10-31)
#>  os       Linux Mint 21.2
#>  system   x86_64, linux-gnu
#>  ui       X11
#>  language nl_BE:nl
#>  collate  nl_BE.UTF-8
#>  ctype    nl_BE.UTF-8
#>  tz       Europe/Brussels
#>  date     2023-12-19
#>  pandoc   3.1.1 @ /usr/lib/rstudio/resources/app/bin/quarto/bin/tools/ (via rmarkdown)
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package     * version date (UTC) lib source
#>  class         7.3-22  2023-05-03 [3] RSPM (R 4.2.0)
#>  classInt      0.4-10  2023-09-05 [3] RSPM (R 4.3.0)
#>  cli           3.6.2   2023-12-11 [3] RSPM (R 4.3.0)
#>  codetools     0.2-19  2023-02-01 [3] RSPM (R 4.2.0)
#>  DBI           1.1.3   2022-06-18 [3] RSPM (R 4.2.0)
#>  digest        0.6.33  2023-07-07 [3] RSPM (R 4.2.0)
#>  dplyr         1.1.4   2023-11-17 [3] RSPM (R 4.3.0)
#>  e1071         1.7-14  2023-12-06 [3] RSPM (R 4.3.0)
#>  evaluate      0.23    2023-11-01 [3] RSPM (R 4.3.0)
#>  fansi         1.0.6   2023-12-08 [3] RSPM (R 4.3.0)
#>  fastmap       1.1.1   2023-02-24 [3] RSPM (R 4.2.0)
#>  fs            1.6.3   2023-07-20 [3] RSPM (R 4.2.0)
#>  generics      0.1.3   2022-07-05 [3] RSPM (R 4.2.0)
#>  glue          1.6.2   2022-02-24 [3] RSPM (R 4.2.0)
#>  htmltools     0.5.7   2023-11-03 [3] RSPM (R 4.3.0)
#>  KernSmooth    2.23-22 2023-07-10 [3] RSPM (R 4.2.0)
#>  knitr         1.45    2023-10-30 [3] RSPM (R 4.3.0)
#>  lattice       0.22-5  2023-10-24 [3] RSPM (R 4.3.0)
#>  lifecycle     1.0.4   2023-11-07 [3] RSPM (R 4.3.0)
#>  magrittr      2.0.3   2022-03-30 [3] RSPM (R 4.2.0)
#>  pillar        1.9.0   2023-03-22 [3] RSPM (R 4.2.0)
#>  pkgconfig     2.0.3   2019-09-22 [3] CRAN (R 4.0.1)
#>  proxy         0.4-27  2022-06-09 [3] RSPM (R 4.2.0)
#>  purrr         1.0.2   2023-08-10 [3] RSPM (R 4.2.0)
#>  R.cache       0.16.0  2022-07-21 [3] RSPM (R 4.2.0)
#>  R.methodsS3   1.8.2   2022-06-13 [3] RSPM (R 4.2.0)
#>  R.oo          1.25.0  2022-06-12 [3] RSPM (R 4.2.0)
#>  R.utils       2.12.3  2023-11-18 [3] RSPM (R 4.3.0)
#>  R6            2.5.1   2021-08-19 [3] RSPM (R 4.2.0)
#>  raster        3.6-26  2023-10-14 [3] RSPM (R 4.3.0)
#>  Rcpp          1.0.11  2023-07-06 [3] RSPM (R 4.2.0)
#>  reprex        2.0.2   2022-08-17 [3] RSPM (R 4.2.0)
#>  rlang         1.1.2   2023-11-04 [3] RSPM (R 4.3.0)
#>  rmarkdown     2.25    2023-09-18 [3] RSPM (R 4.3.0)
#>  rstudioapi    0.15.0  2023-07-07 [3] RSPM (R 4.2.0)
#>  sessioninfo   1.2.2   2021-12-06 [3] RSPM (R 4.2.0)
#>  sf            1.0-15  2023-12-18 [1] CRAN (R 4.3.2)
#>  sp            2.1-2   2023-11-26 [3] RSPM (R 4.3.0)
#>  styler        1.10.2  2023-08-29 [3] RSPM (R 4.2.0)
#>  terra         1.7-65  2023-12-15 [1] RSPM (R 4.3.2)
#>  tibble        3.2.1   2023-03-20 [3] RSPM (R 4.3.0)
#>  tidyselect    1.2.0   2022-10-10 [3] RSPM (R 4.2.0)
#>  units         0.8-5   2023-11-28 [3] RSPM (R 4.3.0)
#>  utf8          1.2.4   2023-10-22 [3] RSPM (R 4.3.0)
#>  vctrs         0.6.5   2023-12-01 [3] RSPM (R 4.3.0)
#>  withr         2.5.2   2023-10-30 [3] RSPM (R 4.3.0)
#>  xfun          0.41    2023-11-01 [3] RSPM (R 4.3.0)
#>  yaml          2.3.8   2023-12-11 [3] RSPM (R 4.3.0)
#> 
#>  [1] /home/floris/lib/R/library
#>  [2] /usr/local/lib/R/site-library
#>  [3] /usr/lib/R/site-library
#>  [4] /usr/lib/R/library
#> 
#> ──────────────────────────────────────────────────────────────────────────────
@florisvdh
Copy link
Author

florisvdh commented Dec 19, 2023

Adding some context. This was discovered in a GitHub Actions R-CMD-check workflow of {qgisprocess} after having added unit tests with terra::SpatVector() to the test file that tests the handling of {terra} objects. Only the Ubuntu jobs were affected. It was observed locally that the many warnings disappear after the test file for handling {raster} objects is removed. That file is run before the {terra} test file because of alphabetical order.

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