me--
me--

Reputation: 2148

Simple ST_WITHIN query returning no results

I'm trying to get my head around Cosmos DB's ST_WITHIN function. I started out with something fairly complex but have had to whittle it down to something that I'm certain should work but doesn't.

Consider:

SELECT ST_WITHIN({ 'type': 'Point', 'coordinates': [ 0, 0 ] }, {'type':'Polygon','coordinates':[[[-150, -50], [-150, 50], [150, 50]]]}) FROM c

Why does this return an empty object for every record in c? That is, for 3 items in c, the results look like this:

[
    {},
    {},
    {}
]

At the very least, I would expect it to return false for every object rather than...nothing. But actually in this case I'd expect it to return true, since the point provided is within the polygon.

I expect I'm doing something quite obviously wrong, but I can't figure out what. I've already tried enabling Point, Line, and Polygon indexes on the collection to no avail.

Does anyone have any suggestions?

Upvotes: 2

Views: 300

Answers (1)

Jay Gong
Jay Gong

Reputation: 23782

Ok, i reproduced your issue on my side,please see the statement in the official document.

Similar to how mismatched types work in Azure Cosmos DB query, if the location value specified in either argument is malformed or invalid, then it evaluates to undefined and the evaluated document to be skipped from the query results. If your query returns no results, run ST_ISVALIDDETAILED To debug why the spatial type is invalid.

Then you could check the reason that Each ring of a polygon must contain at least four points with ST_ISVALIDDETAILED method.

enter image description here

Upvotes: 1

Related Questions