Introduction

Sometimes, we might need to store shapes, locations, or other spatial data and perform queries on them. Cosmos DB natively supports this kind of data following the GeoJSON specification.

Representations

Spatial types can be indexed in two different ways. It’s a setting on the container level, changing what the data represents and how queries perform calculations on it.

  • Geometrical: Data belongs to a flat (Euclidean) coordinate system.

  • Geographical: Data belongs to an earth coordinate system. Since the planet is not regular, data is represented on the WGS-84 coordinate reference systems (CRS). Altitude and other elements are considered during queries but are still approximated.

    • Longitude: ± 180 degrees from the prime meridian.

    • Latitude: ± 90 degrees from the equator.

Data types

There are four different types of spatial data we can use:

  • Point

  • LineString

  • Polygon

  • MultiPolygon

Point

It’s self-explanatory and represents an XY coordinate or longitude and latitude. We can use it, for example, to store the location of buildings.

Get hands-on with 1400+ tech skills courses.