Skip to content
GuidesBlogPlaygroundDashboard

Fetch multiple features by type and ID

elements().batch(ElementBatchParamsparams, RequestOptionsrequestOptions = RequestOptions.none()) : FeatureCollection
POST/api/v1/features/batch

Fetch multiple features by type and ID

ParametersExpand Collapse
params: ElementBatchParams
batchRequest: BatchRequest

Fetch multiple OSM elements by their type and ID in a single request. Maximum 100 elements per batch.

ReturnsExpand Collapse
class FeatureCollection:

GeoJSON FeatureCollection (RFC 7946). For paginated endpoints, metadata is returned in HTTP response headers rather than the body:

Header Description
X-Limit Requested result limit
X-Has-More true if more results exist
X-Next-Cursor Opaque cursor for next page (cursor pagination)
X-Next-Offset Numeric offset for next page (offset pagination)
Link RFC 8288 rel="next" link to the next page

Content-Type is application/geo+json.

features: List<GeoJsonFeature>

Array of GeoJSON Feature objects

geometry: GeoJsonGeometry

GeoJSON Geometry object per RFC 7946. Coordinates use [longitude, latitude] order. 3D coordinates [lng, lat, elevation] are used for elevation endpoints.

coordinates: Coordinates

Coordinates array. Nesting depth varies by geometry type: Point = [lng, lat], LineString = [[lng, lat], ...], Polygon = [[[lng, lat], ...], ...], etc.

One of the following:
List<Double>
List<List<Double>>
List<List<List<Double>>>
List<List<List<List<Double>>>>
type: Type

Geometry type

One of the following:
POINT("Point")
LINE_STRING("LineString")
POLYGON("Polygon")
MULTI_POINT("MultiPoint")
MULTI_LINE_STRING("MultiLineString")
MULTI_POLYGON("MultiPolygon")
properties: Properties

OSM tags flattened as key-value pairs, plus @type (node/way/relation) and @id (OSM ID) metadata fields. May include distance_m for proximity queries.

type: Type

Always Feature

id: Optional<String>

Compound identifier in type/osm_id format

type: Type

Always FeatureCollection

Fetch multiple features by type and ID

package com.plazafyi.example

import com.plazafyi.client.PlazaClient
import com.plazafyi.client.okhttp.PlazaOkHttpClient
import com.plazafyi.models.FeatureCollection
import com.plazafyi.models.elements.BatchRequest
import com.plazafyi.models.elements.ElementBatchParams

fun main() {
    val client: PlazaClient = PlazaOkHttpClient.fromEnv()

    val params: BatchRequest = BatchRequest.builder()
        .addElement(BatchRequest.Element.builder()
            .id(21154906L)
            .type(BatchRequest.Element.Type.NODE)
            .build())
        .addElement(BatchRequest.Element.builder()
            .id(4589123L)
            .type(BatchRequest.Element.Type.WAY)
            .build())
        .build()
    val featureCollection: FeatureCollection = client.elements().batch(params)
}
{
  "features": [
    {
      "geometry": {
        "coordinates": [
          2.3522,
          48.8566
        ],
        "type": "Point"
      },
      "properties": {
        "@id": "bar",
        "@type": "bar",
        "amenity": "bar",
        "cuisine": "bar",
        "name": "bar"
      },
      "type": "Feature",
      "id": "node/21154906"
    }
  ],
  "type": "FeatureCollection"
}
Returns Examples
{
  "features": [
    {
      "geometry": {
        "coordinates": [
          2.3522,
          48.8566
        ],
        "type": "Point"
      },
      "properties": {
        "@id": "bar",
        "@type": "bar",
        "amenity": "bar",
        "cuisine": "bar",
        "name": "bar"
      },
      "type": "Feature",
      "id": "node/21154906"
    }
  ],
  "type": "FeatureCollection"
}