2016-09-20 9 views
0

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] 
      ] 
     ] 
    ] 
]); 

結果は次のとおりです。

デシベル:

enter image description here

はその後Robomongoに私が選択を作っています。 getCollection( 'countries')。find({"loc":{$ geoIntersects: {$ジオメトリ:{ "タイプ": "ポイント"、 "座標":[-88.、41.8333926 ]}}}})

enter image description here

そして何行が返されません!ここで何が問題になるのでしょうか?シェルで

同じ:ここ

enter image description here

が、私は反対テストしていたポリゴンです:

:ここ

enter image description here

はポイント(41.8333926、-88.)locationです

enter image description here

mongodbの最新バージョンを使用しています:3.2.9。

答えて

0

答えは、座標構造が正しくないということです。私はインデックスを作成したかったが失敗した。これがどのように見つかったのか。

正しい配列:私はポリゴンすることになって何にポイントを置き、私の元の質問ではそのため

"coordinates" => [[ 
       [-109.95117, 39.77477], 
       [-100.23926, 46.70974], 
       [-94.41608, 37.78902], 
       [-104.67541, 32.70375], 
       [-109.95117, 39.77477] 
      ]]