Intersections

MongoDB allows one to find out which geographical features intersect with which other geographical features. MongoDB provides the function $geoIntersects which takes $geometry as a parameter in order to perform this intersection.

A common example would be finding out how many bridges cross one of the rivers in Paris. In order to complete the query, we need a $geometry which contains the coordinates of all the nodes or points which make up the river.

The query would then look as follows:

db.ParisCollection.find(
   {
     loc: {
       $geoIntersects: {
          $geometry: {
             type: "LineString" ,
             coordinates: [
               [ [ 0, 0 ], ... <all coordinates which make up the river> ]
             ]
          }
       }
     }
   }
)

This query would return every object in the ParisCollection collection which intersects with the specified LineString. These would be each bridge which crosses the river.

Leave a comment

Design a site like this with WordPress.com
Get started