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; }
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; }
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; }
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; }
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; }
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; }
bool GeoParser::isPoint(const BSONObj &obj) { return isGeoJSONPoint(obj) || isLegacyPoint(obj); }
bool GeoParser::isIndexablePoint(const BSONObj &obj) { return isLegacyPoint(obj, true) || isGeoJSONPoint(obj); }