Title: | R Interface to 'Mapbox' Web Services |
---|---|
Description: | Includes support for 'Mapbox' Navigation APIs, including directions, isochrones, and route optimization; the Search API for forward and reverse geocoding; the Maps API for interacting with 'Mapbox' vector tilesets and visualizing 'Mapbox' maps in R; and 'Mapbox Tiling Service' and 'tippecanoe' for generating map tiles. See <https://docs.mapbox.com/api/> for more information about the 'Mapbox' APIs. |
Authors: | Kyle Walker [aut, cre], Eli Pousson [ctb], Anthony North [ctb, cph], Miles McBain [ctb] |
Maintainer: | Kyle Walker <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.6.2 |
Built: | 2024-10-26 06:13:49 UTC |
Source: | https://github.com/walkerke/mapboxapi |
See the Mapbox Static Tiles API documentation for more information.
addMapboxTiles( map, style_id, username, style_url = NULL, scaling_factor = c("1x", "0.5x", "2x"), access_token = NULL, layerId = NULL, group = NULL, options = leaflet::tileOptions(), data = leaflet::getMapData(map), attribution = TRUE )
addMapboxTiles( map, style_id, username, style_url = NULL, scaling_factor = c("1x", "0.5x", "2x"), access_token = NULL, layerId = NULL, group = NULL, options = leaflet::tileOptions(), data = leaflet::getMapData(map), attribution = TRUE )
map |
A map widget object created by |
style_id |
The style ID of a Mapbox style |
username |
A Mapbox username |
style_url |
A Mapbox style URL |
scaling_factor |
The scaling factor to use when rendering the tiles. A
scaling factor of |
access_token |
Your Mapbox access token; which can be set with
|
layerId |
the layer ID |
group |
The name of the group the Mapbox tile layer should belong to (for use in Shiny and to modify layers control in a Leaflet workflow) |
options |
A list of extra options (optional) |
data |
The data object used to derive argument values; can be provided
to the initial call to |
attribution |
If |
A pointer to the Mapbox Static Tiles API which will be translated appropriately by the leaflet R package.
## Not run: library(leaflet) library(mapboxapi) leaflet() %>% addMapboxTiles( style_id = "light-v9", username = "mapbox" ) %>% setView( lng = -74.0051, lat = 40.7251, zoom = 13 ) ## End(Not run)
## Not run: library(leaflet) library(mapboxapi) leaflet() %>% addMapboxTiles( style_id = "light-v9", username = "mapbox" ) %>% setView( lng = -74.0051, lat = 40.7251, zoom = 13 ) ## End(Not run)
Check the status of a Mapbox upload
check_upload_status(upload_id, username, access_token = NULL)
check_upload_status(upload_id, username, access_token = NULL)
upload_id |
The upload ID |
username |
Your account's username |
access_token |
Your Mapbox access token |
Specify feature options for an MTS recipe layer
feature_options( id = NULL, bbox = NULL, attributes = list(zoom_element = NULL, set = NULL, allowed_output = NULL), filter = NULL, simplification = NULL )
feature_options( id = NULL, bbox = NULL, attributes = list(zoom_element = NULL, set = NULL, allowed_output = NULL), filter = NULL, simplification = NULL )
id |
A column representing the feature ID. See https://docs.mapbox.com/mapbox-tiling-service/reference/#id-expression. |
bbox |
A bounding box within which rendered features will be clipped. See https://docs.mapbox.com/mapbox-tiling-service/reference/#bounding-box. |
attributes |
A named list of attribute transformations. |
filter |
An expression that determines how features in the tileset should be filtered. See https://docs.mapbox.com/mapbox-tiling-service/reference/#feature-filters for information on how to specify the filter. |
simplification |
Rules for feature simplification. See https://docs.mapbox.com/mapbox-tiling-service/reference/#feature-simplification for more information on how to specify this. |
A list of feature options, likely to be used in recipe_layer()
.
https://docs.mapbox.com/mapbox-tiling-service/reference/
## Not run: library(tidycensus) library(mapboxapi) options(tigris_use_cache = TRUE) # Get the national data on median age us_median_age_tract <- get_acs( geography = "tract", variables = "B01002_001", state = c(state.abb, "DC"), year = 2020, geometry = TRUE ) # Get it for counties as well us_median_age_county <- get_acs( geography = "county", variables = "B01002_001", year = 2020, geometry = TRUE ) # Create a source from the datasets mts_create_source(data = us_median_age_tract, tileset_id = "us_median_age_tract", username = "your_mapbox_username") mts_create_source(data = us_median_age_county, tileset_id = "us_median_age_county", username = "your_mapbox_username") # Build out the recipe. First, create a recipe layer with # appropriate options. We'll want a larger tile size and to restrict the minzoom # to 4; a maxzoom of 12 will be fine as we can overzoom beyond that # # Your source ID will be returned by `mts_create_source()`, so use that value tract_layer <- recipe_layer( source = "mapbox://tileset-source/your_mapbox_username/us_median_age_tract", minzoom = 4, maxzoom = 12, tiles = tile_options(layer_size = 2500) ) county_layer <- recipe_layer( source = "mapbox://tileset-source/your_mapbox_username/us_median_age_county", minzoom = 2, maxzoom = 5 ) recipe <- mts_make_recipe(tracts = tract_layer, counties = county_layer) # Validate the recipe mts_validate_recipe(recipe) # Create a tileset from the recipe mts_create_tileset(tileset_name = "median_age_acs", username = "your_mapbox_username", recipe = recipe) # Publish the tileset mts_publish_tileset(tileset_name = "median_age_acs", username = "your_mapbox_username") # If necessary, update the recipe mts_update_recipe(tileset_name = "median_age_acs", username = "your_mapbox_username", recipe = new_recipe) # Publish the tileset again after you've updated the recipe mts_publish_tileset(tileset_name = "median_age_acs", username = "your_mapbox_username") ## End(Not run)
## Not run: library(tidycensus) library(mapboxapi) options(tigris_use_cache = TRUE) # Get the national data on median age us_median_age_tract <- get_acs( geography = "tract", variables = "B01002_001", state = c(state.abb, "DC"), year = 2020, geometry = TRUE ) # Get it for counties as well us_median_age_county <- get_acs( geography = "county", variables = "B01002_001", year = 2020, geometry = TRUE ) # Create a source from the datasets mts_create_source(data = us_median_age_tract, tileset_id = "us_median_age_tract", username = "your_mapbox_username") mts_create_source(data = us_median_age_county, tileset_id = "us_median_age_county", username = "your_mapbox_username") # Build out the recipe. First, create a recipe layer with # appropriate options. We'll want a larger tile size and to restrict the minzoom # to 4; a maxzoom of 12 will be fine as we can overzoom beyond that # # Your source ID will be returned by `mts_create_source()`, so use that value tract_layer <- recipe_layer( source = "mapbox://tileset-source/your_mapbox_username/us_median_age_tract", minzoom = 4, maxzoom = 12, tiles = tile_options(layer_size = 2500) ) county_layer <- recipe_layer( source = "mapbox://tileset-source/your_mapbox_username/us_median_age_county", minzoom = 2, maxzoom = 5 ) recipe <- mts_make_recipe(tracts = tract_layer, counties = county_layer) # Validate the recipe mts_validate_recipe(recipe) # Create a tileset from the recipe mts_create_tileset(tileset_name = "median_age_acs", username = "your_mapbox_username", recipe = recipe) # Publish the tileset mts_publish_tileset(tileset_name = "median_age_acs", username = "your_mapbox_username") # If necessary, update the recipe mts_update_recipe(tileset_name = "median_age_acs", username = "your_mapbox_username", recipe = new_recipe) # Publish the tileset again after you've updated the recipe mts_publish_tileset(tileset_name = "median_age_acs", username = "your_mapbox_username") ## End(Not run)
mapboxGeocoderInput()
geocoded location to an sf objectConvert the result of a mapboxGeocoderInput()
geocoded location to an sf object
geocoder_as_sf(input)
geocoder_as_sf(input)
input |
The name of the Shiny input using |
An sf object that can be used downstream in your Shiny applications.
mapboxGeocoderInput()
geocoded location to XY coordinatesConvert the results of a mapboxGeocoderInput()
geocoded location to XY coordinates
geocoder_as_xy(input)
geocoder_as_xy(input)
input |
The name of the Shiny input using |
A length-2 vector representing the geocoded longitude/latitude coordinates of the location.
This function queries the Mapbox Static Tiles API and composites the tiles
as a raster suitable for use as a basemap in
tmap or
ggplot2 (with the
ggspatial::layer_spatial()
function. It returns a raster
layer that corresponds either to an input bounding box or a buffered area
around an input shape.
get_static_tiles( location, zoom, style_id, username, style_url = NULL, scaling_factor = c("1x", "2x"), buffer_dist = 5000, units = "m", crop = TRUE, access_token = NULL )
get_static_tiles( location, zoom, style_id, username, style_url = NULL, scaling_factor = c("1x", "2x"), buffer_dist = 5000, units = "m", crop = TRUE, access_token = NULL )
location |
An input location for which you would like to request tiles.
Can be a length-4 vector representing a bounding box, or an |
zoom |
The zoom level for which you'd like to return tiles. |
style_id |
A Mapbox style ID; retrieve yours from your Mapbox account. |
username |
A Mapbox username. |
style_url |
A Mapbox style URL. |
scaling_factor |
The scaling factor to use; one of |
buffer_dist |
The distance to buffer around an input |
units |
Units of |
crop |
Whether or not to crop the result to the specified bounding box or buffer area.
Defaults to |
access_token |
A Mapbox access token. Supply yours here or set globally with the |
A raster layer of tiles from the requested Mapbox style representing the area around the input location. The raster layer is projected in the Web Mercator coordinate reference system.
## Not run: library(mapboxapi) library(tigris) library(tmap) library(ggspatial) library(ggplot2) ny_tracts <- tracts("NY", "New York", cb = TRUE) ny_tiles <- get_static_tiles( location = ny_tracts, zoom = 10, style_id = "light-v9", username = "mapbox" ) # tmap usage: tm_shape(ny_tiles) + tm_rgb() + tm_shape(ny_tracts) + tm_polygons(alpha = 0.5, col = "navy") + tm_credits("Basemap (c) Mapbox, (c) OpenStreetMap", position = c("RIGHT", "BOTTOM") ) # ggplot2 usage: ggplot() + layer_spatial(ny_tiles) + geom_sf(data = ny_tracts, fill = "navy", alpha = 0.5) + theme_void() + labs(caption = "Basemap (c) Mapbox, (c) OpenStreetMap") ## End(Not run)
## Not run: library(mapboxapi) library(tigris) library(tmap) library(ggspatial) library(ggplot2) ny_tracts <- tracts("NY", "New York", cb = TRUE) ny_tiles <- get_static_tiles( location = ny_tracts, zoom = 10, style_id = "light-v9", username = "mapbox" ) # tmap usage: tm_shape(ny_tiles) + tm_rgb() + tm_shape(ny_tracts) + tm_polygons(alpha = 0.5, col = "navy") + tm_credits("Basemap (c) Mapbox, (c) OpenStreetMap", position = c("RIGHT", "BOTTOM") ) # ggplot2 usage: ggplot() + layer_spatial(ny_tiles) + geom_sf(data = ny_tracts, fill = "navy", alpha = 0.5) + theme_void() + labs(caption = "Basemap (c) Mapbox, (c) OpenStreetMap") ## End(Not run)
See the Mapbox Styles API documentation for more information.
get_style(style_id, username, style_url = NULL, access_token = NULL) list_styles(username, access_token = NULL)
get_style(style_id, username, style_url = NULL, access_token = NULL) list_styles(username, access_token = NULL)
style_id |
A style ID |
username |
A Mapbox username |
style_url |
A Mapbox style URL |
access_token |
A Mapbox public or secret access token; set with
|
get_style returns a list of information about your selected style. list_styles returns a data frame of information about styles from a Mapbox account
Retrieve vector tiles from a given Mapbox tileset
get_vector_tiles(tileset_id, location, zoom, access_token = NULL)
get_vector_tiles(tileset_id, location, zoom, access_token = NULL)
tileset_id |
The name of the tileset ID; names can be retrieved from your Mapbox account |
location |
The location for which you'd like to retrieve tiles. If the
input is an |
zoom |
The zoom level of the request; larger zoom levels will return more detail but will take longer to process. |
access_token |
A Mapbox access token; which can be set with
|
A list of sf
objects representing the different layer types found
in the requested vector tiles.
## Not run: library(mapboxapi) library(ggplot2) vector_extract <- get_vector_tiles( tileset_id = "mapbox.mapbox-streets-v8", location = c(-73.99405, 40.72033), zoom = 15 ) ggplot(vector_extract$building$polygons) + geom_sf() + theme_void() ## End(Not run)
## Not run: library(mapboxapi) library(ggplot2) vector_extract <- get_vector_tiles( tileset_id = "mapbox.mapbox-streets-v8", location = c(-73.99405, 40.72033), zoom = 15 ) ggplot(vector_extract$building$polygons) + geom_sf() + theme_void() ## End(Not run)
These functions wrap static_mapbox()
and ggspatial::layer_spatial()
or
tmap::tm_rgb()
to support the use of images from the Mapbox Static Maps API as
ggplot2 or
tmap basemaps.
layer_static_mapbox( location = NULL, buffer_dist = 1000, units = "m", style_id, username, style_url = NULL, overlay_sf = NULL, overlay_style = NULL, overlay_markers = NULL, width = NULL, height = NULL, scale = 0.5, scaling_factor = c("1x", "2x"), attribution = TRUE, logo = TRUE, before_layer = NULL, access_token = NULL, ... ) tm_static_mapbox( location = NULL, buffer_dist = 1000, units = "m", style_id, username, style_url = NULL, overlay_sf = NULL, overlay_style = NULL, overlay_markers = NULL, width = NULL, height = NULL, scale = 0.5, scaling_factor = c("1x", "2x"), attribution = TRUE, logo = TRUE, before_layer = NULL, access_token = NULL, ... )
layer_static_mapbox( location = NULL, buffer_dist = 1000, units = "m", style_id, username, style_url = NULL, overlay_sf = NULL, overlay_style = NULL, overlay_markers = NULL, width = NULL, height = NULL, scale = 0.5, scaling_factor = c("1x", "2x"), attribution = TRUE, logo = TRUE, before_layer = NULL, access_token = NULL, ... ) tm_static_mapbox( location = NULL, buffer_dist = 1000, units = "m", style_id, username, style_url = NULL, overlay_sf = NULL, overlay_style = NULL, overlay_markers = NULL, width = NULL, height = NULL, scale = 0.5, scaling_factor = c("1x", "2x"), attribution = TRUE, logo = TRUE, before_layer = NULL, access_token = NULL, ... )
location |
An input location for which you would like to request tiles.
Can be a length-4 vector representing a bounding box, or an |
buffer_dist |
The distance to buffer around an input |
units |
Units of |
style_id |
A style ID (required if style_url is |
username |
A Mapbox username (required if |
style_url |
A Mapbox style url; defaults to |
overlay_sf |
The overlay |
overlay_style |
A named list of vectors specifying how to style the sf
overlay. Possible names are "stroke", "stroke-width" (or "stroke_width"),
"stroke-opacity" (or "stroke_opacity"), "fill", and "fill-opacity" (or
"fill_opacity"). The fill and stroke color values can be specified as
six-digit hex codes or color names, and the opacity and width values should
be supplied as floating-point numbers. If overlay_style is |
overlay_markers |
The prepared overlay markers (optional). See the function prep_overlay_markers for more information on how to specify a marker overlay. |
width , height
|
The map width and height; defaults to |
scale |
ratio to scale the output image; |
scaling_factor |
The scaling factor of the tiles; either |
attribution |
Controls whether there is attribution on the image.
Defaults to |
logo |
Controls whether there is a Mapbox logo on the image. Defaults to
|
before_layer |
A character string that specifies where in the hierarchy
of layer elements the overlay should be inserted. The overlay will be
placed just above the specified layer in the given Mapbox styles. List
layer ids for a map style with |
access_token |
A Mapbox access token; which can be set with mb_access_token. |
... |
additional parameters passed to ggspatial::layer_spatial or tmap::tm_rgb |
This function uses a different approach than get_static_tiles()
. Instead,
layer_static_mapbox()
is based largely on layer_mapbox()
in the snapbox package
(available under a MIT license. There
are a few key differences between layer_static_mapbox()
and
layer_mapbox()
. The "scale" parameter is equivalent to the
"scale_ratio" parameter for snapbox. Setting scale_factor = "2x"
is
equivalent to setting retina = TRUE.
Both functions return basemaps that
are no larger than a single tile (a maximum of 1280 by 1280 pixels).
For tm_static_mapbox()
, tmap::tm_shape is called with projection = 3857
and
tmap::tm_rgb is called with max.value = 1
.
Eli Pousson, [email protected]
Anthony North, [email protected]
Miles McBain, [email protected]
Use Mapbox web services APIs for spatial data science and visualization projects in R. Usage of the package is governed by the Mapbox Terms of Service.
Kyle Walker
Useful links:
Report bugs at https://github.com/walkerke/mapboxapi/issues
Use Mapbox's Geocoder widget in a Shiny application
mapboxGeocoderInput( inputId, access_token = NULL, placeholder = "Search", search_within = NULL, proximity = NULL, limit = 5, min_length = 2, language = NULL )
mapboxGeocoderInput( inputId, access_token = NULL, placeholder = "Search", search_within = NULL, proximity = NULL, limit = 5, min_length = 2, language = NULL )
inputId |
The Shiny input ID |
access_token |
The Mapbox access token (required); can be set with
|
placeholder |
The placeholder to be used in the search box; defaults to 'Search' |
search_within |
An |
proximity |
A length-2 vector of longitude and latitude coordinates used to prioritize results near to that location. Defaults to NULL. |
limit |
The maximum number of results to show. Defaults to 5. |
min_length |
The minimum number of characters the user must enter before results are shown. Defaults to 2. |
language |
The language to use for the geocoder. Per the Mapbox documentation, "Options are IETF language tags comprised of a mandatory ISO 639-1 language code and optionally one or more IETF subtags for country or script." |
A Mapbox geocoder widget as a Shiny input
See the Mapbox API documentation for more information on access tokens and token scopes.
mb_access_token(token, overwrite = FALSE, install = FALSE) get_mb_access_token( token = NULL, default = c("MAPBOX_PUBLIC_TOKEN", "MAPBOX_SECRET_TOKEN"), secret_required = FALSE ) list_tokens( username, default = NULL, limit = NULL, sortby = "created", usage = NULL, access_token = NULL )
mb_access_token(token, overwrite = FALSE, install = FALSE) get_mb_access_token( token = NULL, default = c("MAPBOX_PUBLIC_TOKEN", "MAPBOX_SECRET_TOKEN"), secret_required = FALSE ) list_tokens( username, default = NULL, limit = NULL, sortby = "created", usage = NULL, access_token = NULL )
token |
A Mapbox access token; can be public (starting with 'pk') or secret (starting with 'sk') scope, which the function will interpret for you. |
overwrite |
Whether or not to overwrite an existing Mapbox access token.
Defaults to |
install |
if |
default |
If |
secret_required |
If |
username |
The Mapbox username for which you'd like to list access tokens. |
limit |
The maximum number of tokens to return. Defaults to |
sortby |
How to sort the returned tokens; one of |
usage |
If |
access_token |
Your Mapbox access token. If left |
A tibble of information about tokens in your Mapbox account.
## Not run: my_token <- "..." # The token generated from your Mapbox account mb_access_token(my_token, install = TRUE) Sys.getenv("MAPBOX_PUBLIC_TOKEN") get_mb_access_token() ## End(Not run) ## Not run: token_list <- list_tokens( username = "kwalkertcu", # You would use your own username here limit = 10, sortby = "modified" #' ) ## End(Not run)
## Not run: my_token <- "..." # The token generated from your Mapbox account mb_access_token(my_token, install = TRUE) Sys.getenv("MAPBOX_PUBLIC_TOKEN") get_mb_access_token() ## End(Not run) ## Not run: token_list <- list_tokens( username = "kwalkertcu", # You would use your own username here limit = 10, sortby = "modified" #' ) ## End(Not run)
Geocode addresses or locations in bulk using the Mapbox Batch Geocoding API
mb_batch_geocode( data, search_column = NULL, address_line1 = NULL, address_number = NULL, street = NULL, block = NULL, place = NULL, region = NULL, postcode = NULL, locality = NULL, neighborhood = NULL, country = NULL, permanent = FALSE, limit = 1, search_within = NULL, language = NULL, types = NULL, proximity = NULL, worldview = NULL, allow_large_job = FALSE, access_token = NULL, sf = TRUE )
mb_batch_geocode( data, search_column = NULL, address_line1 = NULL, address_number = NULL, street = NULL, block = NULL, place = NULL, region = NULL, postcode = NULL, locality = NULL, neighborhood = NULL, country = NULL, permanent = FALSE, limit = 1, search_within = NULL, language = NULL, types = NULL, proximity = NULL, worldview = NULL, allow_large_job = FALSE, access_token = NULL, sf = TRUE )
data |
An input data frame |
search_column |
A column that contains a description of the place to geocode, or a full address. |
address_line1 |
The name of a column in |
address_number |
The name of a column in |
street |
The name of a column in |
block |
The name of a column in |
place |
The name of a column in |
region |
The name of a column in |
postcode |
The name of a column in |
locality |
The name of a column in |
neighborhood |
The name of a column in |
country |
A character string or vector of ISO 3166 alpha-2 country codes within which you would like to limit your search. |
permanent |
Either FALSE (the default) when results are not intended to be stored, or TRUE if the results are planned to be stored. |
limit |
How many results to return per address. This is not currently accessible for users and can only be 1. |
search_within |
An |
language |
The user's language, which can help with interpretation of queries. Available languages are found at https://docs.mapbox.com/api/search/#language-coverage. |
types |
A vector of feature types to limit to which the search should be
limited. Available options include |
proximity |
proximity Either a vector of coordinates or an IP address string to bias the results to favor locations near to the input location. |
worldview |
Returns features intended for different regional or cultural groups. The US ( |
allow_large_job |
A boolean indicating that the user is OK with potential charges incurred to their account due to a large geocoding job (over 1000 addresses). The Mapbox Free Tier includes 100,000 free geocodes per month. Defaults to |
access_token |
The Mapbox access token (required); can be set with
|
sf |
A boolean that determines whether the output will be an sf POINT object ( |
The input dataset as an sf POINT object representing the geocoded locations, or the input dataset with longitude, latitude, and matched address columns included.
See the Mapbox Directions API documentation for more information.
mb_directions( input_data = NULL, origin = NULL, destination = NULL, profile = "driving", output = "sf", depart_at = NULL, alternatives = NULL, annotations = NULL, bearings = NULL, continue_straight = NULL, exclude = NULL, geometries = "geojson", overview = "simplified", radiuses = NULL, approaches = NULL, steps = NULL, banner_instructions = NULL, language = NULL, roundabout_exits = NULL, voice_instructions = NULL, voice_units = NULL, waypoint_names = NULL, waypoint_targets = NULL, waypoints = NULL, walking_speed = NULL, walkway_bias = NULL, alley_bias = NULL, access_token = NULL )
mb_directions( input_data = NULL, origin = NULL, destination = NULL, profile = "driving", output = "sf", depart_at = NULL, alternatives = NULL, annotations = NULL, bearings = NULL, continue_straight = NULL, exclude = NULL, geometries = "geojson", overview = "simplified", radiuses = NULL, approaches = NULL, steps = NULL, banner_instructions = NULL, language = NULL, roundabout_exits = NULL, voice_instructions = NULL, voice_units = NULL, waypoint_names = NULL, waypoint_targets = NULL, waypoints = NULL, walking_speed = NULL, walkway_bias = NULL, alley_bias = NULL, access_token = NULL )
input_data |
An input dataset of class |
origin |
An address or coordinate pair that represents the origin of
your requested route. Cannot be used with |
destination |
An address or coordinate pair that represents the destination of your requested route. |
profile |
One of "driving" (the default), "driving-traffic", "walking", or "cycling". |
output |
One of "sf" (the default), which returns an sf LINESTRING representing the route geometry, or "full", which returns the full request from the Directions API as a list. |
depart_at |
(optional) For the "driving" or "driving-traffic" profiles,
the departure date and time to reflect historical traffic patterns. If
"driving-traffic" is used, live traffic will be mixed in with historical
traffic for dates/times near to the current time. Should be specified as an
ISO 8601 date/time, e.g. |
alternatives |
Whether or not to return alternative routes with your request. If TRUE, a list of up to 3 possible routes will be returned. |
annotations |
A comma-separated string of additional route metadata, which may include duration, distance, speed, and congestion. Must be used with overview = "full". |
bearings |
A semicolon-delimited character string of bearings |
continue_straight |
continue_straight |
exclude |
Road types to exclude from your route; possible choices are
|
geometries |
The route geometry format. If |
overview |
If left blank, defaults to |
radiuses |
A character string with semicolon-separated radii that
specify the distance (in meters) to snap each input coordinate to the road
network. Defaults to |
approaches |
A character string with semicolon-separated specifications
for how to approach waypoints. Options include |
steps |
If |
banner_instructions |
Whether or not to return banner objects; only
available when |
language |
The language of the returned instructions (defaults to
English). Available language codes are found at
https://docs.mapbox.com/api/navigation/#instructions-languages. Only
available when |
roundabout_exits |
If TRUE, adds instructions for roundabout entrance
and exit. Only available when |
voice_instructions , voice_units
|
Only available when |
waypoint_names , waypoint_targets , waypoints
|
Only available when |
walking_speed |
The walking speed in meters/second; available when
|
walkway_bias |
Can take values between -1 and 1, where negative numbers
avoid walkways and positive numbers prefer walkways. Available when
|
alley_bias |
Can take values between -1 and 1, where negative numbers
avoid alleys and positive numbers prefer alleys. Available when |
access_token |
A Mapbox access token; which can be set with
|
An sf
object (or list of sf
objects), or full R list representing
the API response.
## Not run: library(mapboxapi) library(leaflet) my_route <- mb_directions( origin = "10 Avenue de Wagram, 75008 Paris France", destination = "59 Rue de Tocqueville, 75017 Paris France", profile = "cycling", steps = TRUE, language = "fr" ) leaflet(my_route) %>% addMapboxTiles( style_id = "light-v9", username = "mapbox" ) %>% addPolylines() ## End(Not run)
## Not run: library(mapboxapi) library(leaflet) my_route <- mb_directions( origin = "10 Avenue de Wagram, 75008 Paris France", destination = "59 Rue de Tocqueville, 75017 Paris France", profile = "cycling", steps = TRUE, language = "fr" ) leaflet(my_route) %>% addMapboxTiles( style_id = "light-v9", username = "mapbox" ) %>% addPolylines() ## End(Not run)
See the Mapbox Geocoding API documentation for more information.
mb_geocode( search_text = NULL, structured_input = NULL, permanent = FALSE, autocomplete = TRUE, limit = 1, types = NULL, search_within = NULL, language = NULL, country = NULL, proximity = NULL, worldview = NULL, output = "coordinates", access_token = NULL ) mb_reverse_geocode( coordinates, permanent = FALSE, limit = 1, language = NULL, types = NULL, country = NULL, worldview = NULL, output = "text", access_token = NULL )
mb_geocode( search_text = NULL, structured_input = NULL, permanent = FALSE, autocomplete = TRUE, limit = 1, types = NULL, search_within = NULL, language = NULL, country = NULL, proximity = NULL, worldview = NULL, output = "coordinates", access_token = NULL ) mb_reverse_geocode( coordinates, permanent = FALSE, limit = 1, language = NULL, types = NULL, country = NULL, worldview = NULL, output = "text", access_token = NULL )
search_text |
The text to search, formatted as a character string. Can be an address, a location, or a description of a point of interest. |
structured_input |
A named list of structured address inputs, to be used in place of |
permanent |
Either FALSE (the default) when results are not intended to be stored, or TRUE if the results are planned to be stored. |
autocomplete |
Whether or not to return autocomplete results. Defaults to FALSE. |
limit |
How many results to return; defaults to 1 (maximum 10). |
types |
A vector of feature types to limit to which the search should be
limited. Available options include |
search_within |
An |
language |
The user's language, which can help with interpretation of queries. Available languages are found at https://docs.mapbox.com/api/search/#language-coverage. |
country |
A character string or vector of ISO 3166 alpha-2 country codes within which you would like to limit your search. |
proximity |
Either a vector of coordinates or an IP address string to bias the results to favor locations near to the input location. |
worldview |
Returns features intended for different regional or cultural groups. The US ( |
output |
one of |
access_token |
The Mapbox access token (required); can be set with
|
coordinates |
The coordinates of a location in format |
A character vector, list, or sf
object representing the query
results.
## Not run: whitehouse <- mb_geocode("1600 Pennsylvania Ave, Washington DC") ## End(Not run) ## Not run: mb_reverse_geocode(c(77.5958768, 12.9667046), limit = 5, types = "address") ## End(Not run)
## Not run: whitehouse <- mb_geocode("1600 Pennsylvania Ave, Washington DC") ## End(Not run) ## Not run: mb_reverse_geocode(c(77.5958768, 12.9667046), limit = 5, types = "address") ## End(Not run)
This function returns isochrones from the Mapbox Navigation Service
Isochrone API. Isochrones are
shapes that represent the reachable area around one or more locations within
a given travel time. Isochrones can be computed for driving, walking, or
cycling routing profiles, and can optionally be set to return distances
rather than times. mb_isochrone()
returns isochrones as simple
features objects in the WGS 1984 geographic coordinate system.
mb_isochrone( location, profile = "driving", time = c(5, 10, 15), distance = NULL, depart_at = NULL, access_token = NULL, denoise = 1, generalize = NULL, geometry = "polygon", output = "sf", rate_limit = 300, keep_color_cols = FALSE, id_column = NULL )
mb_isochrone( location, profile = "driving", time = c(5, 10, 15), distance = NULL, depart_at = NULL, access_token = NULL, denoise = 1, generalize = NULL, geometry = "polygon", output = "sf", rate_limit = 300, keep_color_cols = FALSE, id_column = NULL )
location |
A vector of form |
profile |
One of "driving", "walking", "cycling", or "driving-traffic". "driving" is the default. |
time |
A vector of isochrone contours, specified in minutes. Defaults to |
distance |
A vector of distance contours specified in meters. If supplied, will supercede
any call to the |
depart_at |
(optional) For the "driving" or "driving-traffic" profiles, the departure date and time to reflect historical traffic patterns. If "driving-traffic" is used, live traffic will be mixed in with historical traffic for dates/times near to the current time. Should be specified as an ISO 8601 date/time, e.g. |
access_token |
A valid Mapbox access token. |
denoise |
A floating-point value between 0 and 1 used to remove smaller contours. 1 is the default and returns only the largest contour for an input time. |
generalize |
A value expressed in meters of the tolerance for the Douglas-Peucker generalization algorithm used to simplify the isochrone shapes. If |
geometry |
one of |
output |
one of |
rate_limit |
The rate limit for the API, expressed in maximum number of calls per minute. For most users this will be 300 though this parameter can be modified based on your Mapbox plan. Used when |
keep_color_cols |
Whether or not to retain the color columns that the Mapbox API generates by default (applies when the output is an |
id_column |
If the input dataset is an |
An sf
object representing the isochrone(s) around the location(s).
## Not run: library(mapboxapi) library(mapdeck) isochrones <- mb_isochrone("The Kremlin, Moscow Russia", time = c(4, 8, 12), profile = "walking" ) mapdeck(style = mapdeck_style("light")) %>% add_polygon( data = isochrones, fill_colour = "time", fill_opacity = 0.5, legend = TRUE ) ## End(Not run)
## Not run: library(mapboxapi) library(mapdeck) isochrones <- mb_isochrone("The Kremlin, Moscow Russia", time = c(4, 8, 12), profile = "walking" ) mapdeck(style = mapdeck_style("light")) %>% add_polygon( data = isochrones, fill_colour = "time", fill_opacity = 0.5, legend = TRUE ) ## End(Not run)
Retrieve a matrix of travel times from the Mapbox Directions API
mb_matrix( origins, destinations = NULL, profile = "driving", fallback_speed = NULL, output = c("duration", "distance"), duration_output = c("minutes", "seconds"), access_token = NULL, depart_at = NULL, allow_large_matrix = FALSE )
mb_matrix( origins, destinations = NULL, profile = "driving", fallback_speed = NULL, output = c("duration", "distance"), duration_output = c("minutes", "seconds"), access_token = NULL, depart_at = NULL, allow_large_matrix = FALSE )
origins |
The input coordinates of your request. Acceptable inputs include a list of
coordinate pair vectors in |
destinations |
The destination coordinates of your request. If |
profile |
One of "driving" (the default), "driving-traffic", "walking", or "cycling". |
fallback_speed |
A value expressed in kilometers per hour used to estimate travel time when a route cannot be found between locations. The returned travel time will be based on the straight-line estimate of travel between the locations at the specified fallback speed. |
output |
one of |
duration_output |
one of |
access_token |
A Mapbox access token (required) |
depart_at |
(optional) For the "driving" or "driving-traffic" profiles, the departure date and time to reflect historical traffic patterns. If "driving-traffic" is used, live traffic will be mixed in with historical traffic for dates/times near to the current time. Should be specified as an ISO 8601 date/time, e.g. |
allow_large_matrix |
|
An R matrix of source-destination travel times.
## Not run: library(mapboxapi) library(tigris) library(mapdeck) philly_tracts <- tracts("PA", "Philadelphia", cb = TRUE, class = "sf") downtown_philly <- mb_geocode("Philadelphia City Hall, Philadelphia PA") time_to_downtown <- mb_matrix(philly_tracts, downtown_philly) philly_tracts$time <- time_to_downtown mapdeck(style = mapdeck_style("light")) %>% add_polygon( data = philly_tracts, fill_colour = "time", fill_opacity = 0.6, legend = TRUE ) ## End(Not run)
## Not run: library(mapboxapi) library(tigris) library(mapdeck) philly_tracts <- tracts("PA", "Philadelphia", cb = TRUE, class = "sf") downtown_philly <- mb_geocode("Philadelphia City Hall, Philadelphia PA") time_to_downtown <- mb_matrix(philly_tracts, downtown_philly) philly_tracts$time <- time_to_downtown mapdeck(style = mapdeck_style("light")) %>% add_polygon( data = philly_tracts, fill_colour = "time", fill_opacity = 0.6, legend = TRUE ) ## End(Not run)
Return an optimized route for a series of input coordinates
mb_optimized_route( input_data, profile = c("driving", "walking", "cycling", "driving-traffic"), output = "sf", source = c("any", "first"), destination = c("any", "last"), roundtrip = TRUE, annotations = NULL, approaches = NULL, bearings = NULL, distributions = NULL, language = NULL, overview = "simplified", radiuses = NULL, steps = NULL, access_token = NULL )
mb_optimized_route( input_data, profile = c("driving", "walking", "cycling", "driving-traffic"), output = "sf", source = c("any", "first"), destination = c("any", "last"), roundtrip = TRUE, annotations = NULL, approaches = NULL, bearings = NULL, distributions = NULL, language = NULL, overview = "simplified", radiuses = NULL, steps = NULL, access_token = NULL )
input_data |
An input dataset of class |
profile |
One of "driving" (the default), "driving-traffic", "walking", or "cycling". |
output |
One of "sf" (the default), which returns an |
source |
One of |
destination |
One of |
roundtrip |
If |
annotations |
A comma-separated string of additional route metadata,
which may include duration, distance, speed, and congestion. Must be used
with |
approaches |
A character string with semicolon-separated specifications
for how to approach waypoints. Options include |
bearings |
A semicolon-delimited character string of bearings. |
distributions |
A semicolon-delimited character string of number pairs that specifies pick-up and drop-off locations. The first number indicates the index of the pick-up location, and the second number represents the index of the drop-off location. |
language |
The language of the returned instructions (defaults to
English). Available language codes are found at
https://docs.mapbox.com/api/navigation/#instructions-languages. Only
available when |
overview |
If left blank, defaults to |
radiuses |
A character string with semicolon-separated radii that
specify the distance (in meters) to snap each input coordinate to the road
network. Defaults to |
steps |
If |
access_token |
Your Mapbox access token; which can be set with
|
Either a list of two sf
objects - one representing the waypoints, and one representing the route - or an R list representing the full optimization API response.
## Not run: library(mapboxapi) library(sf) to_visit <- data.frame( X = c(-0.209307, -0.185875, -0.216877, -0.233511, -0.234541), Y = c(5.556019, 5.58031, 5.582528, 5.566771, 5.550209) ) %>% st_as_sf(coords = c("X", "Y"), crs = 4326) optimized_route <- mb_optimized_route(to_visit, profile = "driving-traffic" ) ## End(Not run)
## Not run: library(mapboxapi) library(sf) to_visit <- data.frame( X = c(-0.209307, -0.185875, -0.216877, -0.233511, -0.234541), Y = c(5.556019, 5.58031, 5.582528, 5.566771, 5.550209) ) %>% st_as_sf(coords = c("X", "Y"), crs = 4326) optimized_route <- mb_optimized_route(to_visit, profile = "driving-traffic" ) ## End(Not run)
The mts_create_source()
function can be used to create a tileset source or append to an existing tileset source. This function publishes a simple features object you've created in R to your Mapbox account, where it is stored as line-delimited GeoJSON. A tileset source is required to create a vector tileset, and the same source can be used across multiple tilesets.
mts_create_source(data, tileset_id, username, access_token = NULL)
mts_create_source(data, tileset_id, username, access_token = NULL)
data |
An input simple features object |
tileset_id |
The tileset ID. If the tileset ID already exists in your Mapbox account, this function will overwrite the existing source with a new source. |
username |
Your Mapbox username |
access_token |
Your Mapbox access token with secret scope. Install with |
A list of the MTS API's responses, including the name of the tileset source in your Mapbox account. You'll use this name to build a MTS recipe.
https://docs.mapbox.com/api/maps/mapbox-tiling-service/#create-a-tileset-source
## Not run: library(tidycensus) library(mapboxapi) options(tigris_use_cache = TRUE) # Get the national data on median age us_median_age_tract <- get_acs( geography = "tract", variables = "B01002_001", state = c(state.abb, "DC"), year = 2020, geometry = TRUE ) # Get it for counties as well us_median_age_county <- get_acs( geography = "county", variables = "B01002_001", year = 2020, geometry = TRUE ) # Create a source from the datasets mts_create_source(data = us_median_age_tract, tileset_id = "us_median_age_tract", username = "your_mapbox_username") mts_create_source(data = us_median_age_county, tileset_id = "us_median_age_county", username = "your_mapbox_username") # Build out the recipe. First, create a recipe layer with # appropriate options. We'll want a larger tile size and to restrict the minzoom # to 4; a maxzoom of 12 will be fine as we can overzoom beyond that # # Your source ID will be returned by `mts_create_source()`, so use that value tract_layer <- recipe_layer( source = "mapbox://tileset-source/your_mapbox_username/us_median_age_tract", minzoom = 4, maxzoom = 12, tiles = tile_options(layer_size = 2500) ) county_layer <- recipe_layer( source = "mapbox://tileset-source/your_mapbox_username/us_median_age_county", minzoom = 2, maxzoom = 5 ) recipe <- mts_make_recipe(tracts = tract_layer, counties = county_layer) # Validate the recipe mts_validate_recipe(recipe) # Create a tileset from the recipe mts_create_tileset(tileset_name = "median_age_acs", username = "your_mapbox_username", recipe = recipe) # Publish the tileset mts_publish_tileset(tileset_name = "median_age_acs", username = "your_mapbox_username") # If necessary, update the recipe mts_update_recipe(tileset_name = "median_age_acs", username = "your_mapbox_username", recipe = new_recipe) # Publish the tileset again after you've updated the recipe mts_publish_tileset(tileset_name = "median_age_acs", username = "your_mapbox_username") ## End(Not run)
## Not run: library(tidycensus) library(mapboxapi) options(tigris_use_cache = TRUE) # Get the national data on median age us_median_age_tract <- get_acs( geography = "tract", variables = "B01002_001", state = c(state.abb, "DC"), year = 2020, geometry = TRUE ) # Get it for counties as well us_median_age_county <- get_acs( geography = "county", variables = "B01002_001", year = 2020, geometry = TRUE ) # Create a source from the datasets mts_create_source(data = us_median_age_tract, tileset_id = "us_median_age_tract", username = "your_mapbox_username") mts_create_source(data = us_median_age_county, tileset_id = "us_median_age_county", username = "your_mapbox_username") # Build out the recipe. First, create a recipe layer with # appropriate options. We'll want a larger tile size and to restrict the minzoom # to 4; a maxzoom of 12 will be fine as we can overzoom beyond that # # Your source ID will be returned by `mts_create_source()`, so use that value tract_layer <- recipe_layer( source = "mapbox://tileset-source/your_mapbox_username/us_median_age_tract", minzoom = 4, maxzoom = 12, tiles = tile_options(layer_size = 2500) ) county_layer <- recipe_layer( source = "mapbox://tileset-source/your_mapbox_username/us_median_age_county", minzoom = 2, maxzoom = 5 ) recipe <- mts_make_recipe(tracts = tract_layer, counties = county_layer) # Validate the recipe mts_validate_recipe(recipe) # Create a tileset from the recipe mts_create_tileset(tileset_name = "median_age_acs", username = "your_mapbox_username", recipe = recipe) # Publish the tileset mts_publish_tileset(tileset_name = "median_age_acs", username = "your_mapbox_username") # If necessary, update the recipe mts_update_recipe(tileset_name = "median_age_acs", username = "your_mapbox_username", recipe = new_recipe) # Publish the tileset again after you've updated the recipe mts_publish_tileset(tileset_name = "median_age_acs", username = "your_mapbox_username") ## End(Not run)
After you've uploaded your spatial data to your Mapbox account with mts_create_source
and prepared a valid recipe with mts_make_recipe()
, you can use your source and recipe to create a vector tileset. This tileset will be hosted at your Mapbox account. Once created successfully, you will need to publish the tileset using mts_publish_tileset
to use it in Mapbox Studio, Mapbox GL JS, or an R package that can read Mapbox tilesets.
mts_create_tileset( tileset_name, username, recipe, request_name = tileset_name, access_token = NULL )
mts_create_tileset( tileset_name, username, recipe, request_name = tileset_name, access_token = NULL )
tileset_name |
The name of the MTS tileset you intend to create |
username |
Your Mapbox username |
recipe |
An MTS recipe, created with |
request_name |
The name of the request; defaults to the tileset name |
access_token |
Your Mapbox access token |
The response from the API, formatted as an R list.
https://docs.mapbox.com/api/maps/mapbox-tiling-service/#create-a-tileset
## Not run: library(tidycensus) library(mapboxapi) options(tigris_use_cache = TRUE) # Get the national data on median age us_median_age_tract <- get_acs( geography = "tract", variables = "B01002_001", state = c(state.abb, "DC"), year = 2020, geometry = TRUE ) # Get it for counties as well us_median_age_county <- get_acs( geography = "county", variables = "B01002_001", year = 2020, geometry = TRUE ) # Create a source from the datasets mts_create_source(data = us_median_age_tract, tileset_id = "us_median_age_tract", username = "your_mapbox_username") mts_create_source(data = us_median_age_county, tileset_id = "us_median_age_county", username = "your_mapbox_username") # Build out the recipe. First, create a recipe layer with # appropriate options. We'll want a larger tile size and to restrict the minzoom # to 4; a maxzoom of 12 will be fine as we can overzoom beyond that # # Your source ID will be returned by `mts_create_source()`, so use that value tract_layer <- recipe_layer( source = "mapbox://tileset-source/your_mapbox_username/us_median_age_tract", minzoom = 4, maxzoom = 12, tiles = tile_options(layer_size = 2500) ) county_layer <- recipe_layer( source = "mapbox://tileset-source/your_mapbox_username/us_median_age_county", minzoom = 2, maxzoom = 5 ) recipe <- mts_make_recipe(tracts = tract_layer, counties = county_layer) # Validate the recipe mts_validate_recipe(recipe) # Create a tileset from the recipe mts_create_tileset(tileset_name = "median_age_acs", username = "your_mapbox_username", recipe = recipe) # Publish the tileset mts_publish_tileset(tileset_name = "median_age_acs", username = "your_mapbox_username") # If necessary, update the recipe mts_update_recipe(tileset_name = "median_age_acs", username = "your_mapbox_username", recipe = new_recipe) # Publish the tileset again after you've updated the recipe mts_publish_tileset(tileset_name = "median_age_acs", username = "your_mapbox_username") ## End(Not run)
## Not run: library(tidycensus) library(mapboxapi) options(tigris_use_cache = TRUE) # Get the national data on median age us_median_age_tract <- get_acs( geography = "tract", variables = "B01002_001", state = c(state.abb, "DC"), year = 2020, geometry = TRUE ) # Get it for counties as well us_median_age_county <- get_acs( geography = "county", variables = "B01002_001", year = 2020, geometry = TRUE ) # Create a source from the datasets mts_create_source(data = us_median_age_tract, tileset_id = "us_median_age_tract", username = "your_mapbox_username") mts_create_source(data = us_median_age_county, tileset_id = "us_median_age_county", username = "your_mapbox_username") # Build out the recipe. First, create a recipe layer with # appropriate options. We'll want a larger tile size and to restrict the minzoom # to 4; a maxzoom of 12 will be fine as we can overzoom beyond that # # Your source ID will be returned by `mts_create_source()`, so use that value tract_layer <- recipe_layer( source = "mapbox://tileset-source/your_mapbox_username/us_median_age_tract", minzoom = 4, maxzoom = 12, tiles = tile_options(layer_size = 2500) ) county_layer <- recipe_layer( source = "mapbox://tileset-source/your_mapbox_username/us_median_age_county", minzoom = 2, maxzoom = 5 ) recipe <- mts_make_recipe(tracts = tract_layer, counties = county_layer) # Validate the recipe mts_validate_recipe(recipe) # Create a tileset from the recipe mts_create_tileset(tileset_name = "median_age_acs", username = "your_mapbox_username", recipe = recipe) # Publish the tileset mts_publish_tileset(tileset_name = "median_age_acs", username = "your_mapbox_username") # If necessary, update the recipe mts_update_recipe(tileset_name = "median_age_acs", username = "your_mapbox_username", recipe = new_recipe) # Publish the tileset again after you've updated the recipe mts_publish_tileset(tileset_name = "median_age_acs", username = "your_mapbox_username") ## End(Not run)
Retrieve the recipe for an MTS tileset in your Mapbox account
mts_get_recipe(tileset_name, username, access_token = NULL)
mts_get_recipe(tileset_name, username, access_token = NULL)
tileset_name |
The tileset name for which you'd like to retrieve a recipe |
username |
Your Mapbox username |
access_token |
Your Mapbox access token with secret scope |
The recipe for your tileset as an R list
https://docs.mapbox.com/api/maps/mapbox-tiling-service/#retrieve-a-tilesets-recipe
## Not run: library(tidycensus) library(mapboxapi) options(tigris_use_cache = TRUE) # Get the national data on median age us_median_age_tract <- get_acs( geography = "tract", variables = "B01002_001", state = c(state.abb, "DC"), year = 2020, geometry = TRUE ) # Get it for counties as well us_median_age_county <- get_acs( geography = "county", variables = "B01002_001", year = 2020, geometry = TRUE ) # Create a source from the datasets mts_create_source(data = us_median_age_tract, tileset_id = "us_median_age_tract", username = "your_mapbox_username") mts_create_source(data = us_median_age_county, tileset_id = "us_median_age_county", username = "your_mapbox_username") # Build out the recipe. First, create a recipe layer with # appropriate options. We'll want a larger tile size and to restrict the minzoom # to 4; a maxzoom of 12 will be fine as we can overzoom beyond that # # Your source ID will be returned by `mts_create_source()`, so use that value tract_layer <- recipe_layer( source = "mapbox://tileset-source/your_mapbox_username/us_median_age_tract", minzoom = 4, maxzoom = 12, tiles = tile_options(layer_size = 2500) ) county_layer <- recipe_layer( source = "mapbox://tileset-source/your_mapbox_username/us_median_age_county", minzoom = 2, maxzoom = 5 ) recipe <- mts_make_recipe(tracts = tract_layer, counties = county_layer) # Validate the recipe mts_validate_recipe(recipe) # Create a tileset from the recipe mts_create_tileset(tileset_name = "median_age_acs", username = "your_mapbox_username", recipe = recipe) # Publish the tileset mts_publish_tileset(tileset_name = "median_age_acs", username = "your_mapbox_username") # If necessary, update the recipe mts_update_recipe(tileset_name = "median_age_acs", username = "your_mapbox_username", recipe = new_recipe) # Publish the tileset again after you've updated the recipe mts_publish_tileset(tileset_name = "median_age_acs", username = "your_mapbox_username") ## End(Not run)
## Not run: library(tidycensus) library(mapboxapi) options(tigris_use_cache = TRUE) # Get the national data on median age us_median_age_tract <- get_acs( geography = "tract", variables = "B01002_001", state = c(state.abb, "DC"), year = 2020, geometry = TRUE ) # Get it for counties as well us_median_age_county <- get_acs( geography = "county", variables = "B01002_001", year = 2020, geometry = TRUE ) # Create a source from the datasets mts_create_source(data = us_median_age_tract, tileset_id = "us_median_age_tract", username = "your_mapbox_username") mts_create_source(data = us_median_age_county, tileset_id = "us_median_age_county", username = "your_mapbox_username") # Build out the recipe. First, create a recipe layer with # appropriate options. We'll want a larger tile size and to restrict the minzoom # to 4; a maxzoom of 12 will be fine as we can overzoom beyond that # # Your source ID will be returned by `mts_create_source()`, so use that value tract_layer <- recipe_layer( source = "mapbox://tileset-source/your_mapbox_username/us_median_age_tract", minzoom = 4, maxzoom = 12, tiles = tile_options(layer_size = 2500) ) county_layer <- recipe_layer( source = "mapbox://tileset-source/your_mapbox_username/us_median_age_county", minzoom = 2, maxzoom = 5 ) recipe <- mts_make_recipe(tracts = tract_layer, counties = county_layer) # Validate the recipe mts_validate_recipe(recipe) # Create a tileset from the recipe mts_create_tileset(tileset_name = "median_age_acs", username = "your_mapbox_username", recipe = recipe) # Publish the tileset mts_publish_tileset(tileset_name = "median_age_acs", username = "your_mapbox_username") # If necessary, update the recipe mts_update_recipe(tileset_name = "median_age_acs", username = "your_mapbox_username", recipe = new_recipe) # Publish the tileset again after you've updated the recipe mts_publish_tileset(tileset_name = "median_age_acs", username = "your_mapbox_username") ## End(Not run)
List tileset sources in your Mapbox account
mts_list_sources( username, sortby = c("created", "modified"), limit = 100, start = NULL, access_token = NULL )
mts_list_sources( username, sortby = c("created", "modified"), limit = 100, start = NULL, access_token = NULL )
username |
Your Mapbox username |
sortby |
One of |
limit |
The number of tileset sources to return; defaults to 100. The maximum number of tileset sources returned by this endpoint is 2000. |
start |
The source ID at which to start the list of sources; defaults to |
access_token |
Your Mapbox access token with secret scope. |
A data frame containing information on your tileset sources.
https://docs.mapbox.com/api/maps/mapbox-tiling-service/#create-a-tileset-source
## Not run: source_list <- mts_list_sources(username = "your_mapbox_username") ## End(Not run)
## Not run: source_list <- mts_list_sources(username = "your_mapbox_username") ## End(Not run)
List tilesets in a Mapbox account
mts_list_tilesets( username, type = NULL, visibility = NULL, sortby = c("created", "modified"), limit = 100, start = NULL, access_token = NULL )
mts_list_tilesets( username, type = NULL, visibility = NULL, sortby = c("created", "modified"), limit = 100, start = NULL, access_token = NULL )
username |
A Mapbox username |
type |
(optional) Return only |
visibility |
Return only |
sortby |
One of |
limit |
The number of tilesets to return; defaults to 100. The maximum number of tilesets returned by this endpoint is 500. |
start |
The tileset ID at which to start the list of sources; defaults to |
access_token |
Your Mapbox access token with secret scope. |
A data frame containing information on available tilesets in a given Mapbox account.
https://docs.mapbox.com/api/maps/mapbox-tiling-service/#list-tilesets
## Not run: tileset_list <- mts_list_tilesets(username = "your_mapbox_username") ## End(Not run)
## Not run: tileset_list <- mts_list_tilesets(username = "your_mapbox_username") ## End(Not run)
Prepare a recipe for use with the Mapbox Tiling Service
mts_make_recipe(...)
mts_make_recipe(...)
... |
One or more named lists that represent layers in the Mapbox Tiling Service recipe specification (https://docs.mapbox.com/mapbox-tiling-service/reference/#layer-example). These lists can be prepared with the helper function |
An R list representing an MTS recipe to be used to create a tileset.
https://docs.mapbox.com/mapbox-tiling-service/reference/
## Not run: library(tidycensus) library(mapboxapi) options(tigris_use_cache = TRUE) # Get the national data on median age us_median_age_tract <- get_acs( geography = "tract", variables = "B01002_001", state = c(state.abb, "DC"), year = 2020, geometry = TRUE ) # Get it for counties as well us_median_age_county <- get_acs( geography = "county", variables = "B01002_001", year = 2020, geometry = TRUE ) # Create a source from the datasets mts_create_source(data = us_median_age_tract, tileset_id = "us_median_age_tract", username = "your_mapbox_username") mts_create_source(data = us_median_age_county, tileset_id = "us_median_age_county", username = "your_mapbox_username") # Build out the recipe. First, create a recipe layer with # appropriate options. We'll want a larger tile size and to restrict the minzoom # to 4; a maxzoom of 12 will be fine as we can overzoom beyond that # # Your source ID will be returned by `mts_create_source()`, so use that value tract_layer <- recipe_layer( source = "mapbox://tileset-source/your_mapbox_username/us_median_age_tract", minzoom = 4, maxzoom = 12, tiles = tile_options(layer_size = 2500) ) county_layer <- recipe_layer( source = "mapbox://tileset-source/your_mapbox_username/us_median_age_county", minzoom = 2, maxzoom = 5 ) recipe <- mts_make_recipe(tracts = tract_layer, counties = county_layer) # Validate the recipe mts_validate_recipe(recipe) # Create a tileset from the recipe mts_create_tileset(tileset_name = "median_age_acs", username = "your_mapbox_username", recipe = recipe) # Publish the tileset mts_publish_tileset(tileset_name = "median_age_acs", username = "your_mapbox_username") # If necessary, update the recipe mts_update_recipe(tileset_name = "median_age_acs", username = "your_mapbox_username", recipe = new_recipe) # Publish the tileset again after you've updated the recipe mts_publish_tileset(tileset_name = "median_age_acs", username = "your_mapbox_username") ## End(Not run)
## Not run: library(tidycensus) library(mapboxapi) options(tigris_use_cache = TRUE) # Get the national data on median age us_median_age_tract <- get_acs( geography = "tract", variables = "B01002_001", state = c(state.abb, "DC"), year = 2020, geometry = TRUE ) # Get it for counties as well us_median_age_county <- get_acs( geography = "county", variables = "B01002_001", year = 2020, geometry = TRUE ) # Create a source from the datasets mts_create_source(data = us_median_age_tract, tileset_id = "us_median_age_tract", username = "your_mapbox_username") mts_create_source(data = us_median_age_county, tileset_id = "us_median_age_county", username = "your_mapbox_username") # Build out the recipe. First, create a recipe layer with # appropriate options. We'll want a larger tile size and to restrict the minzoom # to 4; a maxzoom of 12 will be fine as we can overzoom beyond that # # Your source ID will be returned by `mts_create_source()`, so use that value tract_layer <- recipe_layer( source = "mapbox://tileset-source/your_mapbox_username/us_median_age_tract", minzoom = 4, maxzoom = 12, tiles = tile_options(layer_size = 2500) ) county_layer <- recipe_layer( source = "mapbox://tileset-source/your_mapbox_username/us_median_age_county", minzoom = 2, maxzoom = 5 ) recipe <- mts_make_recipe(tracts = tract_layer, counties = county_layer) # Validate the recipe mts_validate_recipe(recipe) # Create a tileset from the recipe mts_create_tileset(tileset_name = "median_age_acs", username = "your_mapbox_username", recipe = recipe) # Publish the tileset mts_publish_tileset(tileset_name = "median_age_acs", username = "your_mapbox_username") # If necessary, update the recipe mts_update_recipe(tileset_name = "median_age_acs", username = "your_mapbox_username", recipe = new_recipe) # Publish the tileset again after you've updated the recipe mts_publish_tileset(tileset_name = "median_age_acs", username = "your_mapbox_username") ## End(Not run)
mts_publish_tileset()
publishes an existing vector tileset at your Mapbox account, allowing you to use the vector tiles in your projects. The tileset name will be the same name you specified in mts_create_tileset()
.
mts_publish_tileset(tileset_name, username, access_token = NULL)
mts_publish_tileset(tileset_name, username, access_token = NULL)
tileset_name |
The name of the tileset (as supplied to |
username |
Your Mapbox username |
access_token |
Your Mapbox access token |
The published tileset will conform to rules specified in its recipe. If you want to change the recipe for a tileset, use mts_update_recipe()
then re-publish the tileset with a call to mts_publish_tileset()
once more.
The response from the Mapbox Tiling Service API, formatted as an R list.
https://docs.mapbox.com/api/maps/mapbox-tiling-service/#publish-a-tileset
## Not run: library(tidycensus) library(mapboxapi) options(tigris_use_cache = TRUE) # Get the national data on median age us_median_age_tract <- get_acs( geography = "tract", variables = "B01002_001", state = c(state.abb, "DC"), year = 2020, geometry = TRUE ) # Get it for counties as well us_median_age_county <- get_acs( geography = "county", variables = "B01002_001", year = 2020, geometry = TRUE ) # Create a source from the datasets mts_create_source(data = us_median_age_tract, tileset_id = "us_median_age_tract", username = "your_mapbox_username") mts_create_source(data = us_median_age_county, tileset_id = "us_median_age_county", username = "your_mapbox_username") # Build out the recipe. First, create a recipe layer with # appropriate options. We'll want a larger tile size and to restrict the minzoom # to 4; a maxzoom of 12 will be fine as we can overzoom beyond that # # Your source ID will be returned by `mts_create_source()`, so use that value tract_layer <- recipe_layer( source = "mapbox://tileset-source/your_mapbox_username/us_median_age_tract", minzoom = 4, maxzoom = 12, tiles = tile_options(layer_size = 2500) ) county_layer <- recipe_layer( source = "mapbox://tileset-source/your_mapbox_username/us_median_age_county", minzoom = 2, maxzoom = 5 ) recipe <- mts_make_recipe(tracts = tract_layer, counties = county_layer) # Validate the recipe mts_validate_recipe(recipe) # Create a tileset from the recipe mts_create_tileset(tileset_name = "median_age_acs", username = "your_mapbox_username", recipe = recipe) # Publish the tileset mts_publish_tileset(tileset_name = "median_age_acs", username = "your_mapbox_username") # If necessary, update the recipe mts_update_recipe(tileset_name = "median_age_acs", username = "your_mapbox_username", recipe = new_recipe) # Publish the tileset again after you've updated the recipe mts_publish_tileset(tileset_name = "median_age_acs", username = "your_mapbox_username") ## End(Not run)
## Not run: library(tidycensus) library(mapboxapi) options(tigris_use_cache = TRUE) # Get the national data on median age us_median_age_tract <- get_acs( geography = "tract", variables = "B01002_001", state = c(state.abb, "DC"), year = 2020, geometry = TRUE ) # Get it for counties as well us_median_age_county <- get_acs( geography = "county", variables = "B01002_001", year = 2020, geometry = TRUE ) # Create a source from the datasets mts_create_source(data = us_median_age_tract, tileset_id = "us_median_age_tract", username = "your_mapbox_username") mts_create_source(data = us_median_age_county, tileset_id = "us_median_age_county", username = "your_mapbox_username") # Build out the recipe. First, create a recipe layer with # appropriate options. We'll want a larger tile size and to restrict the minzoom # to 4; a maxzoom of 12 will be fine as we can overzoom beyond that # # Your source ID will be returned by `mts_create_source()`, so use that value tract_layer <- recipe_layer( source = "mapbox://tileset-source/your_mapbox_username/us_median_age_tract", minzoom = 4, maxzoom = 12, tiles = tile_options(layer_size = 2500) ) county_layer <- recipe_layer( source = "mapbox://tileset-source/your_mapbox_username/us_median_age_county", minzoom = 2, maxzoom = 5 ) recipe <- mts_make_recipe(tracts = tract_layer, counties = county_layer) # Validate the recipe mts_validate_recipe(recipe) # Create a tileset from the recipe mts_create_tileset(tileset_name = "median_age_acs", username = "your_mapbox_username", recipe = recipe) # Publish the tileset mts_publish_tileset(tileset_name = "median_age_acs", username = "your_mapbox_username") # If necessary, update the recipe mts_update_recipe(tileset_name = "median_age_acs", username = "your_mapbox_username", recipe = new_recipe) # Publish the tileset again after you've updated the recipe mts_publish_tileset(tileset_name = "median_age_acs", username = "your_mapbox_username") ## End(Not run)
Update a tileset's MTS recipe
mts_update_recipe(tileset_name, username, recipe, access_token = NULL)
mts_update_recipe(tileset_name, username, recipe, access_token = NULL)
tileset_name |
The name of your Mapbox tileset |
username |
Your Mapbox username |
recipe |
The new recipe for your tileset, likely created with |
access_token |
Your Mapbox access token |
If the update is successful, the function will print a message informing you of its success. Otherwise, a list of responses from the API will be returned letting you know why the request was invalid.
https://docs.mapbox.com/api/maps/mapbox-tiling-service/#update-a-tilesets-recipe
## Not run: library(tidycensus) library(mapboxapi) options(tigris_use_cache = TRUE) # Get the national data on median age us_median_age_tract <- get_acs( geography = "tract", variables = "B01002_001", state = c(state.abb, "DC"), year = 2020, geometry = TRUE ) # Get it for counties as well us_median_age_county <- get_acs( geography = "county", variables = "B01002_001", year = 2020, geometry = TRUE ) # Create a source from the datasets mts_create_source(data = us_median_age_tract, tileset_id = "us_median_age_tract", username = "your_mapbox_username") mts_create_source(data = us_median_age_county, tileset_id = "us_median_age_county", username = "your_mapbox_username") # Build out the recipe. First, create a recipe layer with # appropriate options. We'll want a larger tile size and to restrict the minzoom # to 4; a maxzoom of 12 will be fine as we can overzoom beyond that # # Your source ID will be returned by `mts_create_source()`, so use that value tract_layer <- recipe_layer( source = "mapbox://tileset-source/your_mapbox_username/us_median_age_tract", minzoom = 4, maxzoom = 12, tiles = tile_options(layer_size = 2500) ) county_layer <- recipe_layer( source = "mapbox://tileset-source/your_mapbox_username/us_median_age_county", minzoom = 2, maxzoom = 5 ) recipe <- mts_make_recipe(tracts = tract_layer, counties = county_layer) # Validate the recipe mts_validate_recipe(recipe) # Create a tileset from the recipe mts_create_tileset(tileset_name = "median_age_acs", username = "your_mapbox_username", recipe = recipe) # Publish the tileset mts_publish_tileset(tileset_name = "median_age_acs", username = "your_mapbox_username") # If necessary, update the recipe mts_update_recipe(tileset_name = "median_age_acs", username = "your_mapbox_username", recipe = new_recipe) # Publish the tileset again after you've updated the recipe mts_publish_tileset(tileset_name = "median_age_acs", username = "your_mapbox_username") ## End(Not run)
## Not run: library(tidycensus) library(mapboxapi) options(tigris_use_cache = TRUE) # Get the national data on median age us_median_age_tract <- get_acs( geography = "tract", variables = "B01002_001", state = c(state.abb, "DC"), year = 2020, geometry = TRUE ) # Get it for counties as well us_median_age_county <- get_acs( geography = "county", variables = "B01002_001", year = 2020, geometry = TRUE ) # Create a source from the datasets mts_create_source(data = us_median_age_tract, tileset_id = "us_median_age_tract", username = "your_mapbox_username") mts_create_source(data = us_median_age_county, tileset_id = "us_median_age_county", username = "your_mapbox_username") # Build out the recipe. First, create a recipe layer with # appropriate options. We'll want a larger tile size and to restrict the minzoom # to 4; a maxzoom of 12 will be fine as we can overzoom beyond that # # Your source ID will be returned by `mts_create_source()`, so use that value tract_layer <- recipe_layer( source = "mapbox://tileset-source/your_mapbox_username/us_median_age_tract", minzoom = 4, maxzoom = 12, tiles = tile_options(layer_size = 2500) ) county_layer <- recipe_layer( source = "mapbox://tileset-source/your_mapbox_username/us_median_age_county", minzoom = 2, maxzoom = 5 ) recipe <- mts_make_recipe(tracts = tract_layer, counties = county_layer) # Validate the recipe mts_validate_recipe(recipe) # Create a tileset from the recipe mts_create_tileset(tileset_name = "median_age_acs", username = "your_mapbox_username", recipe = recipe) # Publish the tileset mts_publish_tileset(tileset_name = "median_age_acs", username = "your_mapbox_username") # If necessary, update the recipe mts_update_recipe(tileset_name = "median_age_acs", username = "your_mapbox_username", recipe = new_recipe) # Publish the tileset again after you've updated the recipe mts_publish_tileset(tileset_name = "median_age_acs", username = "your_mapbox_username") ## End(Not run)
Validate a Mapbox Tiling Service recipe
mts_validate_recipe(recipe, access_token = NULL)
mts_validate_recipe(recipe, access_token = NULL)
recipe |
A recipe list, created with |
access_token |
Your Mapbox access token. |
A response from the API indicating whether the MTS recipe is valid or not. If the recipe is valid, returns TRUE
, allowing you to use the output of this function for error handling pipelines. If the recipe is invalid, the function returns FALSE
and prints the API response telling you why the recipe is invalid.
https://docs.mapbox.com/api/maps/mapbox-tiling-service/#validate-a-recipe
## Not run: library(tidycensus) library(mapboxapi) options(tigris_use_cache = TRUE) # Get the national data on median age us_median_age_tract <- get_acs( geography = "tract", variables = "B01002_001", state = c(state.abb, "DC"), year = 2020, geometry = TRUE ) # Get it for counties as well us_median_age_county <- get_acs( geography = "county", variables = "B01002_001", year = 2020, geometry = TRUE ) # Create a source from the datasets mts_create_source(data = us_median_age_tract, tileset_id = "us_median_age_tract", username = "your_mapbox_username") mts_create_source(data = us_median_age_county, tileset_id = "us_median_age_county", username = "your_mapbox_username") # Build out the recipe. First, create a recipe layer with # appropriate options. We'll want a larger tile size and to restrict the minzoom # to 4; a maxzoom of 12 will be fine as we can overzoom beyond that # # Your source ID will be returned by `mts_create_source()`, so use that value tract_layer <- recipe_layer( source = "mapbox://tileset-source/your_mapbox_username/us_median_age_tract", minzoom = 4, maxzoom = 12, tiles = tile_options(layer_size = 2500) ) county_layer <- recipe_layer( source = "mapbox://tileset-source/your_mapbox_username/us_median_age_county", minzoom = 2, maxzoom = 5 ) recipe <- mts_make_recipe(tracts = tract_layer, counties = county_layer) # Validate the recipe mts_validate_recipe(recipe) # Create a tileset from the recipe mts_create_tileset(tileset_name = "median_age_acs", username = "your_mapbox_username", recipe = recipe) # Publish the tileset mts_publish_tileset(tileset_name = "median_age_acs", username = "your_mapbox_username") # If necessary, update the recipe mts_update_recipe(tileset_name = "median_age_acs", username = "your_mapbox_username", recipe = new_recipe) # Publish the tileset again after you've updated the recipe mts_publish_tileset(tileset_name = "median_age_acs", username = "your_mapbox_username") ## End(Not run)
## Not run: library(tidycensus) library(mapboxapi) options(tigris_use_cache = TRUE) # Get the national data on median age us_median_age_tract <- get_acs( geography = "tract", variables = "B01002_001", state = c(state.abb, "DC"), year = 2020, geometry = TRUE ) # Get it for counties as well us_median_age_county <- get_acs( geography = "county", variables = "B01002_001", year = 2020, geometry = TRUE ) # Create a source from the datasets mts_create_source(data = us_median_age_tract, tileset_id = "us_median_age_tract", username = "your_mapbox_username") mts_create_source(data = us_median_age_county, tileset_id = "us_median_age_county", username = "your_mapbox_username") # Build out the recipe. First, create a recipe layer with # appropriate options. We'll want a larger tile size and to restrict the minzoom # to 4; a maxzoom of 12 will be fine as we can overzoom beyond that # # Your source ID will be returned by `mts_create_source()`, so use that value tract_layer <- recipe_layer( source = "mapbox://tileset-source/your_mapbox_username/us_median_age_tract", minzoom = 4, maxzoom = 12, tiles = tile_options(layer_size = 2500) ) county_layer <- recipe_layer( source = "mapbox://tileset-source/your_mapbox_username/us_median_age_county", minzoom = 2, maxzoom = 5 ) recipe <- mts_make_recipe(tracts = tract_layer, counties = county_layer) # Validate the recipe mts_validate_recipe(recipe) # Create a tileset from the recipe mts_create_tileset(tileset_name = "median_age_acs", username = "your_mapbox_username", recipe = recipe) # Publish the tileset mts_publish_tileset(tileset_name = "median_age_acs", username = "your_mapbox_username") # If necessary, update the recipe mts_update_recipe(tileset_name = "median_age_acs", username = "your_mapbox_username", recipe = new_recipe) # Publish the tileset again after you've updated the recipe mts_publish_tileset(tileset_name = "median_age_acs", username = "your_mapbox_username") ## End(Not run)
Markers are prepared to match GeoJSON marker-spec which is a partial implementation of the GeoJSON simplestyle-spec (described as a work-in-progress by Mapbox).
prep_overlay_markers( data = NULL, marker_type = c("pin-s", "pin-l", "url"), label = NA, color = NA, longitude = NULL, latitude = NULL, url = NA )
prep_overlay_markers( data = NULL, marker_type = c("pin-s", "pin-l", "url"), label = NA, color = NA, longitude = NULL, latitude = NULL, url = NA )
data |
An input data frame with longitude and latitude columns (X and Y
or lon and lat as names are also acceptable) or an |
marker_type |
The marker type; one of |
label |
The marker label (optional). Can be a letter, number (0 through 99), or a valid Maki icon (see https://labs.mapbox.com/maki-icons/) for options). |
color |
The marker color (optional). |
longitude |
A vector of longitudes; inferred from the input dataset if
|
latitude |
A vector of latitudes; inferred from the input dataset if
|
url |
The URL of the image to be used for the icon if |
A formatted list of marker specifications that can be passed to the static_mapbox function.
Get information about features in a tileset using the Tilequery API
query_tiles( location, tileset_id, radius = 0, limit = 5, dedupe = TRUE, geometry = NULL, layers = NULL, access_token = NULL )
query_tiles( location, tileset_id, radius = 0, limit = 5, dedupe = TRUE, geometry = NULL, layers = NULL, access_token = NULL )
location |
The location for which you'd like to query tiles, expressed as either a length-2 vector of longitude and latitude or an address you'd like to geocode. |
tileset_id |
The tileset ID to query. |
radius |
The radius around the point (in meters) for which you'd like to query features. For point-in-polygon queries (e.g. "what county is my point located in?") the default of 0 should be used. |
limit |
How many features to return (defaults to 5). Can be an integer between 1 and 50. |
dedupe |
Whether or not to return duplicate features as identified by their IDs. The default, TRUE, will de-duplicate your dataset. |
geometry |
The feature geometry type to query - can be |
layers |
A vector of layer IDs you'd like to query (recommended); if left blank will query all layers, with the limitation that at most 50 features can be returned. |
access_token |
A Mapbox access token, which can be set with
|
An R list containing the API response, which includes information about the requested features. Parse the list to extract desired elements.
https://docs.mapbox.com/help/tutorials/find-elevations-with-tilequery-api/
## Not run: library(mapboxapi) elevation <- query_tiles( location = "Breckenridge, Colorado", tileset_id = "mapbox.mapbox-terrain-v2", layer = "contour", limit = 50 ) max(elevation$features$properties$ele) ## End(Not run)
## Not run: library(mapboxapi) elevation <- query_tiles( location = "Breckenridge, Colorado", tileset_id = "mapbox.mapbox-terrain-v2", layer = "contour", limit = 50 ) max(elevation$features$properties$ele) ## End(Not run)
Prepare a formatted recipe layer for use in a Mapbox Tiling Service recipe
recipe_layer( source, minzoom, maxzoom, features = feature_options(), tiles = tile_options() )
recipe_layer( source, minzoom, maxzoom, features = feature_options(), tiles = tile_options() )
source |
The tileset source ID. This is returned by |
minzoom |
The minimum zoom level at which a layer can be viewed. |
maxzoom |
The maximum zoom level at which a layer is rendered; the layer will still be visible past the maximum zoom level due to overzooming. |
features |
A list of feature options, possibly generated with |
tiles |
A list of tile options, possibly generated with |
A recipe layer list to be used in mts_make_recipe()
.
https://docs.mapbox.com/mapbox-tiling-service/reference/
## Not run: library(tidycensus) library(mapboxapi) options(tigris_use_cache = TRUE) # Get the national data on median age us_median_age_tract <- get_acs( geography = "tract", variables = "B01002_001", state = c(state.abb, "DC"), year = 2020, geometry = TRUE ) # Get it for counties as well us_median_age_county <- get_acs( geography = "county", variables = "B01002_001", year = 2020, geometry = TRUE ) # Create a source from the datasets mts_create_source(data = us_median_age_tract, tileset_id = "us_median_age_tract", username = "your_mapbox_username") mts_create_source(data = us_median_age_county, tileset_id = "us_median_age_county", username = "your_mapbox_username") # Build out the recipe. First, create a recipe layer with # appropriate options. We'll want a larger tile size and to restrict the minzoom # to 4; a maxzoom of 12 will be fine as we can overzoom beyond that # # Your source ID will be returned by `mts_create_source()`, so use that value tract_layer <- recipe_layer( source = "mapbox://tileset-source/your_mapbox_username/us_median_age_tract", minzoom = 4, maxzoom = 12, tiles = tile_options(layer_size = 2500) ) county_layer <- recipe_layer( source = "mapbox://tileset-source/your_mapbox_username/us_median_age_county", minzoom = 2, maxzoom = 5 ) recipe <- mts_make_recipe(tracts = tract_layer, counties = county_layer) # Validate the recipe mts_validate_recipe(recipe) # Create a tileset from the recipe mts_create_tileset(tileset_name = "median_age_acs", username = "your_mapbox_username", recipe = recipe) # Publish the tileset mts_publish_tileset(tileset_name = "median_age_acs", username = "your_mapbox_username") # If necessary, update the recipe mts_update_recipe(tileset_name = "median_age_acs", username = "your_mapbox_username", recipe = new_recipe) # Publish the tileset again after you've updated the recipe mts_publish_tileset(tileset_name = "median_age_acs", username = "your_mapbox_username") ## End(Not run)
## Not run: library(tidycensus) library(mapboxapi) options(tigris_use_cache = TRUE) # Get the national data on median age us_median_age_tract <- get_acs( geography = "tract", variables = "B01002_001", state = c(state.abb, "DC"), year = 2020, geometry = TRUE ) # Get it for counties as well us_median_age_county <- get_acs( geography = "county", variables = "B01002_001", year = 2020, geometry = TRUE ) # Create a source from the datasets mts_create_source(data = us_median_age_tract, tileset_id = "us_median_age_tract", username = "your_mapbox_username") mts_create_source(data = us_median_age_county, tileset_id = "us_median_age_county", username = "your_mapbox_username") # Build out the recipe. First, create a recipe layer with # appropriate options. We'll want a larger tile size and to restrict the minzoom # to 4; a maxzoom of 12 will be fine as we can overzoom beyond that # # Your source ID will be returned by `mts_create_source()`, so use that value tract_layer <- recipe_layer( source = "mapbox://tileset-source/your_mapbox_username/us_median_age_tract", minzoom = 4, maxzoom = 12, tiles = tile_options(layer_size = 2500) ) county_layer <- recipe_layer( source = "mapbox://tileset-source/your_mapbox_username/us_median_age_county", minzoom = 2, maxzoom = 5 ) recipe <- mts_make_recipe(tracts = tract_layer, counties = county_layer) # Validate the recipe mts_validate_recipe(recipe) # Create a tileset from the recipe mts_create_tileset(tileset_name = "median_age_acs", username = "your_mapbox_username", recipe = recipe) # Publish the tileset mts_publish_tileset(tileset_name = "median_age_acs", username = "your_mapbox_username") # If necessary, update the recipe mts_update_recipe(tileset_name = "median_age_acs", username = "your_mapbox_username", recipe = new_recipe) # Publish the tileset again after you've updated the recipe mts_publish_tileset(tileset_name = "median_age_acs", username = "your_mapbox_username") ## End(Not run)
This function uses the Mapbox Static Maps API to return a pointer to an
"magick-image"
class image or a httr::response object from the static map
image URL.
static_mapbox( location = NULL, buffer_dist = 1000, units = "m", style_id, username, style_url = NULL, overlay_sf = NULL, overlay_style = NULL, overlay_markers = NULL, longitude = NULL, latitude = NULL, zoom = NULL, width = NULL, height = NULL, bearing = NULL, pitch = NULL, scale = 0.5, scaling_factor = c("1x", "2x"), attribution = TRUE, logo = TRUE, before_layer = NULL, access_token = NULL, image = TRUE, strip = TRUE )
static_mapbox( location = NULL, buffer_dist = 1000, units = "m", style_id, username, style_url = NULL, overlay_sf = NULL, overlay_style = NULL, overlay_markers = NULL, longitude = NULL, latitude = NULL, zoom = NULL, width = NULL, height = NULL, bearing = NULL, pitch = NULL, scale = 0.5, scaling_factor = c("1x", "2x"), attribution = TRUE, logo = TRUE, before_layer = NULL, access_token = NULL, image = TRUE, strip = TRUE )
location |
An input location for which you would like to request tiles.
Can be a length-4 vector representing a bounding box, or an |
buffer_dist |
The distance to buffer around an input |
units |
Units of |
style_id |
A style ID (required if style_url is |
username |
A Mapbox username (required if |
style_url |
A Mapbox style url; defaults to |
overlay_sf |
The overlay |
overlay_style |
A named list of vectors specifying how to style the sf
overlay. Possible names are "stroke", "stroke-width" (or "stroke_width"),
"stroke-opacity" (or "stroke_opacity"), "fill", and "fill-opacity" (or
"fill_opacity"). The fill and stroke color values can be specified as
six-digit hex codes or color names, and the opacity and width values should
be supplied as floating-point numbers. If overlay_style is |
overlay_markers |
The prepared overlay markers (optional). See the function prep_overlay_markers for more information on how to specify a marker overlay. |
longitude , latitude
|
The longitude and latitude of the map center. If an overlay is supplied, the map will default to the extent of the overlay unless longitude, latitude, and zoom are all specified. |
zoom |
The map zoom. The map will infer this from the overlay unless longitude, latitude, and zoom are all specified. |
width , height
|
The map width and height; defaults to |
pitch , bearing
|
The map pitch and bearing; defaults to |
scale |
ratio to scale the output image; |
scaling_factor |
The scaling factor of the tiles; either |
attribution |
Controls whether there is attribution on the image.
Defaults to |
logo |
Controls whether there is a Mapbox logo on the image. Defaults to
|
before_layer |
A character string that specifies where in the hierarchy
of layer elements the overlay should be inserted. The overlay will be
placed just above the specified layer in the given Mapbox styles. List
layer ids for a map style with |
access_token |
A Mapbox access token; which can be set with mb_access_token. |
image |
If |
strip |
If |
A pointer to an image of class "magick-image"
if image = TRUE
.
The resulting image can be manipulated further with functions from the
magick package.
## Not run: library(mapboxapi) points_of_interest <- tibble::tibble( longitude = c(-73.99405, -74.00616, -73.99577, -74.00761), latitude = c(40.72033, 40.72182, 40.71590, 40.71428) ) prepped_pois <- prep_overlay_markers( data = points_of_interest, marker_type = "pin-l", label = 1:4, color = "fff" ) map <- static_mapbox( style_id = "streets-v11", username = "mapbox", overlay_markers = prepped_pois, width = 1200, height = 800 ) map ## End(Not run)
## Not run: library(mapboxapi) points_of_interest <- tibble::tibble( longitude = c(-73.99405, -74.00616, -73.99577, -74.00761), latitude = c(40.72033, 40.72182, 40.71590, 40.71428) ) prepped_pois <- prep_overlay_markers( data = points_of_interest, marker_type = "pin-l", label = 1:4, color = "fff" ) map <- static_mapbox( style_id = "streets-v11", username = "mapbox", overlay_markers = prepped_pois, width = 1200, height = 800 ) map ## End(Not run)
Specify tile options for an MTS recipe layer
tile_options( bbox = NULL, extent = NULL, buffer_size = NULL, limit = NULL, union = list(where = NULL, group_by = NULL, aggregate = NULL, maintain_direction = NULL, simplification = NULL), filter = NULL, attributes = NULL, order = NULL, remove_filled = NULL, id = NULL, layer_size = NULL )
tile_options( bbox = NULL, extent = NULL, buffer_size = NULL, limit = NULL, union = list(where = NULL, group_by = NULL, aggregate = NULL, maintain_direction = NULL, simplification = NULL), filter = NULL, attributes = NULL, order = NULL, remove_filled = NULL, id = NULL, layer_size = NULL )
bbox , extent , buffer_size , limit , union , filter , attributes , order , remove_filled , id , layer_size
|
Tile options in the MTS recipe. See https://docs.mapbox.com/mapbox-tiling-service/reference/#tile-configuration for more information on the available options. |
A list of tile options, likely to be used in recipe_layer
.
https://docs.mapbox.com/mapbox-tiling-service/reference/
## Not run: library(tidycensus) library(mapboxapi) options(tigris_use_cache = TRUE) # Get the national data on median age us_median_age_tract <- get_acs( geography = "tract", variables = "B01002_001", state = c(state.abb, "DC"), year = 2020, geometry = TRUE ) # Get it for counties as well us_median_age_county <- get_acs( geography = "county", variables = "B01002_001", year = 2020, geometry = TRUE ) # Create a source from the datasets mts_create_source(data = us_median_age_tract, tileset_id = "us_median_age_tract", username = "your_mapbox_username") mts_create_source(data = us_median_age_county, tileset_id = "us_median_age_county", username = "your_mapbox_username") # Build out the recipe. First, create a recipe layer with # appropriate options. We'll want a larger tile size and to restrict the minzoom # to 4; a maxzoom of 12 will be fine as we can overzoom beyond that # # Your source ID will be returned by `mts_create_source()`, so use that value tract_layer <- recipe_layer( source = "mapbox://tileset-source/your_mapbox_username/us_median_age_tract", minzoom = 4, maxzoom = 12, tiles = tile_options(layer_size = 2500) ) county_layer <- recipe_layer( source = "mapbox://tileset-source/your_mapbox_username/us_median_age_county", minzoom = 2, maxzoom = 5 ) recipe <- mts_make_recipe(tracts = tract_layer, counties = county_layer) # Validate the recipe mts_validate_recipe(recipe) # Create a tileset from the recipe mts_create_tileset(tileset_name = "median_age_acs", username = "your_mapbox_username", recipe = recipe) # Publish the tileset mts_publish_tileset(tileset_name = "median_age_acs", username = "your_mapbox_username") # If necessary, update the recipe mts_update_recipe(tileset_name = "median_age_acs", username = "your_mapbox_username", recipe = new_recipe) # Publish the tileset again after you've updated the recipe mts_publish_tileset(tileset_name = "median_age_acs", username = "your_mapbox_username") ## End(Not run)
## Not run: library(tidycensus) library(mapboxapi) options(tigris_use_cache = TRUE) # Get the national data on median age us_median_age_tract <- get_acs( geography = "tract", variables = "B01002_001", state = c(state.abb, "DC"), year = 2020, geometry = TRUE ) # Get it for counties as well us_median_age_county <- get_acs( geography = "county", variables = "B01002_001", year = 2020, geometry = TRUE ) # Create a source from the datasets mts_create_source(data = us_median_age_tract, tileset_id = "us_median_age_tract", username = "your_mapbox_username") mts_create_source(data = us_median_age_county, tileset_id = "us_median_age_county", username = "your_mapbox_username") # Build out the recipe. First, create a recipe layer with # appropriate options. We'll want a larger tile size and to restrict the minzoom # to 4; a maxzoom of 12 will be fine as we can overzoom beyond that # # Your source ID will be returned by `mts_create_source()`, so use that value tract_layer <- recipe_layer( source = "mapbox://tileset-source/your_mapbox_username/us_median_age_tract", minzoom = 4, maxzoom = 12, tiles = tile_options(layer_size = 2500) ) county_layer <- recipe_layer( source = "mapbox://tileset-source/your_mapbox_username/us_median_age_county", minzoom = 2, maxzoom = 5 ) recipe <- mts_make_recipe(tracts = tract_layer, counties = county_layer) # Validate the recipe mts_validate_recipe(recipe) # Create a tileset from the recipe mts_create_tileset(tileset_name = "median_age_acs", username = "your_mapbox_username", recipe = recipe) # Publish the tileset mts_publish_tileset(tileset_name = "median_age_acs", username = "your_mapbox_username") # If necessary, update the recipe mts_update_recipe(tileset_name = "median_age_acs", username = "your_mapbox_username", recipe = new_recipe) # Publish the tileset again after you've updated the recipe mts_publish_tileset(tileset_name = "median_age_acs", username = "your_mapbox_username") ## End(Not run)
Tippecanoe is a tile-generation utility for building vector tilesets from large (or small) collections of GeoJSON, Geobuf, or CSV features. The tippecanoe function requires that the tippecanoe utility is installed on your system; see the tippecanoe documentation for installation instructions. Once installed, tippecanoe can be used in large visualization workflows in concert with Mapbox Studio.
tippecanoe( input, output, layer_name = NULL, min_zoom = NULL, max_zoom = NULL, drop_rate = NULL, overwrite = TRUE, other_options = NULL, keep_geojson = FALSE )
tippecanoe( input, output, layer_name = NULL, min_zoom = NULL, max_zoom = NULL, drop_rate = NULL, overwrite = TRUE, other_options = NULL, keep_geojson = FALSE )
input |
The dataset from which to generate vector tiles. Can be an sf object or GeoJSON file on disk. |
output |
The name of the output .mbtiles file (with .mbtiles extension). Will be saved in the current working directory. |
layer_name |
The name of the layer in the output .mbtiles file. If NULL,
will either be a random string (if input is an |
min_zoom , max_zoom
|
The minimum and maximum zoom levels for which to compute tiles. If both min_zoom and max_zoom are blank, tippecanoe will guess the best zoom levels for your data. |
drop_rate |
The rate at which tippecanoe will drop features as you zoom out. If NULL, tippecanoe will drop features as needed in the densest tiles to stay within Mapbox's limits. |
overwrite |
If |
other_options |
A character string of other options to be passed to the tippecanoe program. |
keep_geojson |
Whether nor not to keep the temporary CSV or GeoJSON file
used to generate the tiles. Defaults to |
Mapbox also offers the Mapbox Tiling Service as an alternate way to transform datasets into vector tiles.
## Not run: # Workflow: create a dynamic tileset for dot-density mapping library(tidycensus) library(sf) library(mapboxapi) # Get population data for Census tracts in Vermont vt_population <- get_decennial( geography = "tract", variables = "P001001", state = "Vermont", year = 2010, geometry = TRUE ) # Convert to representative dots - 1 per person vt_dots <- st_sample( vt_population, size = vt_population$value ) # Use tippecanoe to create dynamic tiles tippecanoe( input = vt_dots, output = "vt_population.mbtiles", layer_name = "vermont_population", max_zoom = 18, drop_rate = 1.5 ) # Upload to your Mapbox account for visualization # A Mapbox secret access token must be set with mb_access_token() # to upload data to your account upload_tiles( input = "vt_population.mbtiles", username = "kwalkertcu", tileset_id = "vt_population_dots", multipart = TRUE ) ## End(Not run)
## Not run: # Workflow: create a dynamic tileset for dot-density mapping library(tidycensus) library(sf) library(mapboxapi) # Get population data for Census tracts in Vermont vt_population <- get_decennial( geography = "tract", variables = "P001001", state = "Vermont", year = 2010, geometry = TRUE ) # Convert to representative dots - 1 per person vt_dots <- st_sample( vt_population, size = vt_population$value ) # Use tippecanoe to create dynamic tiles tippecanoe( input = vt_dots, output = "vt_population.mbtiles", layer_name = "vermont_population", max_zoom = 18, drop_rate = 1.5 ) # Upload to your Mapbox account for visualization # A Mapbox secret access token must be set with mb_access_token() # to upload data to your account upload_tiles( input = "vt_population.mbtiles", username = "kwalkertcu", tileset_id = "vt_population_dots", multipart = TRUE ) ## End(Not run)
Upload dataset to your Mapbox account
upload_tiles( input, username, access_token = NULL, tileset_id = NULL, tileset_name = NULL, keep_geojson = FALSE, multipart = FALSE )
upload_tiles( input, username, access_token = NULL, tileset_id = NULL, tileset_name = NULL, keep_geojson = FALSE, multipart = FALSE )
input |
An |
username |
Your Mapbox username |
access_token |
Your Mapbox access token; must have secret scope |
tileset_id |
The ID of the tileset in your Mapbox account |
tileset_name |
The name of the tileset in your Mapbox account |
keep_geojson |
Whether or not to keep the temporary GeoJSON used to
generate the tiles (if the input is an |
multipart |
Whether or not to upload to the temporary AWS staging bucket
as a multipart object; defaults to |
## Not run: # Example: create a tileset of median age for all United States Census tracts # Requires setting a Mapbox secret access token as an environment variable library(mapboxapi) library(tidycensus) options(tigris_use_cache = TRUE) median_age <- get_acs( geography = "tract", variables = "B01002_001", state = c(state.abb, "DC"), geometry = TRUE ) upload_tiles( input = median_age, username = "kwalkertcu", # Your username goes here tileset_id = "median_age", tileset_name = "us_median_age_2014_to_2018" ) ## End(Not run)
## Not run: # Example: create a tileset of median age for all United States Census tracts # Requires setting a Mapbox secret access token as an environment variable library(mapboxapi) library(tidycensus) options(tigris_use_cache = TRUE) median_age <- get_acs( geography = "tract", variables = "B01002_001", state = c(state.abb, "DC"), geometry = TRUE ) upload_tiles( input = median_age, username = "kwalkertcu", # Your username goes here tileset_id = "median_age", tileset_name = "us_median_age_2014_to_2018" ) ## End(Not run)