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

Static provider basemaps #140

Open
zackarno opened this issue Jun 5, 2024 · 0 comments
Open

Static provider basemaps #140

zackarno opened this issue Jun 5, 2024 · 0 comments
Assignees
Labels
enhancement New feature or request question Further information is requested visuals

Comments

@zackarno
Copy link
Collaborator

zackarno commented Jun 5, 2024

Was playing around with this package {basemaps} and i think it might be useful if we ever wanted to create static basemaps behind the shapefiles for context. It seems to be able to find the appropriate zoom level based on the extent of the sf feature.

Probably too much work/testing required for initial release, but could be something to keep in mind/explore more

library(sf)

library(tidyverse)
library(basemaps)


sf_adm0 <- read_rds("bgd_adm0.rds")

here you can see the map types offered in the package. Only ESRI and Carto are offered out of the box without API tokens. However I suspect some of the ones with tokens would be even better/more appropriate.

get_maptypes()
#> $osm
#> [1] "streets"     "streets_de"  "topographic"
#> 
#> $osm_stamen
#> [1] "toner"      "toner_bg"   "terrain"    "terrain_bg" "watercolor"
#> 
#> $osm_stadia
#> [1] "alidade_smooth"      "alidade_smooth_dark" "outdoors"           
#> [4] "osm_bright"         
#> 
#> $osm_thunderforest
#>  [1] "cycle"          "transport"      "landscape"      "outdoors"      
#>  [5] "transport_dark" "spinal"         "pioneer"        "mobile_atlas"  
#>  [9] "neighbourhood"  "atlas"         
#> 
#> $carto
#>  [1] "light"                "light_no_labels"      "light_only_labels"   
#>  [4] "dark"                 "dark_no_labels"       "dark_only_labels"    
#>  [7] "voyager"              "voyager_no_labels"    "voyager_only_labels" 
#> [10] "voyager_labels_under"
#> 
#> $mapbox
#> [1] "streets"   "outdoors"  "light"     "dark"      "satellite" "hybrid"   
#> [7] "terrain"  
#> 
#> $esri
#>  [1] "natgeo_world_map"                     
#>  [2] "usa_topo_maps"                        
#>  [3] "world_imagery"                        
#>  [4] "world_physical_map"                   
#>  [5] "world_shaded_relief"                  
#>  [6] "world_street_map"                     
#>  [7] "world_terrain_base"                   
#>  [8] "world_topo_map"                       
#>  [9] "world_dark_gray_base"                 
#> [10] "world_dark_gray_reference"            
#> [11] "world_light_gray_base"                
#> [12] "world_light_gray_reference"           
#> [13] "world_hillshade_dark"                 
#> [14] "world_hillshade"                      
#> [15] "world_ocean_base"                     
#> [16] "world_ocean_reference"                
#> [17] "antarctic_imagery"                    
#> [18] "arctic_imagery"                       
#> [19] "arctic_ocean_base"                    
#> [20] "arctic_ocean_reference"               
#> [21] "world_boundaries_and_places_alternate"
#> [22] "world_boundaries_and_places"          
#> [23] "world_reference_overlay"              
#> [24] "world_transportation"                 
#> [25] "delorme_world_base_map"               
#> [26] "world_navigation_charts"

Here is a little preview of a few of the "nice" ones for our application. I could imagine something without many boundaries, but a few labels/topographic features for context being ideal as that would allow us to superimpose the adm0 of interest without any conflicting lines

sf_webmercator <- st_transform(sf_adm0 ,"EPSG:3857")


ggplot() +
  basemap_gglayer(
    sf_webmercator,
    map_service = "carto",
    map_type = "voyager"
    ) +
  scale_fill_identity() +
  coord_sf()+
  geom_sf(data= sf_webmercator, fill="transparent",color="black")+
  geom_sf(data= sf_webmercator, fill="transparent",color="black")+
  labs(
    x = "",
    y = "",

    subtitle = "Carto - Voyager",
  ) +
  theme(
    rect = element_blank(),
    axis.ticks = element_blank(),
    axis.text.x = element_blank(),
    axis.text.y = element_blank(),
    panel.grid.major = element_blank(),
    panel.grid.minor = element_blank(),
    axis.line.x = element_blank(),
    plot.caption = element_text(hjust = 1)

  )
#> Loading basemap 'voyager' from map service 'carto'...
#> Using geom_raster() with maxpixels = 255425.
#> Coordinate system already present. Adding new coordinate system, which will
#> replace the existing one.

