20 #include <boost/scoped_ptr.hpp>
23 #include "mongo/client/export_macros.h"
29 #include "mongo/geo/point.h"
35 template <
typename TCoordinates>
67 return GeoObjType_MultiPolygon;
75 std::vector<Point<TCoordinates> >
getPoints()
const;
88 static std::vector<Polygon<TCoordinates> > parseAllPolygons(
const BSONObj& bson);
91 std::vector<Polygon<TCoordinates> > _polygons;
92 mutable boost::scoped_ptr<BoundingBox<TCoordinates> > _boundingBox;
103 template <
typename TCoordinates>
105 : _bson(
GeoObj<TCoordinates>::validateType(bson, kMultiPolygonTypeStr)),
106 _polygons(parseAllPolygons(bson)),
107 _boundingBox(
Geometry<TCoordinates>::parseBoundingBox(bson)) {}
109 template <
typename TCoordinates>
112 _boundingBox.reset(computeBoundingBox());
113 return *_boundingBox.get();
116 template <
typename TCoordinates>
118 std::vector<Point<TCoordinates> > points, curPolygonPoints;
119 for (
size_t i = 0; i < _polygons.size(); ++i) {
120 curPolygonPoints = _polygons[i].getPoints();
121 points.insert(points.end(), curPolygonPoints.begin(), curPolygonPoints.end());
126 template <
typename TCoordinates>
128 std::vector<BSONElement> linearRingElems = polygon.Array();
129 std::vector<LineString<TCoordinates> > linearRings;
130 for (
size_t i = 0; i < linearRingElems.size(); ++i) {
134 return Polygon<TCoordinates>(linearRings);
137 template <
typename TCoordinates>
138 std::vector<Polygon<TCoordinates> > MultiPolygon<TCoordinates>::parseAllPolygons(
139 const BSONObj& bson) {
140 std::vector<BSONElement> polygonArr = Geometry<TCoordinates>::getCoordsField(bson).Array();
141 std::vector<Polygon<TCoordinates> > polygons;
142 for (
size_t i = 0; i < polygonArr.size(); ++i) {
143 polygons.push_back(parsePolygon(polygonArr[i]));
148 template <
typename TCoordinates>
149 BoundingBox<TCoordinates>* MultiPolygon<TCoordinates>::computeBoundingBox()
const {
virtual BoundingBox< TCoordinates > getBoundingBox() const
Obtain the bounding box surrounding this MultiPolygon.
Definition: multipolygon.h:110
Utility functions for parsing numbers from strings.
Definition: compare_numbers.h:20
Definition: linestring.h:34
Definition: multipolygon.h:36
virtual GeoObjType getType() const
Get the geometry type of this object.
Definition: multipolygon.h:66
std::vector< Point< TCoordinates > > getPoints() const
Obtain the points that make up this MultiPolygon.
Definition: multipolygon.h:117
an embedded array
Definition: bsontypes.h:50
BSONElement represents an "element" in a BSONObj.
Definition: bsonelement.h:55
std::vector< Polygon< TCoordinates > > getPolygons() const
Obtain the Polygons that make up this MultiPolygon.
Definition: multipolygon.h:82
Definition: geometry.h:39
virtual BSONObj toBSON() const
Obtain a BSON representation of the MultiPolygon.
Definition: multipolygon.h:50
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
MultiPolygon(const BSONObj &bson)
MultiPolygon constructor.
Definition: multipolygon.h:104