diff options
| author | Even Rouault <even.rouault@spatialys.com> | 2019-10-04 11:45:43 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-10-04 11:45:43 +0200 |
| commit | 2bac8760df976adb3e112f98cfcbfc5d9d90e22a (patch) | |
| tree | 72a481a5887fec8401e4b825c38d3747d2b23911 /src/iso19111/c_api.cpp | |
| parent | 7bfef6a9c94482826a41687f795b1a991e17ed35 (diff) | |
| parent | ae779eaa8264914a401f585f747a0f87fd5350e9 (diff) | |
| download | PROJ-2bac8760df976adb3e112f98cfcbfc5d9d90e22a.tar.gz PROJ-2bac8760df976adb3e112f98cfcbfc5d9d90e22a.zip | |
Merge pull request #1656 from rouault/demote_to_2D
Add a proj_crs_demote_to_2D(). Useful if forced to export a 3D CRS to a best approximate as WKT1 that doesn't support it
Diffstat (limited to 'src/iso19111/c_api.cpp')
| -rw-r--r-- | src/iso19111/c_api.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/iso19111/c_api.cpp b/src/iso19111/c_api.cpp index ac3a5f11..4fedbe05 100644 --- a/src/iso19111/c_api.cpp +++ b/src/iso19111/c_api.cpp @@ -3388,6 +3388,48 @@ PJ *proj_crs_create_projected_3D_crs_from_2D(PJ_CONTEXT *ctx, // --------------------------------------------------------------------------- +/** \brief Create a 2D CRS from an existing 3D CRS. + * + * See osgeo::proj::crs::CRS::demoteTo2D(). + * + * The returned object must be unreferenced with proj_destroy() after + * use. + * It should be used by at most one thread at a time. + * + * @param ctx PROJ context, or NULL for default context + * @param crs_2D_name CRS name. Or NULL (in which case the name of crs_3D + * will be used) + * @param crs_3D 3D CRS to be "demoted" to 2D. Must not be NULL. + * + * @return Object that must be unreferenced with + * proj_destroy(), or NULL in case of error. + * @since 7.0 + */ +PJ *proj_crs_demote_to_2D(PJ_CONTEXT *ctx, const char *crs_2D_name, + const PJ *crs_3D) { + SANITIZE_CTX(ctx); + auto cpp_3D_crs = dynamic_cast<const CRS *>(crs_3D->iso_obj.get()); + if (!cpp_3D_crs) { + proj_log_error(ctx, __FUNCTION__, "crs_3D is not a CRS"); + return nullptr; + } + try { + auto dbContext = getDBcontextNoException(ctx, __FUNCTION__); + return pj_obj_create( + ctx, cpp_3D_crs->demoteTo2D(crs_2D_name ? std::string(crs_2D_name) + : cpp_3D_crs->nameStr(), + dbContext)); + } catch (const std::exception &e) { + proj_log_error(ctx, __FUNCTION__, e.what()); + if (ctx->cpp_context) { + ctx->cpp_context->autoCloseDbIfNeeded(); + } + return nullptr; + } +} + +// --------------------------------------------------------------------------- + /** \brief Instantiate a EngineeringCRS with just a name * * The returned object must be unreferenced with proj_destroy() after |
