PyMongo/MongoDB源站和目的地LatLon的地理空间查询

2024-09-27 21:32:39 发布

您现在位置:Python中文网/ 问答频道 /正文

在Python中使用PyMongo,我试图在一个设置的半径内对源LatLon和目的LatLon执行地理空间查询,并打印第一个结果。下面是我想的,但是我得到了一个错误。正确的做法是什么?在

代码:

origin = [float(44.8697193), float(13.8414046)]
dest = [float(48.1367203), float(11.576754)]
query = db.collection.find({'origLatLng': {'$within': {'$center': [origin,.75]}}}, {'destLatLng': {'$within': {'$center': [dest,.75]}}})[0]
print query

错误:

^{pr2}$

不要在没有目标的情况下搜索目标。我做错什么了?在


Tags: 目的目标错误半径空间originfloatquery
2条回答

不确定您正在使用的实际MongoDB版本,但是$within已被弃用,现在您应该使用$geoWithin

http://docs.mongodb.org/manual/reference/operator/geoWithin/

另请参阅上面的链接了解更多选项。我不是Python的专家,但我希望$geoWithin能解决您的问题。在

我觉得你的语法有问题。实际上有两个查询文档,一个用于origLatLng,另一个用于destLatLng。我想你的意思是:

query = db.collection.find({'start': {'$within': {'$center': [origin,.75]}}, 'end': {'$within': {'$center': [dest,.75]}}})[0]

您的第二个查询文档被解释为执行一个投影,这就是为什么使用“Unsupported projection option:$within”的操作失败的原因。在

相关问题 更多 >

    热门问题