Tilequery API | API Docs (original) (raw)

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

Retrieve features from a tileset

get

https://api.mapbox.com

/v4/{tileset_id}/tilequery/{lon},{lat}.json

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 25 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

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: Original geometry of featureResult polygonIf the query point is within the polygon, the result will be the query point location. If the query point is outside the polygon, the result is the interpolated closest point along the nearest edge of the feature within the radius threshold.linestringThe result is the interpolated closest point along the feature within the radius threshold.pointThe result is the nearest point within the radius threshold.
properties.tilequery.layer string The vector tile layer of the feature result.

Example response

Retrieve features from rasterarray tilesets

Example requests

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

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

Tilequery API pricing

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.

Additional Developer Resources