20 #include <boost/scoped_ptr.hpp>
23 #include "mongo/client/export_macros.h"
30 #include "mongo/util/assert_util.h"
36 template <
typename TCoordinates>
39 template <
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;
129 template <
typename TCoordinates>
131 : _bson(
GeoObj<TCoordinates>::validateType(bson, kGeometryCollectionTypeStr)),
132 _geometries(parseGeometries(bson)),
133 _boundingBox(
Geometry<TCoordinates>::parseBoundingBox(bson)) {}
135 template <
typename TCoordinates>
137 for (
size_t i = 0; i < _geometries.size(); ++i)
138 delete _geometries[i];
141 template <
typename TCoordinates>
144 _boundingBox.reset(computeBoundingBox());
145 return *_boundingBox.get();
148 template <
typename TCoordinates>
154 template <
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) {
170 template <
typename TCoordinates>
171 BoundingBox<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());
virtual GeoObjType getType() const
Get the geometry type of this object.
Definition: geometrycollection.h:92
Utility functions for parsing numbers from strings.
Definition: compare_numbers.h:20
virtual BSONObj toBSON() const
Obtain a BSON representation of this geometry collection.
Definition: geometrycollection.h:75
~GeometryCollection()
Frees the heap memory for each geometry stored in this collection.
Definition: geometrycollection.h:136
Definition: geometrycollection.h:37
virtual BoundingBox< TCoordinates > getBoundingBox() const
Obtain the bounding box surrounding the set of geometries in this geometry collection.
Definition: geometrycollection.h:142
BSONType type() const
Returns the type of the element.
Definition: bsonelement.h:154
Definition: geometrycollection.h:40
BSONElement getField(const StringData &name) const
Get the field of the specified name.
GeometryCollection(const BSONObj &bson)
GeometryCollection constructor.
Definition: geometrycollection.h:130
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
an embedded array
Definition: bsontypes.h:50
BSONElement represents an "element" in a BSONObj.
Definition: bsonelement.h:55
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
Definition: geometry.h:39
C++ representation of a "BSON" object – that is, an extended JSON-style object in a binary represent...
Definition: bsonobj.h:78
static BoundingBox< TCoordinates > * computeBoundingBox(const std::vector< Point< TCoordinates > > &points)
Compute the bounding box around the given points.
Definition: geometry.h:137
Represents a bounding box.
Definition: boundingbox.h:67