DocumentDB:ST_DISTANCE函数不适用于'<' (小于)符号 [英] DocumentDB: ST_DISTANCE function does not work with '<' (smaller than) sign
问题描述
我有一个工作正常的查询,如下所示:
I have a perfectly working query that looks as follows:
从位置p WHERE ST_DISTANCE(p.geometry,{'type':'Point','coordinates':[52.0826443333333,5.11771783333333]})> 6000中选择p.id>
SELECT p.id FROM place p WHERE ST_DISTANCE(p.geometry, {'type': 'Point', 'coordinates':[52.0826443333333, 5.11771783333333]} ) > 6000
它返回距离地理空间点超过6000 m的文档ID的列表.一切似乎都很好.但是,如果我将>"(大于)符号转为<" (小于),则不会产生任何结果.有趣的是,如果我将WHERE子句放在SELECT语句中,它的确会返回false/true语句,如下所示:
It returns a list of id's of documents that are more than 6000 m from the geospatial point. Everything seems fine. However, if I turn around the '>' (greater than) sign to '<' (smaller than), it does not give any result. Interestingly, it does return false/true statements if I put the WHERE clause in a SELECT statement, as follows:
SELECT ST_DISTANCE(p.geometry,{'type':'Point','coordinates':[52.0826443333333,5.11771783333333]})<来自位置p
SELECT ST_DISTANCE(p.geometry, {'type': 'Point', 'coordinates':[52.0826443333333, 5.11771783333333]}) < 6000 AS result FROM place p
它会按预期生成true和false语句.因此,评估似乎可行,但未返回任何输出.当前,我只是使用后一种解决方法,并选择计算出的距离.但是现在我必须计算其他地方(例如在客户端或存储过程中)一定距离内的点.
It generates both true and false statements as expected. So the evaluation seems to work, but it does not return any output. Currently, I just use this latter work around, and also select the computed distances. But now I have to compute the points that are within a certain distance somewhere else (like on the client side or in a stored procedure).
更新 我使用指定的索引策略进行了测试(多亏了这个示例):
UPDATE I tested with a specified index policy (thanks to this example):
'indexingPolicy':{'includedPaths':[{'path':'/"geometry"/?','indexes':[{'kind':'Spatial','dataType':'LineString'}] },{'path':'/'}]}
'indexingPolicy': {'includedPaths': [{'path': '/"geometry"/?', 'indexes': [ {'kind': 'Spatial', 'dataType': 'LineString'}]}, {'path': '/'}]}
这解决了问题.我仍然认为,空间函数确实在大于"而不是小于"上起作用是很奇怪的,但是我认为这是可以解决的.
And that solved the problem. I still think it is odd that the spatial function did work on 'greater than' and not on 'smaller than', but I think it is solved with this.
推荐答案
您应在该字段上指定一个Spatial
索引,如下所示:
You should specify a Spatial
index on that field like this:
'indexingPolicy': {
'includedPaths': [
{
'path': '/"geometry"/?',
'indexes': [
{'kind': 'Spatial', 'dataType': 'LineString'}
]
},
{'path': '/'}
]
}
这篇关于DocumentDB:ST_DISTANCE函数不适用于'<' (小于)符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!