$geoWithin查询未能检索包含在查询多边形内的点 – v2

huangapple go评论55阅读模式
英文:

$geoWithin query fail to retrieve point included in the queried polygon - v2

问题

I've already asked the same question in this post. My example was subject to earth curvature issue so let's have a look at another one.

This time I have two nested polygons. A large one and a smaller one. Performing a $geoWithin query with the larger one returns no document, while the document is found using the smaller polygon. Any thoughts?

$geoWithin查询未能检索包含在查询多边形内的点 – v2

The document I'm trying to query is located on an island on the west coast of France.

{
"_id": {
"$oid": "625fec0f6476793a4581d172"
},
"featureOfInterest": {
"samplingFeature": {
"geometry": {
"type": "Point",
"coordinates": [
-2.3433781679840138,
46.713764788942484
]
},
"name": [
{
"lang": "en",
"text": "France"
}
],
"type": "Feature"
}
}
}

And the query:

db.collection.aggregate([
{
$match: {
"$or": [
// Largest polygon - returns no document
{
"samplingFeature.geometry": {
"$geoWithin": {
"$geometry": {
"type": "Polygon",
"coordinates": [
[[-55.722656, 34.161818], [58.007813, 34.161818], [58.007813, 53.540307], [-55.722656, 53.540307], [-55.722656, 34.161818]]
]
}
}
}
},
// Smallest polygon - returns the document
//{
// "samplingFeature.geometry": {
// "$geoWithin": {
// "$geometry": {
// "type": "Polygon",
// "coordinates": [[[-5.800781, 42.682435], [9.316406, 42.682435], [9.316406, 50.625073], [-5.800781, 50.625073], [-5.800781, 42.682435]]]
// }
// }
//}
//}
]
}
}
])

英文:

I've already ask the same question in this post. My example was subject to earth curvature issue so lets have a look to another one.


This time I have two nested polygons. A large one and a smaller one. Performing a $geoWithin query with the larger one return no document while the document is found using the smaller polygon. Any thoughts?

https://mongoplayground.net/p/V_3-s-itngA

$geoWithin查询未能检索包含在查询多边形内的点 – v2

The document I'm trying to query which is located on an island on France west coast.

  {
    "_id": {
      "$oid": "625fec0f6476793a4581d172"
    },
    "featureOfInterest": {
      "samplingFeature": {
        "geometry": {
          "type": "Point",
          "coordinates": [
            -2.3433781679840138,
            46.713764788942484
          ]
        },
        "name": [
          {
            "lang": "en",
            "text": "France"
          }
        ],
        "type": "Feature"
      }
    }
  }

And the query

db.collection.aggregate([
  {
    $match: {
      "$or": [
        //Largest polygon - return no document
        {
          "samplingFeature.geometry": {
            "$geoWithin": {
              "$geometry": {
                "type": "Polygon",
                "coordinates": [
                  [[-55.722656,34.161818],[58.007813,34.161818],[ 58.007813,53.540307],[ -55.722656, 53.540307], [-55.722656,34.161818]]]
              }
            }
          }
        },
        //Smallest polygon - return the document
        //{
        //  "samplingFeature.geometry": {
        //    "$geoWithin": {
        //      "$geometry": {
        //        "type": "Polygon",
        //        "coordinates": [[[-5.800781, 42.682435], [9.316406, 42.682435], [9.316406, 50.625073], [-5.800781, 50.625073], [-5.800781, 42.682435]]]
        //      }
        //    }
        //}
        //}
        
      ]
    }
  }
])

答案1

得分: 1

你已经把地球弯曲了。你帖子中的坐标制成了这些框:

$geoWithin查询未能检索包含在查询多边形内的点 – v2

标记明显在更大的框外面。

请使用我在你之前问题的答案中提供的jsfddle链接,而不是使用地球仪或其他来源获取你的图像。两点之间的最短路径不一定遵循经度和纬度。请阅读有关Mongo地理空间查询中使用的大圆线计算的数学知识。

英文:

You've bent the planet other way round. The coordinates in your post make these boxes:

$geoWithin查询未能检索包含在查询多边形内的点 – v2

the marker is clearly outside the the larger box.

Please use the link to jsfddle in my answer to your previous question instead of globes, or wherever you get your image from. The shortest path between 2 points far away does not necessarily follow longitudes and latitudes. Please read about the math of Geodesic calculations used in mongo geospatial queries.

huangapple
  • 本文由 发表于 2023年2月18日 01:33:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/75487505.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定