Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to store and query Array Spatial Data in CosmosDB?

Here is a sample document that we would like to store:


{
  "name": "Joe Bloggs",
   "locations": [
        { "type": "Point", "coordinates": [1,1] },
        { "type": "Point", "coordinates": [2,2] }
   ]
}

The key feature of the document is that the "locations" property is an array of GeoJSON points.

According to the documentation it is possible to define an indexing policy for the locations array.

However, it's not clear whether spatial queries such as ST_WITHIN can be used to search, for example, whether any of the points in the array fall within a certain radius of a specified point.

My question: Does CosmosDB support indexing and querying of spatial data when stored in an array?

like image 759
Noel Abrahams Avatar asked Nov 08 '22 14:11

Noel Abrahams


1 Answers

From private conversation with CosmosDB:

Can it be indexed?

yes, you just need to index /locations/[]/? or /locations/*

Can it be queried?

yes, you can query over an array of points by using a JOIN to unwind the array.

SELECT * FROM c JOIN loc IN c.locations WHERE ST_DISTANCE(loc, @myLocation) < @distance

like image 152
Noel Abrahams Avatar answered Nov 27 '22 16:11

Noel Abrahams