bool GeoParser::parsePolygon(const BSONObj &obj, PolygonWithCRS *out) { if (isGeoJSONPolygon(obj)) { const vector<BSONElement>& coordinates = obj.getFieldDotted(GEOJSON_COORDINATES).Array(); if (!parseGeoJSONCRS(obj, &out->crs)) return false; if (out->crs == SPHERE) { out->s2Polygon.reset(new S2Polygon()); if (!parseGeoJSONPolygonCoordinates(coordinates, obj, out->s2Polygon.get())) { return false; } } else if (out->crs == STRICT_SPHERE) { out->bigPolygon.reset(new BigSimplePolygon()); if (!parseBigSimplePolygonCoordinates(coordinates, obj, out->bigPolygon.get())) { return false; } } } else { BSONObjIterator typeIt(obj); BSONElement type = typeIt.next(); BSONObjIterator coordIt(type.embeddedObject()); vector<Point> points; while (coordIt.more()) { Point p; if (!parseLegacyPoint(coordIt.next().Obj(), &p)) { return false; } points.push_back(p); } out->oldPolygon.init(points); out->crs = FLAT; } return true; }
void GeoParser::parseLegacyBox(const BSONObj &obj, Box *out) { BSONObjIterator coordIt(obj); BSONElement minE = coordIt.next(); BSONElement maxE = coordIt.next(); parseLegacyPoint(minE.Obj(), &out->_min); parseLegacyPoint(maxE.Obj(), &out->_max); }
void GeoParser::parseLegacyPolygon(const BSONObj &obj, Polygon *out) { vector<Point> points; BSONObjIterator coordIt(obj); while (coordIt.more()) { Point p; parseLegacyPoint(coordIt.next().Obj(), &p); points.push_back(p); } *out = Polygon(points); }
bool GeoParser::parseBox(const BSONObj &obj, BoxWithCRS *out) { BSONObjIterator typeIt(obj); BSONElement type = typeIt.next(); BSONObjIterator coordIt(type.embeddedObject()); BSONElement minE = coordIt.next(); BSONElement maxE = coordIt.next(); if (!parseLegacyPoint(minE.Obj(), &out->box._min) || !parseLegacyPoint(maxE.Obj(), &out->box._max)) { return false; } out->crs = FLAT; return true; }
bool GeoParser::isLegacyBox(const BSONObj &obj) { BSONObjIterator coordIt(obj); BSONElement minE = coordIt.next(); if (!minE.isABSONObj()) { return false; } if (!isLegacyPoint(minE.Obj())) { return false; } if (!coordIt.more()) { return false; } BSONElement maxE = coordIt.next(); if (!maxE.isABSONObj()) { return false; } if (!isLegacyPoint(maxE.Obj())) { return false; } return true; }
void GeoParser::parseLegacyPolygon(const BSONObj &obj, Polygon *out) { BSONObjIterator typeIt(obj); BSONElement type = typeIt.next(); BSONObjIterator coordIt(type.embeddedObject()); vector<Point> points; while (coordIt.more()) { Point p; parseLegacyPoint(coordIt.next().Obj(), &p); points.push_back(p); } *out = Polygon(points); }
bool GeoParser::isLegacyPolygon(const BSONObj &obj) { BSONObjIterator coordIt(obj); int vertices = 0; while (coordIt.more()) { BSONElement coord = coordIt.next(); if (!coord.isABSONObj()) { return false; } if (!isLegacyPoint(coord.Obj())) { return false; } ++vertices; } if (vertices < 3) { return false; } return true; }
bool GeoParser::isLegacyBox(const BSONObj &obj) { BSONObjIterator typeIt(obj); BSONElement type = typeIt.next(); if (!type.isABSONObj()) { return false; } if (!mongoutils::str::equals(type.fieldName(), "$box")) { return false; } BSONObjIterator coordIt(type.embeddedObject()); BSONElement minE = coordIt.next(); if (!minE.isABSONObj()) { return false; } if (!isLegacyPoint(minE.Obj())) { return false; } if (!coordIt.more()) { return false; } BSONElement maxE = coordIt.next(); if (!maxE.isABSONObj()) { return false; } if (!isLegacyPoint(maxE.Obj())) { return false; } return true; }
static bool isLegacyPolygon(const BSONObj &obj) { BSONObjIterator typeIt(obj); BSONElement type = typeIt.next(); if (!type.isABSONObj()) { return false; } if (!mongoutils::str::equals(type.fieldName(), "$polygon")) { return false; } BSONObjIterator coordIt(type.embeddedObject()); int vertices = 0; while (coordIt.more()) { BSONElement coord = coordIt.next(); if (!coord.isABSONObj()) { return false; } if (!isLegacyPoint(coord.Obj())) { return false; } ++vertices; } if (vertices < 3) { return false; } return true; }
bool GeoParser::parsePolygon(const BSONObj &obj, PolygonWithCRS *out) { if (isGeoJSONPolygon(obj)) { const vector<BSONElement>& coordinates = obj.getFieldDotted(GEOJSON_COORDINATES).Array(); if (!parseGeoJSONPolygonCoordinates(coordinates, obj, &out->polygon)) { return false; } out->crs = SPHERE; } else { BSONObjIterator typeIt(obj); BSONElement type = typeIt.next(); BSONObjIterator coordIt(type.embeddedObject()); vector<Point> points; while (coordIt.more()) { Point p; if (!parseLegacyPoint(coordIt.next().Obj(), &p)) { return false; } points.push_back(p); } out->oldPolygon = Polygon(points); out->crs = FLAT; } return true; }
static bool isLegacyCenterSphere(const BSONObj &obj) { BSONObjIterator typeIt(obj); BSONElement type = typeIt.next(); if (!type.isABSONObj()) { return false; } bool isCenterSphere = mongoutils::str::equals(type.fieldName(), "$centerSphere"); if (!isCenterSphere) { return false; } BSONObjIterator objIt(type.embeddedObject()); BSONElement center = objIt.next(); if (!center.isABSONObj()) { return false; } if (!isLegacyPoint(center.Obj())) { return false; } // Check to make sure the points are valid lng/lat. BSONObjIterator coordIt(center.Obj()); BSONElement lng = coordIt.next(); BSONElement lat = coordIt.next(); if (!isValidLngLat(lng.Number(), lat.Number())) { return false; } if (!objIt.more()) { return false; } BSONElement radius = objIt.next(); if (!radius.isNumber()) { return false; } return true; }
void GeoParser::parseLegacyPolygon(const BSONObj &obj, S2Polygon *out) { vector<S2Point> points; BSONObjIterator coordIt(obj); while (coordIt.more()) { BSONElement coord = coordIt.next(); S2Point point; parseLegacyPoint(coord.Obj(), &point); points.push_back(point); } points.push_back(points[0]); S2PolygonBuilderOptions polyOptions; polyOptions.set_validate(true); S2PolygonBuilder polyBuilder(polyOptions); S2Loop exteriorLoop(points); if (exteriorLoop.is_hole()) { exteriorLoop.Invert(); } polyBuilder.AddLoop(&exteriorLoop); polyBuilder.AssemblePolygon(out, NULL); }