MikkoVihtakari / ggOceanMaps

Plot oceanographic research data on maps using ggplot2
GNU General Public License v3.0
46 stars 7 forks source link

Antimeridian plotting doesn't work #28

Closed flaszlok closed 1 year ago

flaszlok commented 1 year ago

Hi, I tried the new antimeridian feature but somehow can't get it to work at all. First off, the example code

basemap(c(110, -110, 10, 55))

fails with the following message

Detecting antimeridian crossing on decimal degree map. Plotting only works with rotate = TRUE. Turning rotate on. Adjust limits if this is not desired. Error in CPL_transform(x, crs, aoi, pipeline, reverse, desired_accuracy, : OGRCreateCoordinateTransformation(): transformation not available In addition: Warning message: In CPL_transform(x, crs, aoi, pipeline, reverse, desired_accuracy, : GDAL Error 1: No PROJ.4 translation for source SRS, coordinate transformation initialization has failed.

I then tried:

projection <- "EPSG:32636"
lims <- c(110, -110, 10, 55)
world <- st_read(paste0(shapefilePath, "/Landmasses/ne_10m_land/ne_10m_land.shp"))
am_land <- clip_shapefile(world, lims)
am_land <- st_transform(am_land, CRSobj = CRS(projection))
basemap(list(land = am_land, glacier = NULL, bathy = NULL), bathymetry = F, glaciers = F)

This plots a map, but it shows the reverse of what I want, a map centered on the 0-meridian and missing the antimeridian part. I thought I had the coordinates of the limits switched but it happened regardless.

Right now I have somewhat poor understanding on how the package works after the update to v2 (and the documentation is not that helpful as of right now), so it might be that I'm just making a silly mistake.

Cheers,

flaszlok

MikkoVihtakari commented 1 year ago

On a vacation. Addressing these takes longer than usual. Apologies for that.

basemap(c(110, -110, 10, 55)) gives this on my machine:

image

Outdated packages or OS specific problem?

Could you post session info, please?

flaszlok commented 1 year ago

No worries! Great package btw, I can get most other stuff working just this one defies me. Yeah it might be that it is only a problem in my machine!

> sessionInfo()
R version 4.2.3 (2023-03-15)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.6 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.7.1
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.7.1

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_GB.UTF-8       
 [4] LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_GB.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_GB.UTF-8       LC_NAME=C                  LC_ADDRESS=C              
[10] LC_TELEPHONE=C             LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] ggOceanMaps_2.0.4 ggplot2_3.4.2     sf_1.0-14        

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.11        pillar_1.9.0       compiler_4.2.3     class_7.3-22       tools_4.2.3       
 [6] lifecycle_1.0.3    tibble_3.2.1       gtable_0.3.3       pkgconfig_2.0.3    rlang_1.1.1       
[11] DBI_1.1.3          cli_3.6.1          rstudioapi_0.15.0  parallel_4.2.3     e1071_1.7-13      
[16] withr_2.5.0        dplyr_1.1.2        s2_1.1.4           generics_0.1.3     vctrs_0.6.3       
[21] classInt_0.4-9     grid_4.2.3         tidyselect_1.2.0   glue_1.6.2         R6_2.5.1          
[26] fansi_1.0.4        farver_2.1.1       magrittr_2.0.3     scales_1.2.1       stars_0.6-2       
[31] units_0.8-2        abind_1.4-5        colorspace_2.1-0   utf8_1.2.3         KernSmooth_2.23-22
[36] proxy_0.4-27       wk_0.7.3           munsell_0.5.0      lwgeom_0.2-13     
> basemap(c(110, -110, 10, 55))
Detecting antimeridian crossing on decimal degree map. Plotting only works with rotate =
TRUE. Turning rotate on. Adjust limits if this is not desired.
Error: OGRCreateCoordinateTransformation(): transformation not available
In addition: Warning message:
In CPL_transform(x, crs, aoi, pipeline, reverse, desired_accuracy,  :
  GDAL Error 1: No PROJ.4 translation for source SRS, coordinate transformation initialization has failed.
MikkoVihtakari commented 1 year ago

On an Ubuntu machine, I get:

library(sf)
#> Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1; sf_use_s2() is TRUE
library(ggOceanMaps)
#> Loading required package: ggplot2
#> ggOceanMaps: Setting data download folder to a temporary folder
#> /tmp/RtmphCVPwl. This means that any downloaded map data need to be
#> downloaded again when you restart R. To avoid this problem, change the
#> default path to a permanent folder on your computer. Add following
#> lines to your .Rprofile file: {.ggOceanMapsenv <- new.env();
#> .ggOceanMapsenv$datapath <- 'YourCustomPath'}. You can use
#> usethis::edit_r_profile() to edit the file. '~/ggOceanMapsLargeData'
#> would make it in a writable folder on most operating systems.
basemap(c(110, -110, 10, 55))
#> Detecting antimeridian crossing on decimal degree map. Plotting only
#> works with rotate = TRUE. Turning rotate on. Adjust limits if this is
#> not desired.

sessionInfo()
#> R version 4.2.1 (2022-06-23)
#> Platform: x86_64-pc-linux-gnu (64-bit)
#> Running under: Ubuntu 20.04.5 LTS
#> 
#> Matrix products: default
#> BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.9.0
#> LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.9.0
#> 
#> locale:
#>  [1] LC_CTYPE=en_GB.UTF-8       LC_NUMERIC=C              
#>  [3] LC_TIME=en_GB.UTF-8        LC_COLLATE=en_GB.UTF-8    
#>  [5] LC_MONETARY=en_GB.UTF-8    LC_MESSAGES=en_GB.UTF-8   
#>  [7] LC_PAPER=en_GB.UTF-8       LC_NAME=C                 
#>  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
#> [11] LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C       
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#> [1] ggOceanMaps_2.0.4 ggplot2_3.4.2     sf_1.0-14        
#> 
#> loaded via a namespace (and not attached):
#>  [1] Rcpp_1.0.11        compiler_4.2.1     pillar_1.9.0       highr_0.8         
#>  [5] class_7.3-20       tools_4.2.1        digest_0.6.29      gtable_0.3.3      
#>  [9] evaluate_0.14      lifecycle_1.0.3    tibble_3.2.1       pkgconfig_2.0.3   
#> [13] rlang_1.1.1        reprex_2.0.2       DBI_1.1.3          cli_3.6.1         
#> [17] rstudioapi_0.14    parallel_4.2.1     yaml_2.2.1         xfun_0.35         
#> [21] fastmap_1.1.0      e1071_1.7-13       s2_1.1.4           withr_2.5.0       
#> [25] stringr_1.5.0      dplyr_1.0.10       knitr_1.30         generics_0.1.0    
#> [29] fs_1.5.2           vctrs_0.6.3        tidyselect_1.2.0   classInt_0.4-9    
#> [33] grid_4.2.1         glue_1.6.2         R6_2.5.1           fansi_1.0.4       
#> [37] rmarkdown_2.18     farver_2.1.1       magrittr_2.0.3     stars_0.6-2       
#> [41] scales_1.2.1       htmltools_0.5.2    units_0.8-2        abind_1.4-5       
#> [45] assertthat_0.2.1   colorspace_2.1-0   KernSmooth_2.23-17 utf8_1.2.3        
#> [49] stringi_1.7.4      proxy_0.4-27       wk_0.7.3           munsell_0.5.0     
#> [53] lwgeom_0.2-13

Created on 2023-07-18 with reprex v2.0.2

While on my Mac, I get:

library(sf)
#> Linking to GEOS 3.11.0, GDAL 3.5.3, PROJ 9.1.0; sf_use_s2() is TRUE
library(ggOceanMaps)
#> Loading required package: ggplot2
#> ggOceanMaps: Setting data download folder to a temporary folder
#> /var/folders/9v/b70pd53x04d3jjmlrbcgp4_w0000gv/T//Rtmpqu7Qpq. This
#> means that any downloaded map data need to be downloaded again when you
#> restart R. To avoid this problem, change the default path to a
#> permanent folder on your computer. Add following lines to your
#> .Rprofile file: {.ggOceanMapsenv <- new.env(); .ggOceanMapsenv$datapath
#> <- 'YourCustomPath'}. You can use usethis::edit_r_profile() to edit the
#> file. '~/ggOceanMapsLargeData' would make it in a writable folder on
#> most operating systems.
basemap(c(110, -110, 10, 55))
#> Detecting antimeridian crossing on decimal degree map. Plotting only
#> works with rotate = TRUE. Turning rotate on. Adjust limits if this is
#> not desired.

sessionInfo()
#> R version 4.3.1 (2023-06-16)
#> Platform: x86_64-apple-darwin20 (64-bit)
#> Running under: macOS Ventura 13.4.1
#> 
#> Matrix products: default
#> BLAS:   /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/lib/libRblas.0.dylib 
#> LAPACK: /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/lib/libRlapack.dylib;  LAPACK version 3.11.0
#> 
#> locale:
#> [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
#> 
#> time zone: Europe/Helsinki
#> tzcode source: internal
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#> [1] ggOceanMaps_2.0.4 ggplot2_3.4.2     sf_1.0-13        
#> 
#> loaded via a namespace (and not attached):
#>  [1] lwgeom_0.2-13      gtable_0.3.3       dplyr_1.1.2        compiler_4.3.1    
#>  [5] reprex_2.0.2       tidyselect_1.2.0   Rcpp_1.0.10        parallel_4.3.1    
#>  [9] scales_1.2.1       yaml_2.3.7         fastmap_1.1.1      R6_2.5.1          
#> [13] generics_0.1.3     classInt_0.4-9     s2_1.1.4           knitr_1.43        
#> [17] tibble_3.2.1       stars_0.6-1        units_0.8-2        munsell_0.5.0     
#> [21] DBI_1.1.3          pillar_1.9.0       rlang_1.1.1        utf8_1.2.3        
#> [25] xfun_0.39          fs_1.6.2           cli_3.6.1          withr_2.5.0       
#> [29] magrittr_2.0.3     wk_0.7.3           class_7.3-22       digest_0.6.32     
#> [33] grid_4.3.1         rstudioapi_0.14    lifecycle_1.0.3    vctrs_0.6.3       
#> [37] KernSmooth_2.23-21 proxy_0.4-27       evaluate_0.21      glue_1.6.2        
#> [41] farver_2.1.1       abind_1.4-5        fansi_1.0.4        e1071_1.7-13      
#> [45] colorspace_2.1-0   rmarkdown_2.23     tools_4.3.1        pkgconfig_2.0.3   
#> [49] htmltools_0.5.5

Created on 2023-07-18 with reprex v2.0.2

I assume this issue is due to old PROJ? What do you get when you load sf?

flaszlok commented 1 year ago

yeah my PROJ seems outdated

> library(sf) Linking to GEOS 3.6.2, GDAL 2.2.3, PROJ 4.9.3; sf_use_s2() is TRU

MikkoVihtakari commented 1 year ago

This should notify the user about old PROJ: https://github.com/MikkoVihtakari/ggOceanMaps/commit/ba0164a1e5b3c92aeb8f986695650f671501f85b

Thanks for reporting the issue. Reopen if the fix does not do what it should :)