[英]mongodb $geointersects not working
我試圖在mongodb
使用$geointersects
來找到該點所在的多邊形。
對於在php
我創建的測試數據:
$collection = $db->selectCollection('countries');
$result = $collection->insertMany([
[
'c' => 'rus',
'n' => 'Russia',
'loc' => [
"type" => "Polygon",
"coordinates" => [
[-109.95117, 39.77477],
[-100.23926, 46.70974],
[-94.41608, 37.78902],
[-104.67541, 32.70375],
[-109.95117, 39.77477]
]
]
],[
'c' => 'can',
'n' => 'Canada',
'loc' => [
"type" => "Polygon",
"coordinates" => [
[-100.15137, 46.83013],
[-84.31555, 47.89965],
[-82.39746, 37.78808],
[-94.28467, 37.8228 ],
[-100.15137, 46.83013]
]
]
]
]);
結果是:
然后在Robomongo
進行選擇:
db.getCollection('countries')。find({“ loc”:{$ geoIntersects:{$ geometry:{“ type”:“ Point”,“ coordinates”:[-88.0123388,41.8333926]}}}}))
並且沒有返回任何行! 這里可能有什么問題?
外殼相同:
這是我要測試的多邊形:
這是點(41.8333926,-88.0123388)的位置 :
使用最新版本的mongodb:3.2.9。
答案是坐標的結構不正確。 我想創建一個索引,但是失敗了。這就是發現它的方式。
正確的數組:
"coordinates" => [[
[-109.95117, 39.77477],
[-100.23926, 46.70974],
[-94.41608, 37.78902],
[-104.67541, 32.70375],
[-109.95117, 39.77477]
]]
因此,在我最初的問題中,我對應該是多邊形的東西提出了要點。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.