API version: 0.3.0

---

# GeoJSON

[GeoJSON](https://en.wikipedia.org/wiki/GeoJSON), defined in [RFC 7946](https://datatracker.ietf.org/doc/html/rfc7946),
is the format of geo values in Ember Nexus. Requests can also send them as
[WKT](https://en.wikipedia.org/wiki/Well-known_text_representation_of_geometry) (well-known text), and responses can
return WKT on request. Internally, geometries are stored in one format and converted when a response is written.

Geo values are only recognized for properties which the [schema](/reference/schemas.md) defines with one of the geo types.
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.

## Supported geometries

| Schema type                                                      | GeoJSON           | WKT example                                                     |
| ---------------------------------------------------------------- | ----------------- | --------------------------------------------------------------- |
| [`point`](/reference/schemas/types/point.md)                     | `Point`           | `POINT (13.4 52.5)`                                             |
| [`linestring`](/reference/schemas/types/linestring.md)           | `LineString`      | `LINESTRING (0 0, 1 1)`                                         |
| [`polygon`](/reference/schemas/types/polygon.md)                 | `Polygon`         | `POLYGON ((0 0, 10 0, 10 10, 0 0))`                             |
| [`multipoint`](/reference/schemas/types/multipoint.md)           | `MultiPoint`      | `MULTIPOINT ((0 0), (1 1))`                                     |
| [`multilinestring`](/reference/schemas/types/multilinestring.md) | `MultiLineString` | `MULTILINESTRING ((0 0, 1 1), (2 2, 3 3))`                      |
| [`multipolygon`](/reference/schemas/types/multipolygon.md)       | `MultiPolygon`    | `MULTIPOLYGON (((0 0, 1 0, 1 1, 0 0)), ((5 5, 6 5, 6 6, 5 5)))` |

`GeometryCollection` and `Feature` objects are not supported, store each geometry in its own property instead.

Positions are `[longitude, latitude]`, or `[longitude, latitude, altitude]` for properties with `"dimensions": 3`, in
WGS 84. Longitudes range from -180 to 180 and latitudes from -90 to 90. Rings of polygons have to be closed: their last
position equals the first one. The values are checked for their structure and these ranges, not for e.g.
self-intersections.

## WKT

WKT is accepted as input for every geo property, whatever format the responses use. It is the compact format for
ingesting data, e.g. from a spatial database or a CSV export, and may also be used for queries in the future.

- Keywords are case-insensitive, and the `Z` marker is optional for positions with three coordinates:
  `POINT Z (13.4 52.5 34)` equals `POINT (13.4 52.5 34)`.
- An `SRID=4326;` prefix is accepted, other reference systems are rejected.
- `MULTIPOINT` accepts positions with and without their own parentheses: `MULTIPOINT ((0 0), (1 1))` and
  `MULTIPOINT (0 0, 1 1)`.
- `EMPTY` geometries are not supported.

```json
{
  "type": "Place",
  "data": {
    "location": "POINT (13.4 52.5)"
  }
}
```

## Response format

Responses contain GeoJSON by default. Requests can ask for WKT with the `Prefer` header of
[RFC 7240](https://datatracker.ietf.org/doc/html/rfc7240):

```http
GET /<uuid>
Prefer: geometry=wkt
```

| Preference         | Geo values in the response |
| ------------------ | -------------------------- |
| none               | GeoJSON                    |
| `geometry=geojson` | GeoJSON                    |
| `geometry=wkt`     | WKT strings                |

The preference applies to the whole response, every geo value of every element has the same format. Responses which
honored a preference carry `Preference-Applied: geometry=wkt` (or `geometry=geojson`), unknown preferences and values
are ignored. Responses vary by the header, so they carry `Vary: Prefer`.

The preference is supported by [`GET /<uuid>`](/api/get-element.md), the collections [`GET /`](/api/get-index.md),
[`GET /<uuid>/children`](/api/get-children.md), [`GET /<uuid>/parents`](/api/get-parents.md) and
[`GET /<uuid>/related`](/api/get-related.md), and the [element hydration](/reference/search/element-hydration.md) step of
[`POST /search`](/api/post-search.md) and [`POST /search/<uuid>`](/api/post-saved-search.md). Other search steps work with the
internal format.

The `ETag` of a response in another format than GeoJSON gets the name of the format appended: an element whose `ETag` is
`"abcdefg"` has the `ETag` `"abcdefg-wkt"` in WKT responses, on every endpoint above, whether the element has geo values
or not. `If-None-Match` and `If-Match` accept both forms, see
[caching and conditional requests](/guide/caching-and-conditional-requests.md).

## Expressions

[Schema rules](/reference/schemas/rules.md), search expressions and the
[playground](/reference/formats-and-languages/expr-lang/playground.md) see geo values as GeoJSON, whatever format the
request used. The [geo functions](/reference/formats-and-languages/expr-lang/geo-functions.md) of Expr create, convert,
measure and compare them, e.g. `geoContains(document.area, document.location)` or `geoFromWkt('POINT (13.4 52.5)')`.
They check geometries more strictly than writes do: self-intersecting rings, for example, are stored, but fail the geo
functions.

---

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

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

Previous: [Formats and languages](/reference/formats-and-languages.md)

Next: [Expr Lang](/reference/formats-and-languages/expr-lang.md)
