> ## Documentation Index
> Fetch the complete documentation index at: https://docs.buntinglabs.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Extract Features

> This endpoint downloads features from OpenStreetMap based on tags and optionally a bounding box, resulting in a GeoJSON.

This API extracts features from the OpenStreetMap database and formats them as GeoJSON.

You can filter for any tag in the [database](https://taginfo.openstreetmap.org/), either as `key=value`
or `key=*`, and can chain tags if you need 2+ tags.

This endpoint is especially useful for extracting map data directly to user applications (like the browser)
or as a faster alternative to [Overpass Turbo](http://overpass-turbo.eu/) and the [Overpass API](http://overpass-api.de/).

### Request Parameters

<ParamField query="tags" type="string" placeholder="leisure=park" required>
  This is a list of tags in the form `key=value` to filter features for.
  All features extracted will satisfy each of the passed tags given by this parameter.

  This tag list can be created by forming an array of `key=value` items and joining
  them into one string with the `&` character.

  Because both `=` and `&` are reserved characters in URIs, this list must be URL encoded.

  An example list of tags could be `leisure=park` and `name=Westglen Park`. This matches parks
  that have the name Westglen Park. To set this parameter,
  we'll URL encode `leisure=park&name=Westglen Park`.

  Documentation on tags can be found on the [TagInfo](https://taginfo.openstreetmap.org) resource website.
</ParamField>

<ParamField query="bbox" type="string" default="None" placeholder="-97.45,37.59,-97.22,37.76">
  This is the bounding box for extracted features. The coordinates (in EPSG:4326) of
  the bounding box are required to be in (minimum longitude, minimum latitude,
  maximum longitude, maximum latitude) order. Coordinates are expressed as signed floats
  joined by commas.

  An example bounding box in the US could be `-108.984375,32.026706,-103.051758,37.195331`.

  You can create a bounding box [on bboxfinder](http://bboxfinder.com), or in shapely by
  invoking the `bounds` property on a geometry.

  <Tip>To filter based on a `Polygon` or `MultiPolygon` instead, use our endpoint for [downloading OSM features inside a polygon](/openstreetmap-api/extract-within-geometry).</Tip>
</ParamField>

<ParamField query="api_key" type="string" placeholder="demo" required>
  Your account's API key. You can create an API key by
  [registering for an account](https://buntinglabs.com/account/register)
  and copy and paste it from your [account dashboard](https://buntinglabs.com/dashboard).
</ParamField>

<ParamField query="simplify" type="string">
  This optional parameter, when passed, simplifies the output
  geometries. The only valid value is `simplify=point`, which turns
  every output geometry into a single point (its centroid).

  This is convenient for approximating LineStrings and MultiPolygons as their
  central point.

  Note the centroid may fall outside the original polygon, e.g. a donut's
  centroid is outside the ring.
</ParamField>

### Response

When the OSM feature extract is successfully created, a 200 OK response will be
issued, with `Content-Type: application/json`. The body will be a valid [GeoJSON
FeatureCollection](https://geojson.org/).

In the event of an error, an error response will be issued, usually with a 5xx error code.
The error will be JSON-formatted, with an `error` field describing the cause.

<ResponseField name="error" type="string">
  The error message if the extract request parameters were incorrectly formatted.

  This response field will not be present if the extract succeeds.
</ResponseField>

### Data License

This API serves [OpenStreetMap](https://www.openstreetmap.org/) data, which is
freely available and is licensed under the
[Open Data Commons Open Database License (ODbL)](https://www.openstreetmap.org/copyright).

<RequestExample>
  ```bash cURL
  curl --get 'https://osm.buntinglabs.com/v1/osm/extract' \
       --data "tags=aeroway%3Drunway" \
       --data "api_key=demo" \
       --data "bbox=-112.162,40.459,-111.791,40.876"
  ```

  ```javascript JavaScript
  const params = new URLSearchParams({
    tags: "aeroway=runway",
    api_key: "demo",
    bbox: "-112.162,40.459,-111.791,40.876"
  });

  fetch(`https://osm.buntinglabs.com/v1/osm/extract?${params}`)
    .then(response => response.json())
    .then(data => console.log(data));
  ```

  ```python Python
  import requests

  params = {
    "tags": "aeroway=runway",
    "api_key": "demo",
    "bbox": "-112.162,40.459,-111.791,40.876"
  }

  response = requests.get("https://osm.buntinglabs.com/v1/osm/extract", params=params)
  print(response.json())
  ```
</RequestExample>

<ResponseExample>
  ```json Response
  {
    "type": "FeatureCollection",
    "features": [{
      "type": "Feature",
      "properties": {
        "aeroway": "runway"
      },
      "geometry": {
        "type": "MultiPolygon",
        "coordinates": [[[
          [-111.9623558, 40.7735137],
          [-111.9618135, 40.7735137],
          [-111.9618012, 40.7988855],
          [-111.9623435, 40.7989041],
          [-111.9623558, 40.7735137]
        ]]]
      }
    }]
  }
  ```
</ResponseExample>
