[SERVER-35837] geo query the area range coordinates, the result set has coordinates that are not within the area Created: 27/Jun/18  Updated: 27/Oct/23  Resolved: 17/Jul/18

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: 3.4.10
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: wangdejian Assignee: Nick Brewer
Resolution: Works as Designed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

centos7


Participants:

 Description   

mongodb version: rhel70-3.4.10。I have a polygon.

"loc:2dsphere".
[[[ 151.53203354373443 , 58.49758352997918 ] ,
[ 151.53203354373443 , 58.60891434369525] ,
[ 157.98703167431324 , 58.60891434369525 ] ,
[ 157.98703167431324 , 58.49758352997918 ],
[151.53203354373443 , 58.49758352997918]]]

Here's the query:

db.places.find({
  loc: {
    $geoWithin: {
      $geometry: {
        type: "Polygon",
        coordinates: [
          [
            [151.53203354373443, 58.49758352997918],
            [151.53203354373443, 58.60891434369525],
            [157.98703167431324, 58.60891434369525],
            [157.98703167431324, 58.49758352997918],
            [151.53203354373443, 58.49758352997918]
          ]
        ]
      }
    }
  }
})

There exists coordinates that are beyond the highest latitude, 58.60891434369525. For example:
[156.1194,58.638217],[156.1194,58.61],[156.51067,58.610183],[155.858483,58.618367],[155.858483,58.618367],[155.859767,58.618867],[153.55,58,616667]. They are not in the query area.


mongodb版本rhel70-3.4.10。我现在有一个多边形,"loc:2dsphere".
[[[ 151.53203354373443 , 58.49758352997918 ] ,
[ 151.53203354373443 , 58.60891434369525] ,
[ 157.98703167431324 , 58.60891434369525 ] ,
[ 157.98703167431324 , 58.49758352997918 ],
[151.53203354373443 , 58.49758352997918]]]
查询命令如下:

{{db.places.find( { loc :
{ $geoWithin :
{ $geometry :

{ type : "Polygon", coordinates : [ [ [ 151.53203354373443 , 58.49758352997918 ] , [ 151.53203354373443 , 58.60891434369525] , [ 157.98703167431324 , 58.60891434369525 ] , [ 157.98703167431324 , 58.49758352997918 ], [151.53203354373443 , 58.49758352997918] ] ] }

} } } )}}

{{}}

查询结果中发现有不少坐标点纬度超过了该区域的最大纬度,58.60891434369525。例如:[156.1194,58.638217],[156.1194,58.61],[156.51067,58.610183],[155.858483,58.618367],[155.858483,58.618367],[155.859767,58.618867],[153.55,58,616667]等坐标点不在该区域范围内。{{}}

{{}}

{{}}

{{}}

{{}}

{{}}

{{}}

{{}}

{{}}

{{}}



 Comments   
Comment by Nick Brewer [ 17/Jul/18 ]

Hi doe wang

The behavior you're seeing is expected - the lines that make up a polygon are traveling over a sphere, and as a result the polygon can encompass points that are above or below those that make up the shape. This example from our documentation is a good illustration of what this looks like in practice.

Regards,
Nick

Comment by wangdejian [ 11/Jul/18 ]

Can you tell me my question is bug or not?

Generated at Thu Feb 08 04:41:10 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.