16EAGLE / basemaps

A lightweight package for accessing basemaps from open sources in R 🗺️
https://jakob.schwalb-willmann.de/basemaps
GNU General Public License v3.0
57 stars 15 forks source link

Raster pixels are placed at uneven horizontal intervals and will be shifted #24

Closed xiaochi-liu closed 5 months ago

xiaochi-liu commented 10 months ago

Thanks for this excellent package. I'd like to download a basemap for Victoria, Australia:

image

However, I encountered the following warning and couldn't receive the right outcome:

library(tidyverse)
#> Warning: package 'ggplot2' was built under R version 4.3.1
#> Warning: package 'lubridate' was built under R version 4.3.1
library(basemaps)

sf_test = read_rds("sf_test.rds")
sf_test
#> Simple feature collection with 1 feature and 0 fields
#> Geometry type: POLYGON
#> Dimension:     XY
#> Bounding box:  xmin: 140.9619 ymin: -39.15918 xmax: 149.9762 ymax: -33.98064
#> Geodetic CRS:  WGS 84
#>                         geometry
#> 1 POLYGON ((140.9619 -39.1591...

ggplot() + 
  basemap_gglayer(ext = sf_test, map_service = "carto", map_type = "light") +
  scale_fill_identity() + 
  coord_sf()
#> Warning: Transforming 'ext' to Web Mercator (EPSG: 3857), since 'ext' has a
#> different CRS. The CRS of the returned basemap will be Web Mercator, which is
#> the default CRS used by the supported tile services.
#> Loading basemap 'light' from map service 'carto'...
#> Warning: Raster pixels are placed at uneven horizontal intervals and will be shifted
#> ℹ Consider using `geom_tile()` instead.

May I ask how I should handle this situation? The test data is available here, and my session info is as follows:

sessionInfo()
#> R version 4.3.0 (2023-04-21)
#> Platform: aarch64-apple-darwin20 (64-bit)
#> Running under: macOS 14.0
#> 
#> Matrix products: default
#> BLAS:   /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRblas.0.dylib 
#> LAPACK: /Library/Frameworks/R.framework/Versions/4.3-arm64/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: Australia/Melbourne
#> tzcode source: internal
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> loaded via a namespace (and not attached):
#>  [1] digest_0.6.33     fastmap_1.1.1     xfun_0.40         glue_1.6.2       
#>  [5] knitr_1.43        htmltools_0.5.6.1 rmarkdown_2.24    lifecycle_1.0.3  
#>  [9] cli_3.6.1         reprex_2.0.2      withr_2.5.1       compiler_4.3.0   
#> [13] rstudioapi_0.15.0 tools_4.3.0       evaluate_0.21     yaml_2.3.7       
#> [17] rlang_1.1.1       fs_1.6.3

Your kind guidance is much appreciated!

16EAGLE commented 6 months ago

Thanks for reporting this. Could you retry with the latest verison 0.0.6 of basemaps from CRAN? This seems to have orginated from an upstream bug, should be fixed now.

orb16 commented 5 months ago

I have the dev version from github and also have this issue (and the resolution makes it not useable, too, when other layers like world_light_gray_base do work):


bbox <- structure(list(x = structure(list(structure(list(structure(c(19616242.6270123, 
19703033.9940241, 19703033.9940241, 19616242.6270123, 19616242.6270123, 
-4871287.16788705, -4871287.16788705, -4802367.16946593, -4802367.16946593, 
-4871287.16788705), dim = c(5L, 2L))), class = c("XY", "POLYGON", 
"sfg"))), class = c("sfc_POLYGON", "sfc"), precision = 0, bbox = structure(c(xmin = 19616242.6270123, 
ymin = -4871287.16788705, xmax = 19703033.9940241, ymax = -4802367.16946593
), class = "bbox"), crs = structure(list(input = "EPSG:3857", 
    wkt = "PROJCRS[\"WGS 84 / Pseudo-Mercator\",\n    BASEGEOGCRS[\"WGS 84\",\n        ENSEMBLE[\"World Geodetic System 1984 ensemble\",\n            MEMBER[\"World Geodetic System 1984 (Transit)\"],\n            MEMBER[\"World Geodetic System 1984 (G730)\"],\n            MEMBER[\"World Geodetic System 1984 (G873)\"],\n            MEMBER[\"World Geodetic System 1984 (G1150)\"],\n            MEMBER[\"World Geodetic System 1984 (G1674)\"],\n            MEMBER[\"World Geodetic System 1984 (G1762)\"],\n            MEMBER[\"World Geodetic System 1984 (G2139)\"],\n            ELLIPSOID[\"WGS 84\",6378137,298.257223563,\n                LENGTHUNIT[\"metre\",1]],\n            ENSEMBLEACCURACY[2.0]],\n        PRIMEM[\"Greenwich\",0,\n            ANGLEUNIT[\"degree\",0.0174532925199433]],\n        ID[\"EPSG\",4326]],\n    CONVERSION[\"Popular Visualisation Pseudo-Mercator\",\n        METHOD[\"Popular Visualisation Pseudo Mercator\",\n            ID[\"EPSG\",1024]],\n        PARAMETER[\"Latitude of natural origin\",0,\n            ANGLEUNIT[\"degree\",0.0174532925199433],\n            ID[\"EPSG\",8801]],\n        PARAMETER[\"Longitude of natural origin\",0,\n            ANGLEUNIT[\"degree\",0.0174532925199433],\n            ID[\"EPSG\",8802]],\n        PARAMETER[\"False easting\",0,\n            LENGTHUNIT[\"metre\",1],\n            ID[\"EPSG\",8806]],\n        PARAMETER[\"False northing\",0,\n            LENGTHUNIT[\"metre\",1],\n            ID[\"EPSG\",8807]]],\n    CS[Cartesian,2],\n        AXIS[\"easting (X)\",east,\n            ORDER[1],\n            LENGTHUNIT[\"metre\",1]],\n        AXIS[\"northing (Y)\",north,\n            ORDER[2],\n            LENGTHUNIT[\"metre\",1]],\n    USAGE[\n        SCOPE[\"Web mapping and visualisation.\"],\n        AREA[\"World between 85.06°S and 85.06°N.\"],\n        BBOX[-85.06,-180,85.06,180]],\n    ID[\"EPSG\",3857]]"), class = "crs"), n_empty = 0L)), row.names = 1L, class = c("sf", 
"data.frame"), sf_column = "x", agr = structure(integer(0), class = "factor", levels = c("constant", 
"aggregate", "identity"), names = character(0)))

set_defaults(map_service = "esri", map_type = "world_light_gray_reference")

ggplot() + 
  basemap_gglayer(bbox) +
  scale_fill_identity() +
  coord_sf()

thank you!

16EAGLE commented 5 months ago

Thanks for reporting. I included a patch with version 0.0.7. This should fix

The visual tiling issues shown in @xiaochi-liu's initial post were resolved with version 0.0.6, thus I was unable to reproduce them again with your regex.

Please reinstall the package using

remotes::install_github("16eagle/basemaps", dependencies = T)

before retrying your example. Please let me know if this resolves the issue.

16EAGLE commented 5 months ago

Please reopen if this issue persists with the latest CRAN release of basemaps-