bool GeoParser::parseCap(const BSONObj& obj, CapWithCRS *out) { if (isLegacyCenter(obj)) { BSONObjIterator typeIt(obj); BSONElement type = typeIt.next(); BSONObjIterator objIt(type.embeddedObject()); BSONElement center = objIt.next(); if (!parseLegacyPoint(center.Obj(), &out->circle.center)) { return false; } BSONElement radius = objIt.next(); out->circle.radius = radius.number(); out->crs = FLAT; } else { verify(isLegacyCenterSphere(obj)); BSONObjIterator typeIt(obj); BSONElement type = typeIt.next(); BSONObjIterator objIt(type.embeddedObject()); BSONObj centerObj = objIt.next().Obj(); S2Point centerPoint; BSONObjIterator it(centerObj); BSONElement x = it.next(); BSONElement y = it.next(); centerPoint = coordToPoint(x.Number(), y.Number()); BSONElement radiusElt = objIt.next(); double radius = radiusElt.number(); out->cap = S2Cap::FromAxisAngle(centerPoint, S1Angle::Radians(radius)); out->circle.radius = radius; out->circle.center = Point(x.Number(), y.Number()); out->crs = SPHERE; } return true; }
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; }
void GeoParser::parseLegacyCenter(const BSONObj &obj, Circle *out) { BSONObjIterator typeIt(obj); BSONElement type = typeIt.next(); BSONObjIterator objIt(type.embeddedObject()); BSONElement center = objIt.next(); parseLegacyPoint(center.Obj(), &out->center); BSONElement radius = objIt.next(); out->radius = radius.number(); }
void GeoParser::parseLegacyBox(const BSONObj &obj, Box *out) { BSONObjIterator typeIt(obj); BSONElement type = typeIt.next(); BSONObjIterator coordIt(type.embeddedObject()); BSONElement minE = coordIt.next(); BSONElement maxE = coordIt.next(); parseLegacyPoint(minE.Obj(), &out->_min); parseLegacyPoint(maxE.Obj(), &out->_max); }
bool GeoParser::parseBox(const BSONObj &obj, BoxWithCRS *out) { BSONObjIterator typeIt(obj); BSONElement type = typeIt.next(); BSONObjIterator coordIt(type.embeddedObject()); BSONElement minE = coordIt.next(); BSONElement maxE = coordIt.next(); if (!parseLegacyPoint(minE.Obj(), &out->box._min) || !parseLegacyPoint(maxE.Obj(), &out->box._max)) { return false; } out->crs = FLAT; return true; }
void GeoParser::parseLegacyCenterSphere(const BSONObj &obj, S2Cap *out) { BSONObjIterator typeIt(obj); BSONElement type = typeIt.next(); BSONObjIterator objIt(type.embeddedObject()); BSONElement center = objIt.next(); S2Point centerPoint; parseLegacyPoint(center.Obj(), ¢erPoint); BSONElement radiusElt = objIt.next(); double radius = radiusElt.number(); *out = S2Cap::FromAxisAngle(centerPoint, S1Angle::Radians(radius)); }
void GeoParser::parseLegacyPolygon(const BSONObj &obj, Polygon *out) { BSONObjIterator typeIt(obj); BSONElement type = typeIt.next(); BSONObjIterator coordIt(type.embeddedObject()); vector<Point> points; while (coordIt.more()) { Point p; parseLegacyPoint(coordIt.next().Obj(), &p); points.push_back(p); } *out = Polygon(points); }
static bool isLegacyCenter(const BSONObj &obj) { BSONObjIterator typeIt(obj); BSONElement type = typeIt.next(); if (!type.isABSONObj()) { return false; } bool isCenter = mongoutils::str::equals(type.fieldName(), "$center"); if (!isCenter) { return false; } BSONObjIterator objIt(type.embeddedObject()); BSONElement center = objIt.next(); if (!center.isABSONObj()) { return false; } if (!isLegacyPoint(center.Obj())) { return false; } if (!objIt.more()) { return false; } BSONElement radius = objIt.next(); if (!radius.isNumber()) { return false; } return true; }
bool GeoParser::isLegacyBox(const BSONObj &obj) { BSONObjIterator typeIt(obj); BSONElement type = typeIt.next(); if (!type.isABSONObj()) { return false; } if (!mongoutils::str::equals(type.fieldName(), "$box")) { return false; } BSONObjIterator coordIt(type.embeddedObject()); BSONElement minE = coordIt.next(); if (!minE.isABSONObj()) { return false; } if (!isLegacyPoint(minE.Obj())) { return false; } if (!coordIt.more()) { return false; } BSONElement maxE = coordIt.next(); if (!maxE.isABSONObj()) { return false; } if (!isLegacyPoint(maxE.Obj())) { return false; } return true; }
static bool isLegacyPolygon(const BSONObj &obj) { BSONObjIterator typeIt(obj); BSONElement type = typeIt.next(); if (!type.isABSONObj()) { return false; } if (!mongoutils::str::equals(type.fieldName(), "$polygon")) { return false; } BSONObjIterator coordIt(type.embeddedObject()); int vertices = 0; while (coordIt.more()) { BSONElement coord = coordIt.next(); if (!coord.isABSONObj()) { return false; } if (!isLegacyPoint(coord.Obj())) { return false; } ++vertices; } if (vertices < 3) { return false; } return true; }
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; }
static bool isLegacyCenterSphere(const BSONObj &obj) { BSONObjIterator typeIt(obj); BSONElement type = typeIt.next(); if (!type.isABSONObj()) { return false; } bool isCenterSphere = mongoutils::str::equals(type.fieldName(), "$centerSphere"); if (!isCenterSphere) { return false; } BSONObjIterator objIt(type.embeddedObject()); BSONElement center = objIt.next(); if (!center.isABSONObj()) { return false; } if (!isLegacyPoint(center.Obj())) { return false; } // Check to make sure the points are valid lng/lat. BSONObjIterator coordIt(center.Obj()); BSONElement lng = coordIt.next(); BSONElement lat = coordIt.next(); if (!isValidLngLat(lng.Number(), lat.Number())) { return false; } if (!objIt.more()) { return false; } BSONElement radius = objIt.next(); if (!radius.isNumber()) { return false; } return true; }
bool KPrDeclarations::saveOdf(KoPASavingContext &paContext) const { /* <presentation:header-decl presentation:name="hdr1">header</presentation:header-decl> <presentation:footer-decl presentation:name="ftr1">Footer for the slide</presentation:footer-decl> <presentation:footer-decl presentation:name="ftr2">footer</presentation:footer-decl> <presentation:date-time-decl presentation:name="dtd1" presentation:source="current-date" style:data-style-name="D3"/> */ KoXmlWriter &writer(paContext.xmlWriter()); QHash<Type, QHash<QString, QVariant> >::const_iterator typeIt(m_declarations.constBegin()); for (; typeIt != m_declarations.constEnd(); ++typeIt) { QHash<QString, QVariant>::const_iterator keyIt(typeIt.value().begin()); for (; keyIt != typeIt.value().constEnd(); ++keyIt) { switch (typeIt.key()) { case Footer: writer.startElement("presentation:footer-decl"); break; case Header: writer.startElement("presentation:header-decl"); break; case DateTime: writer.startElement("presentation:date-time-decl"); break; } writer.addAttribute("presentation:name", keyIt.key()); if (typeIt.key() == DateTime) { //TODO } else { writer.addTextNode(keyIt.value().value<QString>()); } writer.endElement(); } } return true; }