Ejemplo n.º 1
0
    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;
    }
Ejemplo n.º 2
0
 bool GeoParser::parsePolygon(const BSONObj &obj, S2Polygon *out) {
     if (isGeoJSONPolygon(obj)) {
         parseGeoJSONPolygon(obj, out);
         return true;
     } else {
         return false;
     }
 }
Ejemplo n.º 3
0
 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;
 }
Ejemplo n.º 4
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;
    }
Ejemplo n.º 5
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;
    }
Ejemplo n.º 6
0
 bool GeoParser::isPolygon(const BSONObj &obj) {
     return isGeoJSONPolygon(obj) || isLegacyPolygon(obj);
 }