> ## 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.

# Generate Metes

> Generate the metes (compass bearing and distance) between consecutive points in a polygon.

This API endpoint generates the bearing (cardinal/compass direction) and distance (in meters)
between consecutive points in a supplied polygon (GeoJSON).

This endpoint is useful for rendering survey diagrams like this:

![metes and bounds COGO API](https://mintlify.s3-us-west-1.amazonaws.com/buntinglabs/coordinate-geometry-api/metes_and_bounds.jpeg)

### Request Parameters

<ParamField query="coordinates" type="array" required>
  A sequence of coordinates (single array of \[longitude, latitude] points) that will be used to generate
  the bearing and distance. Similar to the GeoJSON requirement, the coordinates must be closed
  (the first must equal the last).

  Because it is a single sequence ("ring"), it cannot have any holes and cannot be a `MultiPolygon`.
  It will have no properties.

  Providing at least 6 decimal places is recommended (approximately 11 cm precision). An example sequence of coordinates might look like this, in JSON:

  ```json
  {
    "coordinates": [
      [ -77.03787199, 38.89854538 ],
      [ -77.03784314, 38.89617453 ],
      [ -77.03680463, 38.89537525 ],
      [ -77.03571997, 38.89560426 ],
      [ -77.03521802, 38.89639905 ],
      [ -77.03520648, 38.89854538 ],
      [ -77.03787199, 38.89854538 ]
    ]
  }
  ```
</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>

### Response

When features are successfully counted, a 200 OK response will be
issued, with `Content-Type: application/json`. The body will be a FeatureCollection
of GeoJSON LineStrings, where each LineString represents a line from the polygon.

Each LineString belongs to a Feature which will have the properties `bearing_sexagesimal`,
`true_bearing_degrees`, and `distance_meters`.

<ResponseField name="distance_meters" type="float">
  The distance along this line, in meters.
</ResponseField>

<ResponseField name="true_bearing_degrees" type="float">
  This represents the [bearing (or azimuth) of the line](https://en.wikipedia.org/wiki/Bearing_\(angle\)).
  This bearing is calculated from true north and has values 0°-360°, where 0° is due north and
  90° is due east.
</ResponseField>

<ResponseField name="bearing_sexagesimal" type="string">
  This is a string formatting of `true_bearing_degrees` that surveyors typically use. It
  designates the north/south cardinal direction in which to travel and the angle from which
  one should deviate.

  For example, `N 21° 25' 15″ E` is equivalent to true bearing `21.42`. This is sexagesimal (base-60),
  hence 25/60 \~ 0.42.
</ResponseField>

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>

<RequestExample>
  ```bash Example Request
  curl --request POST \
       --url https://osm.buntinglabs.com/v1/cogo/generate-metes \
       --header "Content-Type: application/json" \
       --data '{
       "api_key": "demo",
       "coordinates": [[-77.037871,38.898545],[-77.037843,38.896174],[-77.036804,38.895375],[-77.035206,38.898545],[-77.037871,38.898545]]
  }'
  ```
</RequestExample>

<ResponseExample>
  ```json Response
  {
    "type": "FeatureCollection",
    "features": [{
      "type": "Feature",
      "properties": {
        "bearing_sexagesimal": "S 0° 31' 35″ E",
        "distance_meters": 263.224,
        "true_bearing_degrees": 179.473
      },
      "geometry": {
        "coordinates": [
          [ -77.037871, 38.898545 ],
          [ -77.037843, 38.896174 ]
        ],
        "type": "LineString"
      }
    }]
  }
  ```
</ResponseExample>
