Esempio n. 1
0
    bool GeoParser::isGeoJSONPolygon(const BSONObj& obj) {
        BSONElement type = obj.getFieldDotted(GEOJSON_TYPE);
        if (type.eoo() || (String != type.type())) { return false; }
        if (GEOJSON_TYPE_POLYGON != type.String()) { return false; }

        if (!crsIsOK(obj)) {
            warning() << "Invalid CRS: " << obj.toString() << endl;
            return false;
        }

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

        const vector<BSONElement>& coordinates = coordElt.Array();
        // Must be at least one element, the outer shell
        if (coordinates.empty()) { return false; }
        // Verify that the shell is a bunch'a coordinates.
        for (size_t i = 0; i < coordinates.size(); ++i) {
            if (Array != coordinates[i].type()) { return false; }
            const vector<BSONElement>& thisLoop = coordinates[i].Array();
            // A triangle is the simplest 2d shape, and we repeat a vertex, so, 4.
            if (thisLoop.size() < 4) { return false; }
            if (!isArrayOfCoordinates(thisLoop)) { return false; }
            if (!isLoopClosed(thisLoop)) { return false; }
        }
        return true;
    }
Esempio n. 2
0
 static bool isGeoJSONPolygonCoordinates(const vector<BSONElement>& coordinates) {
     // Must be at least one element, the outer shell
     if (coordinates.empty()) { return false; }
     // Verify that the shell is a bunch'a coordinates.
     for (size_t i = 0; i < coordinates.size(); ++i) {
         if (Array != coordinates[i].type()) { return false; }
         const vector<BSONElement>& thisLoop = coordinates[i].Array();
         // A triangle is the simplest 2d shape, and we repeat a vertex, so, 4.
         if (thisLoop.size() < 4) { return false; }
         if (!isArrayOfCoordinates(thisLoop)) { return false; }
         if (!isLoopClosed(thisLoop)) { return false; }
     }
     return true;
 }