outside2344
outside2344

Reputation: 2105

Spatial Indexes with DocumentDB

I’m trying to do a spatial query against DocumentDB that looks like this:

SELECT * FROM root r WHERE 
   ST_WITHIN({'type':'Point','coordinates':[-122.02625, 37.4718]}, r.boundingBox)

to match a document that looks like this in the collection:

{
 "userId": "747941cfb829",
 "id": "747941cfb829_1453640096710",
 "boundingBox": {
   "type": "Polygon",
   "coordinates": [
     [-122.0263, 37.9718],
     [-122.0262, 37.9718],
     [-122.0262, 36.9718],
     [-122.0263, 36.9718],
     [-122.0263, 37.9718]
   ]
 },
 "distance": 0,
 "duration": 1
}

I’ve turned on spatial indexes ala https://azure.microsoft.com/en-us/documentation/articles/documentdb-geospatial/ but I’m not getting a match back from DocumentDB.

Any ideas?

NOTE: Corrected GeoJson coordinate order.

Upvotes: 1

Views: 394

Answers (1)

Larry Maccherone
Larry Maccherone

Reputation: 9523

The correct specification of a GeoJSON polygon has an additional array around the coordinates than you show to allow for the possibility of holes and multipolygons. So, it would look like this:

{
  "type": "Polygon",
  "coordinates": [
    [
      [0, 0], [10, 10], [10, 0], [0, 0]
    ]
  ]
}

Upvotes: 2

Related Questions