API version: 0.3.0

---

# Polygon

`polygon` holds a [GeoJSON](/reference/formats-and-languages/geojson.md) `Polygon`, an area, a closed outer ring and
optionally holes. Values can be written as GeoJSON or as [WKT](/reference/formats-and-languages/geojson.md#wkt) and are
stored in one internal format. Responses contain GeoJSON, or WKT if the request asks for it with `Prefer: geometry=wkt`,
see [GeoJSON](/reference/formats-and-languages/geojson.md#response-format).

```json geo-map
{
  "type": "Polygon",
  "coordinates": [
    [
      [
        13,
        52.3
      ],
      [
        13.8,
        52.3
      ],
      [
        13.8,
        52.7
      ],
      [
        13,
        52.7
      ],
      [
        13,
        52.3
      ]
    ]
  ]
}
```

**Note**: geo values are only recognized for properties which the schema defines as `polygon`. Without a definition, a
GeoJSON object is stored as a plain object and a WKT string as a plain string, without validation, conversion or geo
index.

## Expressions

[Schema rules](/reference/schemas/rules.md) and search expressions see values of this type as GeoJSON, also if they were
written as WKT. The [geo functions](/reference/formats-and-languages/expr-lang/geo-functions.md) work on them: `geoArea(document.area)` measures the area in square meters, `geoContains(document.area, document.location)` checks whether a point lies inside.

## Settings

| Setting      | Meaning                                                                                                                                            |
| ------------ | -------------------------------------------------------------------------------------------------------------------------------------------------- |
| `dimensions` | `2` (default) for `[longitude, latitude]`, `3` for `[longitude, latitude, altitude]`. Every position of a value has to have this many coordinates. |

The [settings of every property](/reference/schemas.md#properties) apply as well.

## Storage

| Database      | Stored as      | Notes                                                                                    |
| ------------- | -------------- | ---------------------------------------------------------------------------------------- |
| MongoDB       | GeoJSON object | (default), with a `2dsphere` index for the intent `geo`                                  |
| Neo4j         | not supported  | Neo4j has no native type for it, `"storage": "graph"` is rejected with `400 Bad Request` |
| Elasticsearch | `geo_shape`    | search copy                                                                              |

The [search copy](/reference/databases/elasticsearch.md) is written unless the property or the type sets `"search": false`.
Where a property is stored is explained in [placement](/reference/schemas/placement.md).

## Indices

`geo`, see [geo indices](/reference/indices/geo.md).

## Limits

Positions are `[longitude, latitude]` in WGS 84 (longitude -180 to 180, latitude -90 to 90), longitude first, unlike
most map UIs, which show latitude first. Every ring of a polygon needs at least four positions and has to be closed: the
last position equals the first one. Neo4j only stores points, see above. MongoDB documents are limited to 16 MB, which
limits the number of positions, see [MongoDB](/reference/databases/mongodb.md).

## Example

Schema:

```json
{
  "type": "polygon",
  "index": "geo"
}
```

| Format  | Input                                                                                                          | Output                                                                                                                      |
| ------- | -------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- |
| GeoJSON | `{"type": "Polygon", "coordinates": [[[13.0, 52.3], [13.8, 52.3], [13.8, 52.7], [13.0, 52.7], [13.0, 52.3]]]}` | `{"type": "Polygon", "coordinates": [[[13.0, 52.3], [13.8, 52.3], [13.8, 52.7], [13.0, 52.7], [13.0, 52.3]]]}`, the default |
| WKT     | `"POLYGON ((13 52.3, 13.8 52.3, 13.8 52.7, 13 52.7, 13 52.3))"`                                                | `"POLYGON ((13 52.3, 13.8 52.3, 13.8 52.7, 13 52.7, 13 52.3))"` with `Prefer: geometry=wkt`                                 |

---

Home: [Ember Nexus API docs](/index.md)

Full site map: [llms.txt](/llms.txt)

Previous: [LineString](/reference/schemas/types/linestring.md)

Next: [MultiPoint](/reference/schemas/types/multipoint.md)
