MongoDB - 使用$ polygon或$ geometry的$ geoWithin查询给出不同的结果

时间:2016-06-07 10:27:06

标签: mongodb

使用MongoDB 3.2我试图在Points集合上使用2dsphere查询。

假设我在 the_geom 字段中使用了 the_geom 字段,并在 the_geom 字段中添加了 cust_5_abcd

在集合中添加几何图形:

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

现在我正在尝试使用$ geoWithin查询此Point以获取特定Polygon中的所有数据。如果我使用 $ geometry 和GeoJSON定义,或者使用 $ polygon 和严格的坐标,我会得到不同的结果。也许文档中的某些内容缺失或者我误解了。

$ geometry 没有结果:

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

使用 $ polygon 返回我的Point:

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

1 个答案:

答案 0 :(得分:1)

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

  

使用$ polygon时,会计算平面几何体,并且该点落在您描述的多边形内。但是当你使用GeoJSON时,会使用球面几何体,并且该点落在几何体之外

现在的问题是我不能在$ geoIntersect上使用$ polygon作为例子,或者使用其他几何然后是多边形。

相关问题