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

Gba*_*acc 6 mongodb

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

假设我在the_geom字段上有一个带有2dsphere索引的à集合cust_5_abcd.

在集合中添加几何:

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

现在我正在尝试使用$ geoWithin查询此Point以获取特定Polygon中的所有数据.如果我使用带有GeoJSON定义的$ geometry,或者使用$ 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 ] 
                ] 
                ]
            } 
        } 
    } 
})
Run Code Online (Sandbox Code Playgroud)

使用$ 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 ] 
                ]                 
        } 
    } 
})
Run Code Online (Sandbox Code Playgroud)

Gba*_*acc 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 例如或与其他几何图形然后多边形。