MongoDB $ geoWithin语句不适用于宽范围

时间:2016-03-07 14:10:27

标签: mongodb mongodb-query geospatial

以下文档:

{
    "_id" : ObjectId("56dd4fb755eb122ee622e17d"),
    "geo_segments" : {
        "type" : "MultiPoint",
        "coordinates" : [ 
            [ 
                90, 
                0
            ]
        ]
    }
}

可以使用:

找到
db.collection.find({
    "geo_segments": {
      $geoWithin: {
        $geometry: {
          type : "Polygon" ,
          coordinates: [ [
            [-131, -90], [-131, 90],
            [131, 90], [131, -90],
            [-131, -90]
          ] ]
        }
      }
    }
});

但是当我将所有131次出现更改为132时,没有找到任何内容:

db.collection.find({
    "geo_segments": {
      $geoWithin: {
        $geometry: {
          type : "Polygon" ,
          coordinates: [ [
            [-132, -90], [-132, 90], [132, 90], [132, -90], [-132, -90]
          ] ]
        }
      }
    }
});

为什么这不起作用? CRS功能似乎也不起作用:

db.collection.find({
    "geo_segments": {
      $geoWithin: {
        $geometry: {
          type : "Polygon" ,
          coordinates: [ [
            [-132, -90], [-132, 90], [132, 90], [132, -90], [-132, -90]
          ] ],
          crs: {
            type: "name",
            properties: { name: "urn:x-mongodb:crs:strictwinding:EPSG:4326" }
          }
        }
      }
    }
});

字段的索引为2dsphere,Mongo为3.3.1

UPD:

尝试以相反的顺序设置点以将多边形视为“包含”区域,没有结果:

db.geo_series.find({
    "geo_segments": {
      $geoWithin: {
        $geometry: {
          type : "Polygon" ,
          coordinates: [ [
            [-132, -90], [132, -90], [132, 90], [-132, 90], [-132, -90]
          ] ]
        }
      }
    }
});

1 个答案:

答案 0 :(得分:1)

documentation says逆时针缠绕”中的单环多边形相似(原文如此)

db.geo_series.find({
    "geo_segments": {
      "$geoWithin": {
        "$geometry": {
          "type" : "Polygon" ,
          "coordinates": [ [
            [-132, -90],[132, -90], [132, 90], [-132, 90], [-132, -90]
          ] ],
          "crs": {
            "type": "name",
            "properties": { "name": "urn:x-mongodb:crs:strictwinding:EPSG:4326" }
          }
        }
      }
    }
});

因此定义多边形的方向很重要,因为“crs”也是如此,因为你的多边形确实超出了单个半球。

仅供参考,您的多边形基本上与文档中的参考多边形相同,即跨越半球和经度和纬度的反向顺序,但只是略大一些区域。