diff options
| author | Even Rouault <even.rouault@spatialys.com> | 2018-12-04 23:32:19 +0100 |
|---|---|---|
| committer | Even Rouault <even.rouault@spatialys.com> | 2018-12-04 23:32:19 +0100 |
| commit | 419c3850211447b3a435442662f8fa12efd15cca (patch) | |
| tree | 6345a1a54ad7f5f1642e4ed90b8daf4cadb63bff /src | |
| parent | 724342895ee23496b92fc2b2c6e6fbf528cd3ba2 (diff) | |
| download | PROJ-419c3850211447b3a435442662f8fa12efd15cca.tar.gz PROJ-419c3850211447b3a435442662f8fa12efd15cca.zip | |
Add proj_obj_create_vertical_crs() and proj_obj_create_compound_crs()
Diffstat (limited to 'src')
| -rw-r--r-- | src/c_api.cpp | 80 | ||||
| -rw-r--r-- | src/proj_experimental.h | 11 |
2 files changed, 91 insertions, 0 deletions
diff --git a/src/c_api.cpp b/src/c_api.cpp index 718d46bf..a5ed1509 100644 --- a/src/c_api.cpp +++ b/src/c_api.cpp @@ -2101,6 +2101,86 @@ PJ_OBJ *proj_obj_create_geocentric_crs_from_datum(PJ_CONTEXT *ctx, // --------------------------------------------------------------------------- +/** \brief Create a VerticalCRS + * + * The returned object must be unreferenced with proj_obj_unref() 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_name Name of the GeographicCRS. Or NULL + * @param datum_name Name of the VerticalReferenceFrame. Or NULL + * @param linear_units Name of the linear units. Or NULL for Metre + * @param linear_units_conv Conversion factor from the linear unit to metre. Or + * 0 for Metre if linear_units == NULL. Otherwise should be not NULL + * + * @return Object of type VerticalCRS that must be unreferenced with + * proj_obj_unref(), or NULL in case of error. + */ +PJ_OBJ *proj_obj_create_vertical_crs(PJ_CONTEXT *ctx, const char *crs_name, + const char *datum_name, + const char *linear_units, + double linear_units_conv) { + + SANITIZE_CTX(ctx); + try { + const UnitOfMeasure linearUnit( + createLinearUnit(linear_units, linear_units_conv)); + auto datum = + VerticalReferenceFrame::create(createPropertyMapName(datum_name)); + auto vertCRS = VerticalCRS::create( + createPropertyMapName(crs_name), datum, + cs::VerticalCS::createGravityRelatedHeight(linearUnit)); + return PJ_OBJ::create(vertCRS); + } catch (const std::exception &e) { + proj_log_error(ctx, __FUNCTION__, e.what()); + } + return nullptr; +} + +// --------------------------------------------------------------------------- + +/** \brief Create a CompoundCRS + * + * The returned object must be unreferenced with proj_obj_unref() 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_name Name of the GeographicCRS. Or NULL + * @param horiz_crs Horizontal CRS. must not be NULL. + * @param vert_crs Vertical CRS. must not be NULL. + * + * @return Object of type CompoundCRS that must be unreferenced with + * proj_obj_unref(), or NULL in case of error. + */ +PJ_OBJ *proj_obj_create_compound_crs(PJ_CONTEXT *ctx, const char *crs_name, + PJ_OBJ *horiz_crs, PJ_OBJ *vert_crs) { + + assert(horiz_crs); + assert(vert_crs); + SANITIZE_CTX(ctx); + auto l_horiz_crs = util::nn_dynamic_pointer_cast<CRS>(horiz_crs->obj); + if (!l_horiz_crs) { + return nullptr; + } + auto l_vert_crs = util::nn_dynamic_pointer_cast<CRS>(vert_crs->obj); + if (!l_vert_crs) { + return nullptr; + } + try { + auto compoundCRS = CompoundCRS::create( + createPropertyMapName(crs_name), + {NN_NO_CHECK(l_horiz_crs), NN_NO_CHECK(l_vert_crs)}); + return PJ_OBJ::create(compoundCRS); + } catch (const std::exception &e) { + proj_log_error(ctx, __FUNCTION__, e.what()); + } + return nullptr; +} + +// --------------------------------------------------------------------------- + /** \brief Return a copy of the object with its name changed * * Currently, only implemented on CRS objects. diff --git a/src/proj_experimental.h b/src/proj_experimental.h index 1dc16f99..19cde6fc 100644 --- a/src/proj_experimental.h +++ b/src/proj_experimental.h @@ -187,6 +187,17 @@ PJ_OBJ PROJ_DLL *proj_obj_crs_alter_parameters_linear_unit(PJ_CONTEXT *ctx, PJ_OBJ PROJ_DLL *proj_obj_create_engineering_crs(PJ_CONTEXT *ctx, const char *crsName); +PJ_OBJ PROJ_DLL *proj_obj_create_vertical_crs(PJ_CONTEXT *ctx, + const char *crs_name, + const char *datum_name, + const char *linear_units, + double linear_units_conv); + +PJ_OBJ PROJ_DLL *proj_obj_create_compound_crs(PJ_CONTEXT *ctx, + const char *crs_name, + PJ_OBJ* horiz_crs, + PJ_OBJ* vert_crs); + /** Description of a parameter value for a Conversion. */ typedef struct { |
