20#include <boost/scoped_ptr.hpp>
23#include "mongo/client/export_macros.h"
28#include "mongo/geo/point.h"
33template <
typename TCoordinates>
75 return GeoObjType_LineString;
83 std::vector<Point<TCoordinates> >
getPoints()
const {
91 std::vector<Point<TCoordinates> > _points;
92 mutable boost::scoped_ptr<BoundingBox<TCoordinates> > _boundingBox;
103template <
typename TCoordinates>
105 : _bson(
GeoObj<TCoordinates>::validateType(bson, kLineStringTypeStr)),
106 _points(
Geometry<TCoordinates>::parseAllPoints(bson)),
107 _boundingBox(
Geometry<TCoordinates>::parseBoundingBox(bson)) {}
109template <
typename TCoordinates>
111 : _bson(createBSON(points)), _points(points) {}
113template <
typename TCoordinates>
115 : _bson(other._bson), _points(other._points) {
121 if (other._boundingBox)
125template <
typename TCoordinates>
126LineString<TCoordinates>& LineString<TCoordinates>::operator=(LineString<TCoordinates> other) {
128 swap(_bson, other._bson);
129 swap(_points, other._points);
130 swap(_boundingBox, other._boundingBox);
134template <
typename TCoordinates>
137 _boundingBox.reset(computeBoundingBox());
138 return *_boundingBox.get();
141template <
typename TCoordinates>
144 for (
size_t i = 0; i < points.size(); ++i)
145 bab.append(points[i].toBSON()[kCoordsFieldName]);
147 return bob.
append(kTypeFieldName, kLineStringTypeStr).
append(kCoordsFieldName, bab.
arr()).
obj();
150template <
typename TCoordinates>
151BoundingBox<TCoordinates>* LineString<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
LineString(const BSONObj &bson)
LineString constructor.
Definition linestring.h:104
virtual BSONObj toBSON() const
Obtain a BSON representation of the line string.
Definition linestring.h:58
virtual GeoObjType getType() const
Get the geometry type of this object.
Definition linestring.h:74
virtual BoundingBox< TCoordinates > getBoundingBox() const
Obtain the bounding box surrounding this line string.
Definition linestring.h:135
std::vector< Point< TCoordinates > > getPoints() const
Obtain the points that make up this LineString.
Definition linestring.h:83
Represents a Point.
Definition point.h:52
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