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

basemap_ggplot: map resolution #12

Closed Bevann closed 5 months ago

Bevann commented 1 year ago

Is there a method to increase the resolution of the downloaded basemaps? I have tried varying the map_res and dpi variables, however whenever I export maps to use in a document, the basemap is always just a bit too blurry. I am a big fan of the package as it makes it easy to use ggplot for maps that have consistent look as other figures in the document. Examples from the code below compared to the output of of leaflet map using the same basemap layer.

` library(tidyverse) library(basemaps) library(sf) library(tmap) library(tmaptools) library(bcdata) library(mapview)

get data to map

WMU <- bcdc_get_data("wildlife-management-units") %>% filter(REGION_RESPONSIBLE==3) %>% st_transform(3857)

get basemaps various options

WMU_EXT <- st_bbox(WMU)

WMU_BASEMAP_1_300 <- basemap_ggplot(WMU_EXT,map_service = "esri" , map_type = "world_topo_map",map_res = 1, dpi=300)

WMU_BASEMAP_1_1200 <- basemap_ggplot(WMU_EXT,map_service = "esri" , map_type = "world_topo_map",map_res = 1, dpi=1200)

WMU_BASEMAP_05_300 <- basemap_ggplot(WMU_EXT,map_service = "esri" , map_type = "world_topo_map",map_res = 0.5, dpi=300)

WMU_BASEMAP_05_1200 <- basemap_ggplot(WMU_EXT,map_service = "esri" , map_type = "world_topo_map",map_res = 0.5, dpi=1200)

WMU_BASEMAP_15_300 <- basemap_ggplot(WMU_EXT,map_service = "esri" , map_type = "world_topo_map",map_res = 1.5, dpi=300)

WMU_BASEMAP_15_1200 <- basemap_ggplot(WMU_EXT,map_service = "esri" , map_type = "world_topo_map",map_res = 1.5, dpi=1200)

make and save ggplot maps

WMU_1_300<- WMU_BASEMAP_1_300+ geom_sf(inherit.aes = F, data = WMU, fill=NA)+coord_sf(expand = F)

ggsave(filename = "./WMU_1_300.png",plot = WMU_1_300, width = 7 , height = 7, dpi = 1200)

WMU_1_1200<- WMU_BASEMAP_1_1200+ geom_sf(inherit.aes = F, data = WMU, fill=NA)+coord_sf(expand = F)

ggsave(filename = "./WMU_1_1200.png",plot = WMU_1_1200, width = 7 , height = 7, dpi = 1200)

WMU_05_300<- WMU_BASEMAP_05_300+ geom_sf(inherit.aes = F, data = WMU, fill=NA)+coord_sf(expand = F)

ggsave(filename = "./WMU_05_300.png",plot = WMU_05_300, width = 7 , height = 7, dpi = 1200)

WMU_05_1200<- WMU_BASEMAP_05_1200+ geom_sf(inherit.aes = F, data = WMU, fill=NA)+coord_sf(expand = F)

ggsave(filename = "./WMU_05_1200.png",plot = WMU_05_1200, width = 7 , height = 7, dpi = 1200)

WMU_15_300<- WMU_BASEMAP_15_300+ geom_sf(inherit.aes = F, data = WMU, fill=NA)+coord_sf(expand = F)

ggsave(filename = "./WMU_15_300.png",plot = WMU_15_300, width = 7 , height = 7, dpi = 1200)

WMU_15_1200<- WMU_BASEMAP_15_1200+ geom_sf(inherit.aes = F, data = WMU, fill=NA)+coord_sf(expand = F)

ggsave(filename = "./WMU_15_1200.png",plot = WMU_15_1200, width = 7 , height = 7, dpi = 1200)

compare to mapshot of leaflet tiles

tmap_mode("view") tmap_options(basemaps = "Esri.WorldTopoMap" )

TM_MAP <- tm_shape(WMU)+ tm_borders(group = "REGION_RESPONSIBLE", col = "black")

TM_LEAF<- tmap_leaflet(TM_MAP,)

mapview::mapshot(x = TM_LEAF, file="./Mapshot.png" )

`

16EAGLE commented 1 year ago

Thanks for making me aware of this. I pushed a new version to this repository. In case you have time: Could you install the newest version (remotes::install_github("16eagle/basemaps")) and check whether the results of basemap_ggplot are not blurry anymore?

Bevann commented 1 year ago

Thanks for looking into this, I re ran the example with the updated package. The output has a much larger file size, but the output looks the same. Attached image has examples of basemaps downloaded where map_res= 1 and dpi = 300 or 1200, and all exported at 1200 dpi png, file names beginning with NEW were made with the updated package. image

oar-data-trout commented 1 year ago

Hello, I am currently running into this issue as well. Any news or ideas for fixes would be appreciated. Even a workaround would be great. Thanks!

TheTS commented 1 year ago

Also running into the same issue with ggplot! Github version of the package has the same issue.

16EAGLE commented 5 months ago

This should be fixed with the latest release. maxpixels is now by default set to the maximum number of pixels instead of aggregating. See https://github.com/16EAGLE/basemaps/blob/master/NEWS.md#basemaps-007 for details.