ggplot() +
  basemap_gglayer(
    sf_webmercator,
    map_service = "carto",
    map_type = "light_no_labels"
    ) +
  scale_fill_identity() +
  coord_sf()+
  geom_sf(data= sf_webmercator, fill="transparent",color="black")+
  labs(
    x = "",
    y = "",
    title = "Carto - Light no labels"
  ) +
  theme(
    rect = element_blank(),
    axis.ticks = element_blank(),
    axis.text.x = element_blank(),
    axis.text.y = element_blank(),
    panel.grid.major = element_blank(),
    panel.grid.minor = element_blank(),
    axis.line.x = element_blank(),
    plot.caption = element_text(hjust = 1)
  )
#> Loading basemap 'light_no_labels' from map service 'carto'...
#> Using geom_raster() with maxpixels = 255425.
#> Coordinate system already present. Adding new coordinate system, which will
#> replace the existing one.

ggplot() +
  basemap_gglayer(
    sf_webmercator,
    map_service = "esri",
    map_type = "world_street_map"
    ) +
  scale_fill_identity() +
  coord_sf()+
  geom_sf(data= sf_webmercator, fill="transparent",color="black")+
  labs(
    x = "",
    y = "",

    subtitle = "ESRI - World Street Map",
  ) +
  theme(
    rect = element_blank(),
    axis.ticks = element_blank(),
    axis.text.x = element_blank(),
    axis.text.y = element_blank(),
    panel.grid.major = element_blank(),
    panel.grid.minor = element_blank(),
    axis.line.x = element_blank(),
    plot.caption = element_text(hjust = 1)

  )
#> Loading basemap 'world_street_map' from map service 'esri'...
#> Using geom_raster() with maxpixels = 255425.
#> Coordinate system already present. Adding new coordinate system, which will
#> replace the existing one.

ggplot() +
  basemap_gglayer(
    sf_webmercator,
    map_service = "esri",
    map_type = "world_light_gray_base"
    ) +
  scale_fill_identity() +
  coord_sf()+
  geom_sf(data= sf_webmercator, fill="transparent",color="black")+
  labs(
    x = "",
    y = "",

    subtitle = "ESRI - World light grey base",
  ) +
  theme(
    rect = element_blank(),
    axis.ticks = element_blank(),
    axis.text.x = element_blank(),
    axis.text.y = element_blank(),
    panel.grid.major = element_blank(),
    panel.grid.minor = element_blank(),
    axis.line.x = element_blank(),
    plot.caption = element_text(hjust = 1)
  )
#> Loading basemap 'world_light_gray_base' from map service 'esri'...
#> Using geom_raster() with maxpixels = 255425.
#> Coordinate system already present. Adding new coordinate system, which will
#> replace the existing one.

ggplot() +
  basemap_gglayer(
    sf_webmercator,
    map_service = "esri",
    map_type = "world_light_gray_reference"
    ) +
  scale_fill_identity() +
  coord_sf()+
  geom_sf(data= sf_webmercator, fill="transparent",color="black")+
  labs(
    x = "",
    y = "",

    subtitle = "ESRI - World light grey base",
  ) +
  theme(
    rect = element_blank(),
    axis.ticks = element_blank(),
    axis.text.x = element_blank(),
    axis.text.y = element_blank(),
    panel.grid.major = element_blank(),
    panel.grid.minor = element_blank(),
    axis.line.x = element_blank(),
    plot.caption = element_text(hjust = 1)
  )
#> Loading basemap 'world_light_gray_reference' from map service 'esri'...
#> Using geom_tile() with maxpixels = 255425.
#> Coordinate system already present. Adding new coordinate system, which will
#> replace the existing one.

ggplot() +
  basemap_gglayer(
    sf_webmercator,
    map_service = "esri",
    map_type = "natgeo_world_map"
    ) +
  scale_fill_identity() +
  coord_sf()+
  geom_sf(data= sf_webmercator, fill="transparent",color="black")+
  labs(
    x = "",
    y = "",

    subtitle = "ESRI - NatGeo",
  ) +
  theme(
    rect = element_blank(),
    axis.ticks = element_blank(),
    axis.text.x = element_blank(),
    axis.text.y = element_blank(),
    panel.grid.major = element_blank(),
    panel.grid.minor = element_blank(),
    axis.line.x = element_blank(),
    plot.caption = element_text(hjust = 1)

  )
#> Loading basemap 'natgeo_world_map' from map service 'esri'...
#> Using geom_raster() with maxpixels = 255425.
#> Coordinate system already present. Adding new coordinate system, which will
#> replace the existing one.

Created on 2024-06-05 with reprex v2.0.2

@zackarno zackarno added enhancement New feature or request question Further information is requested labels Jun 5, 2024
@hannahker hannahker added this to the P3 milestone Jul 1, 2024
@caldwellst caldwellst removed this from the P3 milestone Oct 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested visuals
Projects
None yet
Development

No branches or pull requests

3 participants