| 1977 | // --------------------------------------------------------------------------- |
| 1978 | |
| 1979 | UnitOfMeasure WKTParser::Private::buildUnit(const WKTNodeNNPtr &node, |
| 1980 | UnitOfMeasure::Type type) { |
| 1981 | const auto *nodeP = node->GP(); |
| 1982 | const auto &children = nodeP->children(); |
| 1983 | if ((type != UnitOfMeasure::Type::TIME && children.size() < 2) || |
| 1984 | (type == UnitOfMeasure::Type::TIME && children.size() < 1)) { |
| 1985 | ThrowNotEnoughChildren(nodeP->value()); |
| 1986 | } |
| 1987 | try { |
| 1988 | std::string unitName(stripQuotes(children[0])); |
| 1989 | PropertyMap properties(buildProperties(node)); |
| 1990 | auto &idNode = |
| 1991 | nodeP->lookForChild(WKTConstants::ID, WKTConstants::AUTHORITY); |
| 1992 | if (!isNull(idNode) && idNode->GP()->childrenSize() < 2) { |
| 1993 | emitRecoverableWarning("not enough children in " + |
| 1994 | idNode->GP()->value() + " node"); |
| 1995 | } |
| 1996 | const bool hasValidIdNode = |
| 1997 | !isNull(idNode) && idNode->GP()->childrenSize() >= 2; |
| 1998 | |
| 1999 | const auto &idNodeChildren(idNode->GP()->children()); |
| 2000 | std::string codeSpace(hasValidIdNode ? stripQuotes(idNodeChildren[0]) |
| 2001 | : std::string()); |
| 2002 | std::string code(hasValidIdNode ? stripQuotes(idNodeChildren[1]) |
| 2003 | : std::string()); |
| 2004 | |
| 2005 | bool queryDb = true; |
| 2006 | if (type == UnitOfMeasure::Type::UNKNOWN) { |
| 2007 | if (ci_equal(unitName, "METER") || ci_equal(unitName, "METRE")) { |
| 2008 | type = UnitOfMeasure::Type::LINEAR; |
| 2009 | unitName = "metre"; |
| 2010 | if (codeSpace.empty()) { |
| 2011 | codeSpace = Identifier::EPSG; |
| 2012 | code = "9001"; |
| 2013 | queryDb = false; |
| 2014 | } |
| 2015 | } else if (ci_equal(unitName, "DEGREE") || |
| 2016 | ci_equal(unitName, "GRAD")) { |
| 2017 | type = UnitOfMeasure::Type::ANGULAR; |
| 2018 | } |
| 2019 | } |
| 2020 | |
| 2021 | if (esriStyle_ && dbContext_ && queryDb) { |
| 2022 | std::string outTableName; |
| 2023 | std::string authNameFromAlias; |
| 2024 | std::string codeFromAlias; |
| 2025 | auto authFactory = AuthorityFactory::create(NN_NO_CHECK(dbContext_), |
| 2026 | std::string()); |
| 2027 | auto officialName = authFactory->getOfficialNameFromAlias( |
| 2028 | unitName, "unit_of_measure", "ESRI", false, outTableName, |
| 2029 | authNameFromAlias, codeFromAlias); |
| 2030 | if (!officialName.empty()) { |
| 2031 | unitName = std::move(officialName); |
| 2032 | codeSpace = std::move(authNameFromAlias); |
| 2033 | code = std::move(codeFromAlias); |
| 2034 | } |
| 2035 | } |
| 2036 |
no test coverage detected