Closed brry closed 1 year ago
Hello,
I think it has to do with the smooth
parameter in terra::plotRGB()
which doesn't seem to be taken into account. I'll look at it more in depth tomorrow.
OpenStreetMap
is using raster
to plot RGB images. maptiles
(and rosm
I think) are using terra
.
The smooth
argument in terra
seems to be broken when compared to the interpolate argument in raster
.
library(terra)
#> terra 1.7.46
library(raster)
#> Loading required package: sp
#> The legacy packages maptools, rgdal, and rgeos, underpinning the sp package,
#> which was just loaded, were retired in October 2023.
#> Please refer to R-spatial evolution reports for details, especially
#> https://r-spatial.org/r/2023/05/15/evolution4.html.
#> It may be desirable to make the sf package available;
#> package maintainers should consider adding sf to Suggests:.
r.spatraster <- terra::rast(system.file("ex/logo.tif", package="terra"))
r.rasterbrick <- raster::brick(r.spatraster)
par(mfrow = c(2,2))
terra::plotRGB(r.spatraster, smooth = FALSE)
terra::plotRGB(r.spatraster, smooth = TRUE)
raster::plotRGB(r.rasterbrick, interpolate = FALSE)
#> Warning in .couldBeLonLat(x, warnings = warnings): CRS is NA. Assuming it is
#> longitude/latitude
raster::plotRGB(r.rasterbrick, interpolate = TRUE)
#> Warning in .couldBeLonLat(x, warnings = warnings): CRS is NA. Assuming it is
#> longitude/latitude
Created on 2023-10-11 with reprex v2.0.2
The problem is solved in terra
.
# remotes::install_github('rspatial/terra')
d <- read.table(sep=",", header=TRUE, text=
"lat, long
52.514464, 13.350137
52.370000, 13.120000
55.685143, 12.580008
50.106452, 14.419989
48.847003, 2.3372130
51.505364,-0.1647520")
# maptiles ----
png("maps%d.png", width=2, height=2, units="in", res=200)
bounds <- sf::st_bbox(sf::st_as_sf(d, coords=c("long", "lat"), crs=4326))
map <- maptiles::get_tiles(bounds, crop=TRUE, zoom=5, project=FALSE)
maptiles::plot_tiles(map, adjust=FALSE)
title(main="maptiles", line=-1)
dev.off()
#> png
#> 2
Created on 2023-10-13 with reprex v2.0.2
Thank you so much!
The images are fuzzy, compared to OpenStreetMap (to be taken off CRAN next week). I guess it uses a different tile fetching mechanism, because at a particular zoom level, the images have better resolution.
This may be related to #5, but I don't think so, as the downloaded tiles in the cache folder have the same fuzzyness.
Is it worth looking into how Ian's code does this? It does look a lot nicer in larger images.
rosm
has the same resolution, by the way.Here is the comparison:
And here's the code generating it: