MongoDB C++ Driver  legacy-1.1.2
Public Member Functions | List of all members
mongo::geo::BoundingBox< TCoordinates > Class Template Reference

Represents a bounding box. More...

#include <boundingbox.h>

Public Member Functions

 BoundingBox (const TCoordinates &min, const TCoordinates &max)
 BoundingBox constructor. More...
 
 BoundingBox (const BSONObj &bson)
 BoundingBox constructor. More...
 
TCoordinates getMin () const
 Get the minimum coordinates of this bounding box. More...
 
TCoordinates getMax () const
 Get the maximum coordinates of this bounding box. More...
 
BSONObj toBSON () const
 Obtain a BSON representation of this bounding box. More...
 
BSONArray toBSONArray () const
 Obtain a flat BSONArray representation of the coordinate values defined by this bounding box. More...
 
BSONArray toNestedBSONArray () const
 Obtain a nested BSONArray representation of the coordinate values defined by this bounding box. More...
 

Detailed Description

template<typename TCoordinates>
class mongo::geo::BoundingBox< TCoordinates >

Represents a bounding box.

A bounding box describes the smallest box that can contain some set of enclosed geometries. For example, the bounding box around the LineString [(0, 0), (5, 0), (2, 6)] would be the rectangle with coordinates [(0, 0), (5, 0), (5, 6), (0, 6)].

A bounding box is defined by the two points on its corners with the lowest and highest values for all axes. The above bounding box is represented as:

{ "bbox" : [ 0, 0, 5, 6 ] }

The first half of the array defines the coordinates of the low point and the second half defines the coordinates of the high point.

Bounding boxes are optional members of Geometries. The BSON for the above LineString, if it included a defined bounding box, would be:

{ "type" : "LineString", "coordinates" : [ [ 0, 0 ], [ 5, 0 ], [ 2, 6 ] ], "bbox" : [ 0, 0, 5, 6 ] }

Example Usage:

BSONObj shapeBSON = cursor->next(); MultiLineString<Coordinates2D> mls(shapeBSON);

// Find all geometry objects inside the bounding box of mls BoundingBox<Coordinates2D> bbox = mls.getBoundingBox(); Query geowithinQuery = MONGO_QUERY("<field_name>" << GEOWITHIN(bbox)); conn.query("<db_name>.<collection_name>", geowithinQuery);

See also
http://geojson.org/geojson-spec.html#bounding-boxes

Constructor & Destructor Documentation

template<typename TCoordinates >
mongo::geo::BoundingBox< TCoordinates >::BoundingBox ( const TCoordinates &  min,
const TCoordinates &  max 
)

BoundingBox constructor.

Parameters
minThe minimum point of the box
maxThe maximum point of the box

Example Usage:

Coordinates2D min(0, 0); Coordinates2D max(5, 6); BoundingBox<Coordinates2D> bbox(min, max);

template<typename TCoordinates >
mongo::geo::BoundingBox< TCoordinates >::BoundingBox ( const BSONObj bson)
explicit

BoundingBox constructor.

Parameters
bsonBSON defining a Geometry that has a member "bbox".

Note that to use this constructor, the BSON must already define the bounding box. If the given BSON has no "bbox" member that defines the bounding box of the shape, an assertion error is raised.

If you have BSON defining a Geometry that has no bbox member and you would like to find the shape's bounding box, call that shape's constructor instead and use its .getBoundingBox() method.

Example usage:

BSONObj bson = BSON( "type" << "LineString" "coordinates" << BSON_ARRAY(BSON_ARRAY(0 << 0) << BSON_ARRAY(5 << 6)) "bbox" << BSON_ARRAY(0 << 0 << 5 << 6)); BoundingBox<Coordinates2D> bbox(bson);

Member Function Documentation

template<typename TCoordinates>
TCoordinates mongo::geo::BoundingBox< TCoordinates >::getMax ( ) const
inline

Get the maximum coordinates of this bounding box.

Returns
TCoordinates that contain the maximum values for each axis of this bounding box.
template<typename TCoordinates>
TCoordinates mongo::geo::BoundingBox< TCoordinates >::getMin ( ) const
inline

Get the minimum coordinates of this bounding box.

Returns
TCoordinates that contain the minimum values for each axis of this bounding box.
template<typename TCoordinates >
BSONObj mongo::geo::BoundingBox< TCoordinates >::toBSON ( ) const

Obtain a BSON representation of this bounding box.

Example BSON, representing minimum coordinates (0, 0) and maximum coordinates (5, 6):

{ "bbox" : [ 0, 0, 5, 6 ] }

Returns
A BSON representation of this bounding box.
template<typename TCoordinates >
BSONArray mongo::geo::BoundingBox< TCoordinates >::toBSONArray ( ) const

Obtain a flat BSONArray representation of the coordinate values defined by this bounding box.

Example BSONArray, representing minimum coordinates (0, 0) and maximum coordinates (5, 6):

[ 0, 0, 5, 6 ]

Returns
A flat BSONArray representation of the coordinate values.
template<typename TCoordinates >
BSONArray mongo::geo::BoundingBox< TCoordinates >::toNestedBSONArray ( ) const

Obtain a nested BSONArray representation of the coordinate values defined by this bounding box.

Example BSONArray, representing minimum coordinates (0, 0) and maximum coordinates (5, 6):

[ [ 0, 0 ], [ 5, 6 ] ]

Returns
A nested BSONArray representation of the coordinate values.

The documentation for this class was generated from the following file: