From 882d84b086010e2a5088be11362db16217beab99 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Mon, 28 Dec 2020 17:07:44 +0100 Subject: C API: add proj_crs_is_derived() --- src/iso19111/c_api.cpp | 23 +++++++++++++++++++++++ src/proj.h | 2 ++ 2 files changed, 25 insertions(+) (limited to 'src') diff --git a/src/iso19111/c_api.cpp b/src/iso19111/c_api.cpp index cb0c113a..ae13b40d 100644 --- a/src/iso19111/c_api.cpp +++ b/src/iso19111/c_api.cpp @@ -1840,6 +1840,29 @@ PJ *proj_crs_get_geodetic_crs(PJ_CONTEXT *ctx, const PJ *crs) { // --------------------------------------------------------------------------- +/** \brief Returns whether a CRS is a derived CRS. + * + * @param ctx PROJ context, or NULL for default context + * @param crs Object of type CRS (must not be NULL) + * @return TRUE if the CRS is a derived CRS. + * @since 8.0 + */ +int proj_crs_is_derived(PJ_CONTEXT *ctx, const PJ *crs) { + if (!crs) { + proj_context_errno_set(ctx, PROJ_ERR_OTHER_API_MISUSE); + proj_log_error(ctx, __FUNCTION__, "missing required input"); + return false; + } + auto l_crs = dynamic_cast(crs->iso_obj.get()); + if (!l_crs) { + proj_log_error(ctx, __FUNCTION__, "Object is not a CRS"); + return false; + } + return dynamic_cast(l_crs) != nullptr; +} + +// --------------------------------------------------------------------------- + /** \brief Get a CRS component from a CompoundCRS * * The returned object must be unreferenced with proj_destroy() after diff --git a/src/proj.h b/src/proj.h index b16f54ea..4b417dc4 100644 --- a/src/proj.h +++ b/src/proj.h @@ -1271,6 +1271,8 @@ int PROJ_DLL proj_get_suggested_operation(PJ_CONTEXT *ctx, /* ------------------------------------------------------------------------- */ +int PROJ_DLL proj_crs_is_derived(PJ_CONTEXT *ctx, const PJ *crs); + PJ PROJ_DLL *proj_crs_get_geodetic_crs(PJ_CONTEXT *ctx, const PJ *crs); PJ PROJ_DLL *proj_crs_get_horizontal_datum(PJ_CONTEXT *ctx, const PJ *crs); -- cgit v1.2.3