20 #include <boost/scoped_ptr.hpp>
23 #include "mongo/client/export_macros.h"
29 #include "mongo/geo/point.h"
34 template <
typename TCoordinates>
73 return GeoObjType_MultiLineString;
81 std::vector<Point<TCoordinates> >
getPoints()
const;
92 static std::vector<LineString<TCoordinates> > parseLineStrings(
const BSONObj& bson);
95 std::vector<LineString<TCoordinates> > _lineStrings;
96 mutable boost::scoped_ptr<BoundingBox<TCoordinates> > _boundingBox;
107 template <
typename TCoordinates>
109 : _bson(
GeoObj<TCoordinates>::validateType(bson, kMultiLineStringTypeStr)),
110 _lineStrings(parseLineStrings(bson)),
111 _boundingBox(
Geometry<TCoordinates>::parseBoundingBox(bson)) {}
113 template <
typename TCoordinates>
116 : _bson(createBSON(lineStrings)), _lineStrings(lineStrings) {}
118 template <
typename TCoordinates>
121 _boundingBox.reset(computeBoundingBox());
122 return *_boundingBox.get();
125 template <
typename TCoordinates>
127 std::vector<Point<TCoordinates> > points, curLineStringPoints;
128 for (
size_t i = 0; i < _lineStrings.size(); ++i) {
129 curLineStringPoints = _lineStrings[i].getPoints();
130 points.insert(points.end(), curLineStringPoints.begin(), curLineStringPoints.end());
135 template <
typename TCoordinates>
140 template <
typename TCoordinates>
144 for (
size_t i = 0; i < lineStrings.size(); ++i)
145 bab.append(lineStrings[i].toBSON()[kCoordsFieldName]);
147 return bob.
append(kTypeFieldName, kMultiLineStringTypeStr)
152 template <
typename TCoordinates>
153 std::vector<LineString<TCoordinates> > MultiLineString<TCoordinates>::parseLineStrings(
155 std::vector<BSONElement> lineStringArr = Geometry<TCoordinates>::getCoordsField(bson).Array();
157 std::vector<LineString<TCoordinates> > lineStrings;
158 for (
size_t i = 0; i < lineStringArr.size(); ++i) {
159 LineString<TCoordinates> line(
160 Geometry<TCoordinates>::parsePointArray(lineStringArr[i].
Array()));
161 lineStrings.push_back(line);
166 template <
typename TCoordinates>
167 BoundingBox<TCoordinates>* MultiLineString<TCoordinates>::computeBoundingBox()
const {
BSONArray arr()
destructive - ownership moves to returned BSONArray
Definition: bsonobjbuilder.h:804
Utility functions for parsing numbers from strings.
Definition: compare_numbers.h:20
std::vector< Point< TCoordinates > > getPoints() const
Obtain the points that make up this MultiLineString.
Definition: multilinestring.h:126
BSONObjBuilder & append(const BSONElement &e)
append element to the object we are building
Definition: bsonobjbuilder.h:124
virtual BSONObj toBSON() const
Obtain a BSON representation of the MultiLineString.
Definition: multilinestring.h:56
Definition: linestring.h:34
Utility for creating a BSONObj.
Definition: bsonobjbuilder.h:53
Definition: multilinestring.h:35
virtual GeoObjType getType() const
Get the geometry type of this object.
Definition: multilinestring.h:72
an embedded array
Definition: bsontypes.h:50
virtual BoundingBox< TCoordinates > getBoundingBox() const
Obtain the bounding box surrounding this MultiLineString.
Definition: multilinestring.h:119
Definition: bsonobjbuilder.h:765
std::vector< LineString< TCoordinates > > getLineStrings() const
Obtain the line strings that make up this MultiLineString.
Definition: multilinestring.h:136
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
MultiLineString(const BSONObj &bson)
MultiLineString constructor.
Definition: multilinestring.h:108