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; }
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; }
bool GeoParser::isLegacyCenter(const BSONObj &obj) { BSONObjIterator objIt(obj); BSONElement center = objIt.next(); if (!center.isABSONObj()) { return false; } if (!isLegacyPoint(center.Obj())) { return false; } if (!objIt.more()) { return false; } BSONElement radius = objIt.next(); if (!radius.isNumber()) { return false; } return true; }
bool GeoParser::parsePoint(const BSONObj &obj, Point *out) { if (isGeoJSONPoint(obj)) { parseGeoJSONPoint(obj, out); return true; } else if (isLegacyPoint(obj)) { parseLegacyPoint(obj, out); return true; } return false; }
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::parsePoint(const BSONObj &obj, S2Point *out) { if (isGeoJSONPoint(obj)) { parseGeoJSONPoint(obj, out); return true; } else if (isLegacyPoint(obj)) { BSONObjIterator it(obj); BSONElement x = it.next(); BSONElement y = it.next(); *out = coordToPoint(x.number(), y.number()); return true; } return false; }
static bool isLegacyCenter(const BSONObj &obj) { BSONObjIterator typeIt(obj); BSONElement type = typeIt.next(); if (!type.isABSONObj()) { return false; } bool isCenter = mongoutils::str::equals(type.fieldName(), "$center"); if (!isCenter) { return false; } BSONObjIterator objIt(type.embeddedObject()); BSONElement center = objIt.next(); if (!center.isABSONObj()) { return false; } if (!isLegacyPoint(center.Obj())) { return false; } if (!objIt.more()) { return false; } BSONElement radius = objIt.next(); if (!radius.isNumber()) { 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::parsePoint(const BSONObj &obj, PointWithCRS *out) { if (isLegacyPoint(obj, true)) { BSONObjIterator it(obj); BSONElement x = it.next(); BSONElement y = it.next(); out->oldPoint.x = x.Number(); out->oldPoint.y = y.Number(); out->crs = FLAT; } else if (isGeoJSONPoint(obj)) { const vector<BSONElement>& coords = obj.getFieldDotted(GEOJSON_COORDINATES).Array(); out->oldPoint.x = coords[0].Number(); out->oldPoint.y = coords[1].Number(); out->crs = FLAT; if (!ShapeProjection::supportsProject(*out, SPHERE)) return false; ShapeProjection::projectInto(out, SPHERE); } 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; }
bool GeoParser::parsePoint(const BSONObj &obj, PointWithCRS *out) { if (isGeoJSONPoint(obj)) { const vector<BSONElement>& coords = obj.getFieldDotted(GEOJSON_COORDINATES).Array(); out->point = coordToPoint(coords[0].Number(), coords[1].Number()); out->cell = S2Cell(out->point); out->oldPoint.x = coords[0].Number(); out->oldPoint.y = coords[1].Number(); out->crs = SPHERE; } else if (isLegacyPoint(obj)) { BSONObjIterator it(obj); BSONElement x = it.next(); BSONElement y = it.next(); out->point = coordToPoint(x.Number(), y.Number()); out->cell = S2Cell(out->point); out->oldPoint.x = x.Number(); out->oldPoint.y = y.Number(); out->crs = FLAT; } return true; }
bool GeoParser::isPoint(const BSONObj &obj) { return isGeoJSONPoint(obj) || isLegacyPoint(obj); }
bool GeoParser::isIndexablePoint(const BSONObj &obj) { return isLegacyPoint(obj, true) || isGeoJSONPoint(obj); }