mongodb - Difference in $geoWithin and $geoIntersects operators? -
what difference in $geowithin , $geointersects operators in mongodb?
if looking coordinates (using default coordinate reference system), $geowithin , $geointersects return same result.
please correct me if wrong.
any simple use case understanding difference appreciated.
from $geointersects:
selects documents geospatial data intersects specified geojson object; i.e. intersection of data , specified object non-empty. includes cases data , specified object share edge.
from $geowithin:
selects documents geospatial data exists entirely within specified shape.
take following example:
> db.test.drop() > var poly1 = { "type" : "polygon", "coordinates" : [[[0, 0], [3, 0], [0, 3], [0, 0]]] } > var poly2 = { "type" : "polygon", "coordinates" : [[[1, 1], [2, 1], [1, 2], [1, 1]]] } // poly1 similar triangle inside poly2 > var poly3 = { "type" : "polygon", "coordinates" : [[[1, 0], [-2, 0], [1, 3], [1, 0]]] } // poly3 poly1 flipped around "vertical" edge, bumped on 1 unit, intersects poly1 not contained in > db.test.insert({ "loc" : poly2 }) > db.test.insert({ "loc" : poly3 }) > db.test.ensureindex({ "loc" : "2dsphere" }) > db.test.find({ "loc" : { "$geointersects" : { "$geometry" : poly1 } } }) // poly2 , poly3 returned > db.test.find({ "loc" : { "$geowithin" : { "$geometry" : poly1 } } }) // poly2 returned
Comments
Post a Comment