0

ST_WITHIN is not giving results, always return zero records.

here is the example:

select *
FROM Areas a
WHERE ST_WITHIN({'type': 'Point', 'coordinates':[31.9, -4.8]}, a.location)

Expecting above query should return one record.

my database entries are

{
  "id": "MyDesignatedLocation",
  "location": {
    "type": "Polygon",
    "coordinates": [
      [
        [
          31.8,
          -5
        ],
        [
          32,
          -5
        ],
        [
          32,
          -4.7
        ],
        [
          31.8,
          -4.7
        ],
        [
          31.8,
          -5
        ]
      ]
    ]
  }
}

1 Answer 1

1

By default, DocumentDB returns results only for path-data type combinations that are indexed. Based on your description, it looks like you do not have Polygons included for Spatial indexing (in projection, the results will be returned via scans).

In order to get results back, please change the indexing policy to include Spatial index on the Polygon data type (See sample indexing policy below). More details here: https://azure.microsoft.com/en-us/documentation/articles/documentdb-geospatial/

{    
   "automatic":true,
   "indexingMode":"Consistent",
   "includedPaths":[
      {
         "path":"/*",
         "indexes":[
            {
               "kind":"Range",
               "dataType":"String",
               "precision":-1
            },
            {
               "kind":"Range",
               "dataType":"Number",
               "precision":-1
            },
            {
               "kind":"Spatial",
               "dataType":"Point"
            },
            {
               "kind":"Spatial",
               "dataType":"Polygon"
            }                
         ]
      }
   ],
   "excludedPaths":[
   ]
}
Sign up to request clarification or add additional context in comments.

3 Comments

For some reason it didn't save indexing policy. Above example is working fine. I am trying below coordinates but it's returning empty records. jsoneditoronline.org/?id=fee820b236ba62089566603fcfe20c7a here is the query SELECT * FROM c where ST_WITHIN({'type':'Point', 'coordinates': [81.136727, 16.188537]}, c.boundary)
@Siva - Please don't post additional issues / queries in comments. Instead, please edit your question. Otherwise, questions end up getting hidden within answers (so, they're less visible, and also disappear if the answer is ever removed). Also risks turning the comments area into a discussion (and this is an unsupported communication model).
It's working fine i figured out coordinates should be counterclockwise.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.