2016-06-07 32 views
5

使用MongoDB 3.2我試圖對點的集合使用2dsphere查詢。

可以說我有一個集合cust_5_abcd與2dsphere指數the_geom場。

集合中添加一個幾何:

db.cust_5_abcd.insert({ 
"chps0" : "Texte d'une ligne", 
"the_geom" : { 
    "type" : "Point", 
    "coordinates" : [ 
     1.032715, 
     40.380028 
    ] 
}}) 

現在我想查詢使用$ geoWithin獲取特定的多邊形內部的所有數據這一點。這是我得到不同的結果,如果我使用$幾何與GeoJSON定義,或與$多邊形和嚴格的座標。也許文件中的某些內容丟失或者我誤解了。

隨着$幾何沒有給出結果:

db.cust_5_abcd.find( { the_geom: 
{ $geoWithin: 
     { $geometry: 
      {  
       "type": "Polygon", 
       "coordinates": [ 
        [ 
         [ -16.237793, 40.162083 ], 
         [ -16.237793, 51.835778 ], 
         [ -13.776855, 51.835778 ], 
         [ -13.776855, 41.426253 ], 
         [ 14.765625, 41.426253 ], 
         [ 14.765625, 40.162083 ], 
         [ -16.237793, 40.162083 ] 
       ] 
       ] 
      } 
     } 
    } 
}) 

隨着$多邊形返回我的觀點:

db.cust_5_abcd.find({ the_geom: 
{ $geoWithin: 
     { $polygon: 
        [ 
         [ -16.237793, 40.162083 ], 
         [ -16.237793, 51.835778 ], 
         [ -13.776855, 51.835778 ], 
         [ -13.776855, 41.426253 ], 
         [ 14.765625, 41.426253 ], 
         [ 14.765625, 40.162083 ], 
         [ -16.237793, 40.162083 ] 
       ]     
     } 
    } 
}) 
+0

這有點奇怪,特別是query.explain(「executionStats」)顯示第一個查詢使用索引(如果已創建),另一個不是... – profesor79

回答

0

得到了MongoDB的人的答案:https://jira.mongodb.org/browse/SERVER-24549?focusedCommentId=1293398&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-1293398

使用$時多邊形會計算平面幾何圖形,並且該點落在您描述的多邊形內。但是,當你使用一個GeoJSON的球面幾何學被使用,並且點落在幾何

外面現在的問題是,我無法使用$多邊形上$ geoIntersect用於爲例或與其他幾何形狀,然後多邊形。

相關問題