diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/c_api.cpp | 30 | ||||
| -rw-r--r-- | src/crs.cpp | 34 | ||||
| -rw-r--r-- | src/factory.cpp | 32 | ||||
| -rw-r--r-- | src/proj.h | 3 |
4 files changed, 99 insertions, 0 deletions
diff --git a/src/c_api.cpp b/src/c_api.cpp index e1f34012..78ca1c24 100644 --- a/src/c_api.cpp +++ b/src/c_api.cpp @@ -791,6 +791,36 @@ int proj_obj_is_deprecated(const PJ_OBJ *obj) { // --------------------------------------------------------------------------- +/** \brief Return a list of non-deprecated objects related to the passed one + * + * @param ctx Context, or NULL for default context. + * @param obj Object (of type CRS for now) for which non-deprecated objects + * must be searched. Must not be NULL + * @return a result set that must be unreferenced with + * proj_obj_list_unref(), or NULL in case of error. + */ +PJ_OBJ_LIST *proj_obj_get_non_deprecated(PJ_CONTEXT *ctx, const PJ_OBJ *obj) { + assert(obj); + SANITIZE_CTX(ctx); + auto crs = dynamic_cast<const CRS *>(obj->obj.get()); + if (!crs) { + return nullptr; + } + try { + std::vector<IdentifiedObjectNNPtr> objects; + auto res = crs->getNonDeprecated(getDBcontext(ctx)); + for (const auto &resObj : res) { + objects.push_back(resObj); + } + return new PJ_OBJ_LIST(std::move(objects)); + } catch (const std::exception &e) { + proj_log_error(ctx, __FUNCTION__, e.what()); + } + return nullptr; +} + +// --------------------------------------------------------------------------- + /** \brief Return whether two objects are equivalent. * * @param obj Object (must not be NULL) diff --git a/src/crs.cpp b/src/crs.cpp index 6212f561..81e9a300 100644 --- a/src/crs.cpp +++ b/src/crs.cpp @@ -603,6 +603,40 @@ CRS::identify(const io::AuthorityFactoryPtr &authorityFactory) const { // --------------------------------------------------------------------------- +/** \brief Return CRSs that are non-deprecated substitutes for the current CRS. + */ +std::list<CRSNNPtr> +CRS::getNonDeprecated(const io::DatabaseContextNNPtr &dbContext) const { + std::list<CRSNNPtr> res; + const auto &l_identifiers = identifiers(); + if (l_identifiers.empty()) { + return res; + } + const char *tableName = nullptr; + if (dynamic_cast<const GeodeticCRS *>(this)) { + tableName = "geodetic_crs"; + } else if (dynamic_cast<const ProjectedCRS *>(this)) { + tableName = "projected_crs"; + } else if (dynamic_cast<const VerticalCRS *>(this)) { + tableName = "vertical_crs"; + } else if (dynamic_cast<const CompoundCRS *>(this)) { + tableName = "compound_crs"; + } + if (!tableName) { + return res; + } + const auto &id = l_identifiers[0]; + auto tmpRes = + dbContext->getNonDeprecated(tableName, *(id->codeSpace()), id->code()); + for (const auto &pair : tmpRes) { + res.emplace_back(io::AuthorityFactory::create(dbContext, pair.first) + ->createCoordinateReferenceSystem(pair.second)); + } + return res; +} + +// --------------------------------------------------------------------------- + //! @cond Doxygen_Suppress std::list<std::pair<CRSNNPtr, int>> diff --git a/src/factory.cpp b/src/factory.cpp index 20701def..d56fb7b6 100644 --- a/src/factory.cpp +++ b/src/factory.cpp @@ -918,6 +918,38 @@ std::vector<std::string> DatabaseContext::getAllowedAuthorities( return split(res[0][0], ','); } +// --------------------------------------------------------------------------- + +std::list<std::pair<std::string, std::string>> +DatabaseContext::getNonDeprecated(const std::string &tableName, + const std::string &authName, + const std::string &code) const { + auto sqlRes = + d->run("SELECT replacement_auth_name, replacement_code, source " + "FROM deprecation " + "WHERE table_name = ? AND deprecated_auth_name = ? " + "AND deprecated_code = ?", + {tableName, authName, code}); + std::list<std::pair<std::string, std::string>> res; + for (const auto &row : sqlRes) { + const auto &source = row[2]; + if (source == "PROJ") { + const auto &replacement_auth_name = row[0]; + const auto &replacement_code = row[1]; + res.emplace_back(replacement_auth_name, replacement_code); + } + } + if (!res.empty()) { + return res; + } + for (const auto &row : sqlRes) { + const auto &replacement_auth_name = row[0]; + const auto &replacement_code = row[1]; + res.emplace_back(replacement_auth_name, replacement_code); + } + return res; +} + //! @endcond // --------------------------------------------------------------------------- @@ -572,6 +572,9 @@ PJ_OBJ_TYPE PROJ_DLL proj_obj_get_type(const PJ_OBJ *obj); int PROJ_DLL proj_obj_is_deprecated(const PJ_OBJ *obj); +PJ_OBJ_LIST PROJ_DLL *proj_obj_get_non_deprecated(PJ_CONTEXT *ctx, + const PJ_OBJ *obj); + /** Comparison criterion. */ typedef enum { |
