MongoDB C++ Driver
legacy-1.1.2
|
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... | |
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);
mongo::geo::BoundingBox< TCoordinates >::BoundingBox | ( | const TCoordinates & | min, |
const TCoordinates & | max | ||
) |
BoundingBox constructor.
min | The minimum point of the box |
max | The maximum point of the box |
Example Usage:
Coordinates2D min(0, 0); Coordinates2D max(5, 6); BoundingBox<Coordinates2D> bbox(min, max);
|
explicit |
BoundingBox constructor.
bson | BSON 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);
|
inline |
Get the maximum coordinates of this bounding box.
|
inline |
Get the minimum coordinates of this bounding box.
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 ] }
BSONArray mongo::geo::BoundingBox< TCoordinates >::toBSONArray | ( | ) | const |
BSONArray mongo::geo::BoundingBox< TCoordinates >::toNestedBSONArray | ( | ) | const |