20#include <boost/scoped_ptr.hpp>
23#include "mongo/client/export_macros.h"
30#include "mongo/util/assert_util.h"
36template <
typename TCoordinates>
39template <
typename TCoordinates>
93 return GeoObjType_GeometryCollection;
105 const std::vector<const GeoObj<TCoordinates>*>&
getGeometries()
const;
114 static std::vector<const GeoObj<TCoordinates>*> parseGeometries(
const BSONObj& bson);
117 std::vector<const GeoObj<TCoordinates>*> _geometries;
118 mutable boost::scoped_ptr<BoundingBox<TCoordinates> > _boundingBox;
129template <
typename TCoordinates>
132 _geometries(parseGeometries(bson)),
133 _boundingBox(
Geometry<TCoordinates>::parseBoundingBox(bson)) {}
135template <
typename TCoordinates>
137 for (
size_t i = 0; i < _geometries.size(); ++i)
138 delete _geometries[i];
141template <
typename TCoordinates>
144 _boundingBox.reset(computeBoundingBox());
145 return *_boundingBox.get();
148template <
typename TCoordinates>
154template <
typename TCoordinates>
159 "bson must contain a field \"geometries\" of type Array",
160 !geometriesField.
eoo() && geometriesField.
type() ==
Array);
162 std::vector<BSONElement> geometriesArr = geometriesField.Array();
163 std::vector<const GeoObj<TCoordinates>*> geometries;
164 for (
size_t i = 0; i < geometriesArr.size(); ++i) {
170template <
typename TCoordinates>
171BoundingBox<TCoordinates>* GeometryCollection<TCoordinates>::computeBoundingBox()
const {
172 std::vector<BoundingBox<TCoordinates> > bboxes;
173 for (
size_t i = 0; i < _geometries.size(); ++i)
174 bboxes.push_back(_geometries[i]->getBoundingBox());
BSONElement represents an "element" in a BSONObj.
Definition bsonelement.h:55
bool eoo() const
Indicates if it is the end-of-object element, which is present at the end of every BSON object.
Definition bsonelement.h:172
BSONType type() const
Returns the type of the element.
Definition bsonelement.h:154
C++ representation of a "BSON" object – that is, an extended JSON-style object in a binary representa...
Definition bsonobj.h:78
BSONElement getField(const StringData &name) const
Get the field of the specified name.
Represents a bounding box.
Definition boundingbox.h:67
Definition geometrycollection.h:40
virtual BoundingBox< TCoordinates > getBoundingBox() const
Obtain the bounding box surrounding the set of geometries in this geometry collection.
Definition geometrycollection.h:142
~GeometryCollection()
Frees the heap memory for each geometry stored in this collection.
Definition geometrycollection.h:136
virtual BSONObj toBSON() const
Obtain a BSON representation of this geometry collection.
Definition geometrycollection.h:75
virtual GeoObjType getType() const
Get the geometry type of this object.
Definition geometrycollection.h:92
const std::vector< const GeoObj< TCoordinates > * > & getGeometries() const
Get a vector of pointers to the geometries contained in this geometry collection.
Definition geometrycollection.h:149
GeometryCollection(const BSONObj &bson)
GeometryCollection constructor.
Definition geometrycollection.h:130
static BoundingBox< TCoordinates > * computeBoundingBox(const std::vector< Point< TCoordinates > > &points)
Compute the bounding box around the given points.
Definition geometry.h:137
const char kGeometryCollectionTypeStr[]
The different possible geometry type names in GeoJSON.
Definition constants.h:34
GeoObjType
An enum to represent the type of geometry of a Geo object.
Definition constants.h:45
Utility functions for parsing numbers from strings.
Definition compare_numbers.h:20
@ Array
an embedded array
Definition bsontypes.h:50