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;
 }
示例#2
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;
 }
示例#3
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;
 }
示例#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
    bool GeoParser::isGeometryCollection(const BSONObj &obj) {
        BSONElement type = obj.getFieldDotted(GEOJSON_TYPE);
        if (type.eoo() || (String != type.type())) { return false; }
        if (GEOJSON_TYPE_GEOMETRY_COLLECTION != type.String()) { return false; }

        BSONElement coordElt = obj.getFieldDotted(GEOJSON_GEOMETRIES);
        if (coordElt.eoo() || (Array != coordElt.type())) { return false; }

        const vector<BSONElement>& coordinates = coordElt.Array();
        if (0 == coordinates.size()) { return false; }

        for (size_t i = 0; i < coordinates.size(); ++i) {
            if (coordinates[i].eoo() || (Object != coordinates[i].type())) { return false; }
            BSONObj obj = coordinates[i].Obj();
            if (!isGeoJSONPoint(obj) && !isLine(obj) && !isGeoJSONPolygon(obj)
                && !isMultiPoint(obj) && !isMultiPolygon(obj) && !isMultiLine(obj)) {
                return false;
            }
        }

        return true;
    }
示例#6
0
    bool GeoParser::parseGeometryCollection(const BSONObj &obj, GeometryCollection *out) {
        BSONElement coordElt = obj.getFieldDotted(GEOJSON_GEOMETRIES);
        const vector<BSONElement>& geometries = coordElt.Array();

        for (size_t i = 0; i < geometries.size(); ++i) {
            const BSONObj& geoObj = geometries[i].Obj();

            if (isGeoJSONPoint(geoObj)) {
                PointWithCRS point;
                if (!parsePoint(geoObj, &point)) { return false; }
                out->points.push_back(point);
            } else if (isLine(geoObj)) {
                out->lines.mutableVector().push_back(new LineWithCRS());
                if (!parseLine(geoObj, out->lines.vector().back())) { return false; }
            } else if (isGeoJSONPolygon(geoObj)) {
                out->polygons.mutableVector().push_back(new PolygonWithCRS());
                if (!parsePolygon(geoObj, out->polygons.vector().back())) { return false; }
            } else if (isMultiPoint(geoObj)) {
                out->multiPoints.mutableVector().push_back(new MultiPointWithCRS());
                if (!parseMultiPoint(geoObj, out->multiPoints.mutableVector().back())) {
                    return false;
                }
            } else if (isMultiPolygon(geoObj)) {
                out->multiPolygons.mutableVector().push_back(new MultiPolygonWithCRS());
                if (!parseMultiPolygon(geoObj, out->multiPolygons.mutableVector().back())) {
                    return false;
                }
            } else {
                verify(isMultiLine(geoObj));
                out->multiLines.mutableVector().push_back(new MultiLineWithCRS());
                if (!parseMultiLine(geoObj, out->multiLines.mutableVector().back())) {
                    return false;
                }
            }
        }

        return true;
    }
示例#7
0
 bool GeoParser::isPoint(const BSONObj &obj) {
     return isGeoJSONPoint(obj) || isLegacyPoint(obj);
 }
示例#8
0
 bool GeoParser::isIndexablePoint(const BSONObj &obj) {
     return isLegacyPoint(obj, true) || isGeoJSONPoint(obj);
 }