Tilequery API
The Mapbox Tilequery API allows you to retrieve data about specific features from rasterarray
and vector
tilesets, based on a given latitude and longitude. Depending on the type of tileset, the Tilequery API can provide slightly different functionality. For vector
tilesets, the Tilequery API makes it possible to query for features within a radius, do point-in-polygon queries, query for features in multiple composite layers, and augment data from the Mapbox Geocoding API with custom data. For rasterarray
tilesets, the Tilequery API makes it possible to query a specific point value across different layers and bands within the tileset.
Mapbox Tilequery API has some functional similarities to the reverse geocoding function of the Mapbox Geocoding API, which accepts a {longitude},{latitude}
pair and returns an address. When querying vector
tilesets with the radius
parameter, the Tilequery API returns the location and properties of the features within the query radius.
NOTE: Mapbox Tilequery API does not support retrieving data from raster
source
Create and run Tilequery API queries and see the results on a map.
Retrieve features from a tileset
Use this endpoint to retrieve features a tileset.
Required parameters | Type | Description |
---|---|---|
tileset_id | string | The ID of the map being queried. To query multiple tilesets at the same time, use a comma-separated list of up to 15 tileset IDs. |
{lon},{lat} | number | The longitude and latitude to be queried. |
You can further refine the results from this endpoint with the following optional parameters:
Vector Specific Query Parameters
Optional parameters | Type | Description |
---|---|---|
radius | number | The approximate distance to query for features, in meters. Defaults to 0 , which does a point-in-polygon query. Has no upper bound. Required for queries against point and line data. Due to the nature of tile buffering, a query with a large radius made against equally large point or line data may not include all possible features in the results. Queries will use tiles from the maximum zoom of the tileset, and will only include the intersecting tile plus eight surrounding tiles when searching for nearby features. |
limit | integer | The number of features between 1 -50 to return. Defaults to 5 . The specified number of features are returned in order of their proximity to the queried {lon},{lat} . |
dedupe | boolean | Determines whether the features in the result will be deduplicated (true , default) or not (false ). The Tilequery API assumes that features are duplicates if all the following are true: the features are from the same layer; the features are the same geometry type; and the features have the same ID and the same properties (or the same properties, if the features do not have IDs). |
geometry | string | Return only a specific geometry type. Options are polygon , linestring , or point . Defaults to returning all geometry types. |
layers | string | A comma-separated list of layers to query, rather than querying all layers. If a specified layer does not exist, it is skipped. If no layers exist, returns an empty FeatureCollection . |
Rasterarray Specific Query Parameters
Although the following parameters are listed as optional, if not provided, the response will contain an empty FeatureCollection
as a rasterarray
tileset can contain many layers and bands.
Optional parameters | Type | Description |
---|---|---|
bands | string | A comma-separated list of bands to query, rather than querying all bands. If a specified band does not exist, it is skipped. If no bands exist, returns an empty FeatureCollection . |
layers | string | A comma-separated list of layers to query, rather than querying all layers. If a specified layer does not exist, it is skipped. If no layers exist, returns an empty FeatureCollection . |
Vector Point-in-polygon queries
To do a point-in-polygon query, do not use the radius
parameter, which will leave it set at the default value of 0
. A point-in-polygon query will only return polygons that your query point is within. Any query point that exists directly along an edge of a polygon will not be returned.
Be aware of the number of results you are returning. There may be overlapping polygons in a tile, especially if you are querying multiple layers. If a query point exists within multiple polygons, there is no way to sort results such that they are returned in the order they were queried. If there are more results than you specified with the limit
parameter, they will not be displayed after the query's limit
is exceeded.
Retrieve features from vector tilesets
Example requests
# Retrieve features within a 10 meter radius of the specified location
$ curl "https://api.mapbox.com/v4/mapbox.mapbox-streets-v8/tilequery/-122.42901,37.80633.json?radius=10&access_token=YOUR_MAPBOX_ACCESS_TOKEN"
# Return at most 20 features
$ curl "https://api.mapbox.com/v4/mapbox.mapbox-streets-v8/tilequery/-122.42901,37.80633.json?limit=20&access_token=YOUR_MAPBOX_ACCESS_TOKEN"
# Query multiple tilesets
$ curl "https://api.mapbox.com/v4/{tileset_id_1},{tileset_id_2},{tileset_id_3}/tilequery/-122.42901,37.80633.json?access_token=YOUR_MAPBOX_ACCESS_TOKEN"
# Return only results from the poi_label and building layers within a 30 meter radius of the specified location
$ curl "https://api.mapbox.com/v4/mapbox.mapbox-streets-v8/tilequery/-122.42901,37.80633.json?radius=30&layers=poi_label,building?access_token=YOUR_MAPBOX_ACCESS_TOKEN"
Response format
A request to the Tilequery API for vector
tilesets returns a GeoJSON FeatureCollection
of features at or near the geographic point described by {longitude},{latitude}
and within the distance described by the optional radius
parameter.
The Tilequery API response is ordered based on which features are closest to the queried {longitude},{latitude}
. If a point-in-polygon query was performed, then all returned features are directly at the query point and proximity does not influence the order in which they are returned.
Each feature in the response body contains the following properties:
Property | Type | Description | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
type | string | This will always be Feature . | ||||||||
id | string | The identifier of the returned feature, as represented in the queried vector tile. | ||||||||
geometry.type | string | This will always be Point . The Tilequery API does not return the full geometry of a feature. Instead, it returns the closest point ({longitude},{latitude} ) of a feature. | ||||||||
geometry.coordinates | array | The coordinates of the returned feature. | ||||||||
properties | object | The properties of the feature. | ||||||||
properties.tilequery.distance | number | The approximate surface distance from the feature result to the queried point, in meters. Note that this number is geographical distance, not distance along the road network. If distance is 0 , the query point is within the geometry (point-in-polygon). | ||||||||
properties.tilequery.geometry | string | The original geometry type of the feature. This can be ”point” , ”linestring” , or ”polygon” . The actual geometry of the feature is not returned in the result set. The original geometry type of a feature impacts what gets returned:
| ||||||||
properties.tilequery.layer | string | The vector tile layer of the feature result. |
Example response
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"id": 4174053671,
"geometry": {
"type": "Point",
"coordinates": [-122.42901, 37.80633]
},
"properties": {
"class": "national_park",
"type": "national_park",
"tilequery": {
"distance": 0,
"geometry": "polygon",
"layer": "landuse_overlay"
}
}
},
{
"type": "Feature",
"id": 822070541,
"geometry": {
"type": "Point",
"coordinates": [-122.4289919435978, 37.806283149631255]
},
"properties": {
"localrank": 1,
"maki": "park",
"name": "Fort Mason",
"name_ar": "Fort Mason",
"name_de": "Fort Mason",
"name_en": "Fort Mason Center",
"name_es": "Fort Mason",
"name_fr": "Fort Mason",
"name_pt": "Fort Mason",
"name_ru": "Fort Mason",
"name_zh": "梅森堡",
"name_zh-Hans": "梅森堡",
"ref": "",
"scalerank": 1,
"type": "National Park",
"tilequery": {
"distance": 5.4376397785894595,
"geometry": "point",
"layer": "poi_label"
}
}
}
]
}
Retrieve features from rasterarray tilesets
Example requests
# Retrieve point specific features for multiple bands from a single layer
$ curl "https://api.mapbox.com/{{constants.VERSION_MAPS_API}}/{tileset_id}/tilequery/-122.42901,37.80633.json?bands=1663516800,1663520400&layers=temperature&access_token=YOUR_MAPBOX_ACCESS_TOKEN"
# Query multiple tilesets
$ curl "https://api.mapbox.com/{{constants.VERSION_MAPS_API}}/{tileset_id_1},{tileset_id_2},{tileset_id_3}/tilequery/-122.42901,37.80633.json?bands=1663516800,1663520400&layers=temperature&access_token=YOUR_MAPBOX_ACCESS_TOKEN"
Response format
A request to the Tilequery API for rasterarray
tilesets returns a GeoJSON FeatureCollection
of features at the geographic point described by {longitude},{latitude}
.
The Tilequery API response is ordered by the layer
and bands
parameters that are used to filter the resulting FeatureCollection
.
Each feature in the response body contains the following properties:
Property | Type | Description |
---|---|---|
type | string | This will always be Feature . |
id | string | This will always be null but exists to preserve the same response interface as the vector tilesets response. |
geometry.type | string | This will always be Point . The Tilequery API returns the value of the point at the requested {longitude},{latitude} when used against rasterarray tilesets. |
geometry.coordinates | array | The coordinates of the returned feature. |
properties | object | The properties of the feature. |
properties.tilequery.layer | string | The layer that the feature belongs to. |
properties.tilequery.band | string | The band that the feature belongs to. |
properties.tilequery.zoom | number | The maxzoom level of the tileset at which the point value was extracted from. |
properties.tilequery.units | string | The unit of measurement for the point value. |
properties.val | number | Point value at the requested {longitude},{latitude} . |
Example response
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"id": null,
"geometry": {
"type": "Point",
"coordinates": [133.3, 35.09]
},
"properties": {
"tilequery": {
"layer": "temperature",
"band": "1663516800",
"zoom": 5,
"units": "C"
},
"val": 24
}
},
{
"type": "Feature",
"id": null,
"geometry": {
"type": "Point",
"coordinates": [133.3, 35.09]
},
"properties": {
"tilequery": {
"layer": "temperature",
"band": "1663520400",
"zoom": 5,
"units": "C"
},
"val": 23.75
}
}
]
}
Supported libraries
Mapbox wrapper libraries help you integrate Mapbox APIs into your existing application. The following SDKs support this endpoint:
See the SDK documentation for details and examples of how to use the relevant methods to query this endpoint.
Tilequery API errors
Response body message | HTTP status code | Description |
---|---|---|
Empty FeatureCollection | 200 | If an empty FeatureCollection is returned, check whether the specified layer exists. |
Not Authorized - No Token | 401 | No token was used in the query. |
Not Authorized - Invalid Token | 401 | Check the access token you used in the query. |
Forbidden | 403 | There may be an issue with your account. Check your Account page for more details. In some cases, using an access tokens with URL restrictions can also result in a 403 error. For more information, see our Token management guide. |
Tileset {tileset name} does not exist | 404 | Check the name of the tileset you used in the query. |
Tile does not exist | 404 | The tile that intersects the specified {lon/lat} location does not exist in the queried tileset. Or, if the tileset was created by MTS but not successfully published, you will see this error. |
options.limit must be a number between 1 and 50 | 422 | The limit specified in the query is larger than 50 or contains non-numeric characters. |
Invalid {lon/lat} value: {value} | 422 | Check the latitude and longitude values you used in the query. |
options.geometry must be \"polygon\", \"linestring\", or \"point\" | 422 | The geometry parameter must be one of the options described in the Retrieve features from vector tiles section of this documentation. |
Tilequery API restrictions and limits
- The default rate limit for the Mapbox Tilequery API endpoint is 600 requests per minute. もし、レート制限をの数を高くしたい場合は、お問い合わせください。.
- If you exceed the rate limit, you will receive an
HTTP 429 Too Many Requests
response. For information on rate limit headers, see the Rate limit headers section. - Responses from the Tilequery API set default Cache-Control headers to
max-age=43200,s-maxage=300
, or a device cache TTL of 12 hours and a CDN cache TTL of 5 minutes. - If you composite multiple tileset IDs, the API request will have the cache time of the tileset with the highest
s-maxage
value. - For general information on caching, see the Maps APIs caching troubleshooting guide.
Tilequery API pricing
- requests ごとに請求されます
- 料金ページの Maps セクションで、Tilequery API request ごとの料金と割引をご確認ください。
Usage of the Tilequery API is measured in API requests. Each query for geographic features in one or more Mapbox-hosted tilesets at a given latitude and longitude will be counted as one Tilequery API request. Details about the number of Tilequery API requests included in the free tier and the cost per request beyond what is included in the free tier are available on the pricing page.