Skip to content

Instantly share code, notes, and snippets.

@rCarto
Last active December 12, 2023 09:42
Show Gist options
  • Select an option

  • Save rCarto/c4bcbed525b5428bf01563548ba2d20f to your computer and use it in GitHub Desktop.

Select an option

Save rCarto/c4bcbed525b5428bf01563548ba2d20f to your computer and use it in GitHub Desktop.

Revisions

  1. rCarto revised this gist Dec 12, 2023. 1 changed file with 17 additions and 7 deletions.
    24 changes: 17 additions & 7 deletions maptiles.md
    Original file line number Diff line number Diff line change
    @@ -1,15 +1,25 @@
    ``` r
    # Your Stadia API key:
    apikey = "xxxxxxxxxxxxxxxxxxxxxxx"

    # Define a bounding box
    library(sf)
    #> Linking to GEOS 3.11.1, GDAL 3.6.2, PROJ 9.1.1; sf_use_s2() is TRUE
    bb <- st_bbox(obj = c(xmin = 24.73592, xmax = 24.75185,
    ymin = 59.4340, ymax = 59.4393),
    crs = "EPSG:4326")

    # Download and compose Stadia/stamen tiles
    library(maptiles)
    nc <- st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE)
    nc_osm <- get_tiles(nc, provider = "Stadia.Stamen.TonerLite",
    project = FALSE, apikey = apikey)
    plot_tiles(nc_osm)
    stam <- get_tiles(x = bb, provider = "Stadia.Stamen.TonerLite",
    apikey = apikey, project = FALSE)

    # Display the basemap
    library(mapsf)
    mf_raster(stam)
    mf_credits(get_credit('Stadia.Stamen.TonerLite'), bg = "white")
    mf_title("Stamen Toner Lite Basemap", tab = FALSE)
    ```

    ![](https://i.imgur.com/t43UrRf.png)<!-- -->
    ![](https://i.imgur.com/eSfMCXk.png)<!-- -->

    <sup>Created on 2023-12-11 with [reprex v2.0.2](https://reprex.tidyverse.org)</sup>
    <sup>Created on 2023-12-12 with [reprex v2.0.2](https://reprex.tidyverse.org)</sup>
  2. rCarto created this gist Dec 11, 2023.
    15 changes: 15 additions & 0 deletions maptiles.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    ``` r
    # Your Stadia API key:
    apikey = "xxxxxxxxxxxxxxxxxxxxxxx"
    library(sf)
    #> Linking to GEOS 3.11.1, GDAL 3.6.2, PROJ 9.1.1; sf_use_s2() is TRUE
    library(maptiles)
    nc <- st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE)
    nc_osm <- get_tiles(nc, provider = "Stadia.Stamen.TonerLite",
    project = FALSE, apikey = apikey)
    plot_tiles(nc_osm)
    ```

    ![](https://i.imgur.com/t43UrRf.png)<!-- -->

    <sup>Created on 2023-12-11 with [reprex v2.0.2](https://reprex.tidyverse.org)</sup>