feature_options: Specify feature options for an MTS recipe layer

View source: R/mts.R

feature_optionsR Documentation

Specify feature options for an MTS recipe layer

Description

Specify feature options for an MTS recipe layer

Usage

feature_options(
  id = NULL,
  bbox = NULL,
  attributes = list(zoom_element = NULL, set = NULL, allowed_output = NULL),
  filter = NULL,
  simplification = NULL
)

Arguments

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. zoom_element specifies how an attribute should be made available at different zoom levels; set allows you to calculate new attributes from existing attributes when processing the tiles; and allowed_output specifies which columns should be carried through to the output tiles. See https://docs.mapbox.com/mapbox-tiling-service/reference/#feature-attributes.

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.

Value

A list of feature options, likely to be used in recipe_layer().

See Also

https://docs.mapbox.com/mapbox-tiling-service/reference/

Examples

## 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)

mapboxapi documentation built on Sept. 21, 2024, 1:06 a.m.