20#include <boost/scoped_ptr.hpp>
23#include "mongo/client/export_macros.h"
29#include "mongo/geo/point.h"
34template <
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;
107template <
typename TCoordinates>
109 : _bson(
GeoObj<TCoordinates>::validateType(bson, kMultiLineStringTypeStr)),
110 _lineStrings(parseLineStrings(bson)),
111 _boundingBox(
Geometry<TCoordinates>::parseBoundingBox(bson)) {}
113template <
typename TCoordinates>
116 : _bson(createBSON(lineStrings)), _lineStrings(lineStrings) {}
118template <
typename TCoordinates>
121 _boundingBox.reset(computeBoundingBox());
122 return *_boundingBox.get();
125template <
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());
135template <
typename TCoordinates>
140template <
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)
152template <
typename TCoordinates>
153std::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);
166template <
typename TCoordinates>
167BoundingBox<TCoordinates>* MultiLineString<TCoordinates>::computeBoundingBox()
const {
Definition bsonobjbuilder.h:765
BSONArray arr()
destructive - ownership moves to returned BSONArray
Definition bsonobjbuilder.h:804
Utility for creating a BSONObj.
Definition bsonobjbuilder.h:53
BSONObjBuilder & append(const BSONElement &e)
append element to the object we are building
Definition bsonobjbuilder.h:124
BSONObj obj()
destructive The returned BSONObj will free the buffer when it is finished.
Definition bsonobjbuilder.h:618
C++ representation of a "BSON" object – that is, an extended JSON-style object in a binary representa...
Definition bsonobj.h:78
Represents a bounding box.
Definition boundingbox.h:67
static BoundingBox< TCoordinates > * computeBoundingBox(const std::vector< Point< TCoordinates > > &points)
Compute the bounding box around the given points.
Definition geometry.h:137
Definition linestring.h:34
Definition multilinestring.h:35
MultiLineString(const BSONObj &bson)
MultiLineString constructor.
Definition multilinestring.h:108
std::vector< LineString< TCoordinates > > getLineStrings() const
Obtain the line strings that make up this MultiLineString.
Definition multilinestring.h:136
virtual GeoObjType getType() const
Get the geometry type of this object.
Definition multilinestring.h:72
virtual BoundingBox< TCoordinates > getBoundingBox() const
Obtain the bounding box surrounding this MultiLineString.
Definition multilinestring.h:119
std::vector< Point< TCoordinates > > getPoints() const
Obtain the points that make up this MultiLineString.
Definition multilinestring.h:126
virtual BSONObj toBSON() const
Obtain a BSON representation of the MultiLineString.
Definition multilinestring.h:56
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