コード例 #1
0
ファイル: geoparser.cpp プロジェクト: ashleybrener/mongo
    bool GeoParser::parsePointWithMaxDistance(const BSONObj& obj, PointWithCRS* out, double* maxOut) {
        BSONObjIterator it(obj);
        if (!it.more()) { return false; }

        BSONElement lng = it.next();
        if (!lng.isNumber()) { return false; }
        if (!it.more()) { return false; }

        BSONElement lat = it.next();
        if (!lat.isNumber()) { return false; }
        if (!it.more()) { return false; }

        BSONElement dist = it.next();
        if (!dist.isNumber()) { return false; }
        if (it.more()) { return false; }

        out->crs = FLAT;
        out->oldPoint.x = lng.number();
        out->oldPoint.y = lat.number();
        *maxOut = dist.number();
        if (isValidLngLat(lng.Number(), lat.Number())) {
            out->flatUpgradedToSphere = true;
            out->point = coordToPoint(lng.Number(), lat.Number());
            out->cell = S2Cell(out->point);
        }
        return true;
    }
コード例 #2
0
ファイル: geoparser.cpp プロジェクト: ashleybrener/mongo
    bool GeoParser::parseCap(const BSONObj& obj, CapWithCRS *out) {
        if (isLegacyCenter(obj)) {
            BSONObjIterator typeIt(obj);
            BSONElement type = typeIt.next();
            BSONObjIterator objIt(type.embeddedObject());
            BSONElement center = objIt.next();
            if (!parseLegacyPoint(center.Obj(), &out->circle.center)) { return false; }
            BSONElement radius = objIt.next();
            out->circle.radius = radius.number();
            out->crs = FLAT;
        } else {
            verify(isLegacyCenterSphere(obj));
            BSONObjIterator typeIt(obj);
            BSONElement type = typeIt.next();
            BSONObjIterator objIt(type.embeddedObject());
            BSONObj centerObj = objIt.next().Obj();

            S2Point centerPoint;
            BSONObjIterator it(centerObj);
            BSONElement x = it.next();
            BSONElement y = it.next();
            centerPoint = coordToPoint(x.Number(), y.Number());
            BSONElement radiusElt = objIt.next();
            double radius = radiusElt.number();
            out->cap = S2Cap::FromAxisAngle(centerPoint, S1Angle::Radians(radius));
            out->circle.radius = radius;
            out->circle.center = Point(x.Number(), y.Number());
            out->crs = SPHERE;
        }
        return true;
    }
コード例 #3
0
ファイル: geoparser.cpp プロジェクト: Axv2/mongo
    static bool parsePoints(const vector<BSONElement>& coordElt, vector<S2Point>* out) {
        for (size_t i = 0; i < coordElt.size(); ++i) {
            const vector<BSONElement>& pointElt = coordElt[i].Array();
            if (pointElt.empty()) { continue; }
            out->push_back(coordToPoint(pointElt[0].Number(), pointElt[1].Number()));
        }

        return true;
    }
コード例 #4
0
ファイル: geoparser.cpp プロジェクト: Axv2/mongo
    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;
    }
コード例 #5
0
ファイル: geoparser.cpp プロジェクト: QiuYe/mongo
 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;
 }
コード例 #6
0
ファイル: geoparser.cpp プロジェクト: ashleybrener/mongo
    bool GeoParser::parseMultiPoint(const BSONObj &obj, MultiPointWithCRS *out) {
        out->points.clear();
        BSONElement coordElt = obj.getFieldDotted(GEOJSON_COORDINATES);
        const vector<BSONElement>& coordinates = coordElt.Array();
        out->points.resize(coordinates.size());
        out->cells.resize(coordinates.size());
        for (size_t i = 0; i < coordinates.size(); ++i) {
            const vector<BSONElement>& thisCoord = coordinates[i].Array();
            out->points[i] = coordToPoint(thisCoord[0].Number(), thisCoord[1].Number());
            out->cells[i] = S2Cell(out->points[i]);
        }

        return true;
    }
コード例 #7
0
ファイル: geoparser.cpp プロジェクト: QiuYe/mongo
 static S2Point coordsToPoint(const vector<BSONElement>& coordElt) {
     return coordToPoint(coordElt[0].Number(), coordElt[1].Number());
 }
コード例 #8
0
ファイル: geoparser.cpp プロジェクト: QiuYe/mongo
 void GeoParser::parseLegacyPoint(const BSONObj &obj, S2Point *out) {
     BSONObjIterator it(obj);
     BSONElement x = it.next();
     BSONElement y = it.next();
     *out = coordToPoint(x.number(), y.number());
 }