Esempio 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;
    }
Esempio n. 2
0
    bool GeoParser::parseMultiPolygon(const BSONObj &obj, MultiPolygonWithCRS *out) {
        vector<BSONElement> coordElt = obj.getFieldDotted(GEOJSON_COORDINATES).Array();
        out->polygons.mutableVector().clear();
        out->polygons.mutableVector().resize(coordElt.size());

        for (size_t i = 0; i < coordElt.size(); ++i) {
            out->polygons.mutableVector()[i] = new S2Polygon();
            if (!parseGeoJSONPolygonCoordinates(
                    coordElt[i].Array(), obj, out->polygons.vector()[i])) {
                return false;
            }
        }

        return true;
    }
Esempio 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;
 }