Пример #1
0
 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;
 }
Пример #2
0
 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;
 }
Пример #3
0
 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;
 }
Пример #4
0
 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;
 }
Пример #5
0
 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;
 }
Пример #6
0
 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;
 }
Пример #7
0
 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;
 }
Пример #8
0
 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;
 }
Пример #9
0
 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;
 }
Пример #10
0
 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;
 }
Пример #11
0
    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;
    }
Пример #12
0
 bool GeoParser::isPoint(const BSONObj &obj) {
     return isGeoJSONPoint(obj) || isLegacyPoint(obj);
 }
Пример #13
0
 bool GeoParser::isIndexablePoint(const BSONObj &obj) {
     return isLegacyPoint(obj, true) || isGeoJSONPoint(obj);
 }