diff options
| author | Even Rouault <even.rouault@spatialys.com> | 2018-12-10 23:55:00 +0100 |
|---|---|---|
| committer | Even Rouault <even.rouault@spatialys.com> | 2018-12-10 23:55:00 +0100 |
| commit | c2c2e5d7f22f3c44c188200717236cf23547ac6f (patch) | |
| tree | 1010b53e93ff7b407f4c09706868e2be69332900 | |
| parent | b51e1159cc59df1bc89f521ed0217f86550fd941 (diff) | |
| download | PROJ-c2c2e5d7f22f3c44c188200717236cf23547ac6f.tar.gz PROJ-c2c2e5d7f22f3c44c188200717236cf23547ac6f.zip | |
C API: add extra output parameters to proj_coordoperation_get_param()
| -rw-r--r-- | src/c_api.cpp | 114 | ||||
| -rw-r--r-- | src/coordinateoperation.cpp | 2 | ||||
| -rw-r--r-- | src/proj.h | 5 | ||||
| -rw-r--r-- | test/unit/test_c_api.cpp | 30 |
4 files changed, 99 insertions, 52 deletions
diff --git a/src/c_api.cpp b/src/c_api.cpp index 230b4492..496312f7 100644 --- a/src/c_api.cpp +++ b/src/c_api.cpp @@ -526,6 +526,38 @@ PJ_OBJ *proj_obj_create_from_database(PJ_CONTEXT *ctx, const char *auth_name, // --------------------------------------------------------------------------- +//! @cond Doxygen_Suppress +static const char *get_unit_category(UnitOfMeasure::Type type) { + const char *ret = nullptr; + switch (type) { + case UnitOfMeasure::Type::UNKNOWN: + ret = "unknown"; + break; + case UnitOfMeasure::Type::NONE: + ret = "none"; + break; + case UnitOfMeasure::Type::ANGULAR: + ret = "angular"; + break; + case UnitOfMeasure::Type::LINEAR: + ret = "linear"; + break; + case UnitOfMeasure::Type::SCALE: + ret = "scale"; + break; + case UnitOfMeasure::Type::TIME: + ret = "time"; + break; + case UnitOfMeasure::Type::PARAMETRIC: + ret = "parametric"; + break; + } + return ret; +} +//! @endcond + +// --------------------------------------------------------------------------- + /** \brief Get information for a unit of measure from a database lookup. * * @param ctx Context, or NULL for default context. @@ -559,29 +591,7 @@ int proj_uom_get_info_from_database(PJ_CONTEXT *ctx, const char *auth_name, *out_conv_factor = obj->conversionToSI(); } if (out_category) { - switch (obj->type()) { - case UnitOfMeasure::Type::UNKNOWN: - *out_category = "unknown"; - break; - case UnitOfMeasure::Type::NONE: - *out_category = "none"; - break; - case UnitOfMeasure::Type::ANGULAR: - *out_category = "angular"; - break; - case UnitOfMeasure::Type::LINEAR: - *out_category = "linear"; - break; - case UnitOfMeasure::Type::SCALE: - *out_category = "scale"; - break; - case UnitOfMeasure::Type::TIME: - *out_category = "time"; - break; - case UnitOfMeasure::Type::PARAMETRIC: - *out_category = "parametric"; - break; - } + *out_category = get_unit_category(obj->type()); } return true; } catch (const std::exception &e) { @@ -5320,16 +5330,24 @@ int proj_coordoperation_get_param_index(PJ_CONTEXT *ctx, * unit conversion factor. or NULL * @param out_unit_name Pointer to a string value to store the parameter * unit name. or NULL + * @param out_unit_auth_name Pointer to a string value to store the + * unit authority name. or NULL + * @param out_unit_code Pointer to a string value to store the + * unit code. or NULL + * @param out_unit_category Pointer to a string value to store the parameter + * name. or + * NULL. This value might be "unknown", "none", "linear", "angular", "scale", + * "time" or "parametric"; * @return TRUE in case of success. */ -int proj_coordoperation_get_param(PJ_CONTEXT *ctx, const PJ_OBJ *coordoperation, - int index, const char **out_name, - const char **out_auth_name, - const char **out_code, double *out_value, - const char **out_value_string, - double *out_unit_conv_factor, - const char **out_unit_name) { +int proj_coordoperation_get_param( + PJ_CONTEXT *ctx, const PJ_OBJ *coordoperation, int index, + const char **out_name, const char **out_auth_name, const char **out_code, + double *out_value, const char **out_value_string, + double *out_unit_conv_factor, const char **out_unit_name, + const char **out_unit_auth_name, const char **out_unit_code, + const char **out_unit_category) { SANITIZE_CTX(ctx); assert(coordoperation); auto op = dynamic_cast<const SingleOperation *>(coordoperation->obj.get()); @@ -5392,18 +5410,36 @@ int proj_coordoperation_get_param(PJ_CONTEXT *ctx, const PJ_OBJ *coordoperation, } if (out_unit_conv_factor) { *out_unit_conv_factor = 0; - if (paramValue) { - if (paramValue->type() == ParameterValue::Type::MEASURE) { - *out_unit_conv_factor = - paramValue->value().unit().conversionToSI(); - } - } } if (out_unit_name) { *out_unit_name = nullptr; - if (paramValue) { - if (paramValue->type() == ParameterValue::Type::MEASURE) { - *out_unit_name = paramValue->value().unit().name().c_str(); + } + if (out_unit_auth_name) { + *out_unit_auth_name = nullptr; + } + if (out_unit_code) { + *out_unit_code = nullptr; + } + if (out_unit_category) { + *out_unit_category = nullptr; + } + if (paramValue) { + if (paramValue->type() == ParameterValue::Type::MEASURE) { + const auto &unit = paramValue->value().unit(); + if (out_unit_conv_factor) { + *out_unit_conv_factor = unit.conversionToSI(); + } + if (out_unit_name) { + *out_unit_name = unit.name().c_str(); + } + if (out_unit_auth_name) { + *out_unit_auth_name = unit.codeSpace().c_str(); + } + if (out_unit_code) { + *out_unit_code = unit.code().c_str(); + } + if (out_unit_category) { + *out_unit_category = get_unit_category(unit.type()); } } } diff --git a/src/coordinateoperation.cpp b/src/coordinateoperation.cpp index 3fa5ea9c..654692fb 100644 --- a/src/coordinateoperation.cpp +++ b/src/coordinateoperation.cpp @@ -2258,7 +2258,7 @@ createParams(const common::Measure &m1, const common::Measure &m2, *(https://proj4.org/operations/projections/utm.html) conversion. * * UTM is a family of conversions, of EPSG codes from 16001 to 16060 for the - * northern hemisphere, and 17001 t 17060 for the southern hemisphere, + * northern hemisphere, and 17001 to 17060 for the southern hemisphere, * based on the Transverse Mercator projection method. * * @param properties See \ref general_properties of the conversion. If the name @@ -899,7 +899,10 @@ int PROJ_DLL proj_coordoperation_get_param(PJ_CONTEXT *ctx, double *out_value, const char **out_value_string, double *out_unit_conv_factor, - const char **out_unit_name); + const char **out_unit_name, + const char **out_unit_auth_name, + const char **out_unit_code, + const char **out_unit_category); int PROJ_DLL proj_coordoperation_get_grid_used_count(PJ_CONTEXT *ctx, const PJ_OBJ *coordoperation); diff --git a/test/unit/test_c_api.cpp b/test/unit/test_c_api.cpp index a49e9501..772519ea 100644 --- a/test/unit/test_c_api.cpp +++ b/test/unit/test_c_api.cpp @@ -990,10 +990,8 @@ TEST_F(CApi, proj_get_codes_from_database) { // --------------------------------------------------------------------------- TEST_F(CApi, conversion) { - auto crs = proj_obj_create_from_wkt( - m_ctxt, - createProjectedCRS()->exportToWKT(WKTFormatter::create().get()).c_str(), - nullptr); + auto crs = proj_obj_create_from_database( + m_ctxt, "EPSG", "32631", PJ_OBJ_CATEGORY_CRS, false, nullptr); ASSERT_NE(crs, nullptr); ObjectKeeper keeper(crs); @@ -1034,12 +1032,12 @@ TEST_F(CApi, conversion) { EXPECT_EQ( proj_coordoperation_get_param_index(m_ctxt, conv, "False easting"), 3); - EXPECT_FALSE(proj_coordoperation_get_param(m_ctxt, conv, -1, nullptr, - nullptr, nullptr, nullptr, - nullptr, nullptr, nullptr)); - EXPECT_FALSE(proj_coordoperation_get_param(m_ctxt, conv, 5, nullptr, - nullptr, nullptr, nullptr, - nullptr, nullptr, nullptr)); + EXPECT_FALSE(proj_coordoperation_get_param( + m_ctxt, conv, -1, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, + nullptr, nullptr, nullptr, nullptr)); + EXPECT_FALSE(proj_coordoperation_get_param( + m_ctxt, conv, 5, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, + nullptr, nullptr, nullptr, nullptr)); const char *name = nullptr; const char *nameAuthorityName = nullptr; @@ -1048,20 +1046,30 @@ TEST_F(CApi, conversion) { const char *valueString = nullptr; double valueUnitConvFactor = 0; const char *valueUnitName = nullptr; + const char *unitAuthName = nullptr; + const char *unitCode = nullptr; + const char *unitCategory = nullptr; EXPECT_TRUE(proj_coordoperation_get_param( m_ctxt, conv, 3, &name, &nameAuthorityName, &nameCode, &value, - &valueString, &valueUnitConvFactor, &valueUnitName)); + &valueString, &valueUnitConvFactor, &valueUnitName, &unitAuthName, + &unitCode, &unitCategory)); ASSERT_NE(name, nullptr); ASSERT_NE(nameAuthorityName, nullptr); ASSERT_NE(nameCode, nullptr); EXPECT_EQ(valueString, nullptr); ASSERT_NE(valueUnitName, nullptr); + ASSERT_NE(unitAuthName, nullptr); + ASSERT_NE(unitCategory, nullptr); + ASSERT_NE(unitCategory, nullptr); EXPECT_EQ(name, std::string("False easting")); EXPECT_EQ(nameAuthorityName, std::string("EPSG")); EXPECT_EQ(nameCode, std::string("8806")); EXPECT_EQ(value, 500000.0); EXPECT_EQ(valueUnitConvFactor, 1.0); EXPECT_EQ(valueUnitName, std::string("metre")); + EXPECT_EQ(unitAuthName, std::string("EPSG")); + EXPECT_EQ(unitCode, std::string("9001")); + EXPECT_EQ(unitCategory, std::string("linear")); } // --------------------------------------------------------------------------- |
