Skip to main content

Raster Recipe Details

A recipe is a JSON document composed of configuration options that tell Mapbox Tiling Service (MTS) how to turn a raster source data into MRT or raster tiles. Recipes allow you to specify details like:

  • The minimum and maximum zoom levels at which you want the features in your tilesets to be visible.
  • Which bands to use for processing.
  • Configure tilesize, buffer and scale for "rasterarray" sources.

Recipes must be constructed according to the rules in the Recipe specification.

To see example recipes for frequently-requested use cases, see the Recipe examples page.

You can use the Tileset explorer to see the recipe for an existing tileset created with MTS. In the Mapbox Studio Tilesets page, click on the tileset's name to open Tileset explorer. Click on Job history, then click on View recipe.

Common recipe filters

Filtering bands based on their index

Recipe filters are quite powerful, but occasionally you might need a filter to target an individual band may not have any band metadata associated with it. In cases like this, we can use the bandindex filter. In this example, we're specifying a filter that uses the bandindex in the expression to filter the band at index 1.

{
"version": 1,
"type": "rasterarray",
"minzoom": 1,
"maxzoom": 3,
"sources": [
{
"uri": "mapbox://tileset-source/{ACCOUNT}/source_1"
}
],
"layers": {
"basic": {
"tilesize": 256,
"resampling": "nearest",
"buffer": 1,
"source_rules": {
"filter": ["all", ["in", ["bandindex"], ["literal", [1]]]]
}
}
}
}

If we wanted to target multiple bands based on their indices, we would change the filter to include a list of all the indices we want. With this filter, we'd get bands 1 through 5.

{
"filter": ["all", ["in", ["bandindex"], ["literal", [1, 2, 3, 4, 5]]]]
}

Filtering bands based on a source tag and band index

Let's look at a slightly more complex recipe where we have two layers and want each layer to include data from a specific source file that does not include band metadata to aid in the filtering. In this scenario, we can use the sourcetag filter along with adding a tag property on a source. We're also including the bandindex in the filter here to make sure our layers have the appropriate bands from each file. This filter can be modified to filter bands on specific band metadata if needed.

{
"version": 1,
"type": "rasterarray",
"minzoom": 2,
"maxzoom": 11,
"sources": [
{
"uri": "mapbox://tileset-source/{ACCOUNT}/source_1",
"tag": "source1"
},
{
"uri": "mapbox://tileset-source/{ACCOUNT}/source_2",
"tag": "source2"
}
],
"layers": {
"layer_from_source1": {
"tilesize": 256,
"resampling": "nearest",
"buffer": 1,
"source_rules": {
"filter": [
"all",
["in", ["bandindex"], ["literal", [1]]],
["in", ["sourcetag"], ["literal", ["source1"]]]
]
}
},
"layer_from_source2": {
"tilesize": 256,
"resampling": "nearest",
"buffer": 1,
"source_rules": {
"filter": [
"all",
["in", ["bandindex"], ["literal", [1]]],
["in", ["sourcetag"], ["literal", ["source2"]]]
]
}
}
}
}
Was this page helpful?