Using MongoDB 3.2 i'm trying to use 2dsphere queries on a collection of Points.
Lets say i have à collection cust_5_abcd with a 2dsphere index on the_geom field.
Add a geometry in the collection :
db.cust_5_abcd.insert({
"chps0" : "Texte d'une ligne",
"the_geom" : {
"type" : "Point",
"coordinates" : [
1.032715,
40.380028
]
}})
Now i'm trying to query this Point using $geoWithin to get all data inside a specific Polygon. This is where i'm getting different result if i use $geometry with the GeoJSON definition , or with $polygon and the strict coordinates. Maybe something in the documentation is missing or something i misunderstood.
With $geometry gives NO result:
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 ]
]
]
}
}
}
})
With $polygon returns my 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 ]
]
}
}
})
Got the answer from the mongodb people : https://jira.mongodb.org/browse/SERVER-24549?focusedCommentId=1293398&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-1293398
When using $polygon a planar geometry is calculated, and the point falls inside the polygon you describe. But when you use GeoJSON a spherical geometry is used, and the point falls outside the geometry
Now the problem is that i cannot use $polygon on $geoIntersect for exemple or with other geometry then a polygon.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With