aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEven Rouault <even.rouault@spatialys.com>2018-12-10 22:18:47 +0100
committerEven Rouault <even.rouault@spatialys.com>2018-12-10 22:18:47 +0100
commitb51e1159cc59df1bc89f521ed0217f86550fd941 (patch)
treef1d551b0a6ed2daab9a972d76f5ad8f64d3e2185
parent3e4fe5e6b5ddec8d426606ca996a81eced154adf (diff)
downloadPROJ-b51e1159cc59df1bc89f521ed0217f86550fd941.tar.gz
PROJ-b51e1159cc59df1bc89f521ed0217f86550fd941.zip
C API: add a proj_coordoperation_get_method_info() method
-rw-r--r--src/c_api.cpp49
-rw-r--r--src/proj.h11
-rw-r--r--test/unit/test_c_api.cpp33
3 files changed, 62 insertions, 31 deletions
diff --git a/src/c_api.cpp b/src/c_api.cpp
index 539675e2..230b4492 100644
--- a/src/c_api.cpp
+++ b/src/c_api.cpp
@@ -1914,19 +1914,10 @@ void proj_free_string_list(PROJ_STRING_LIST list) {
*
* @param ctx PROJ context, or NULL for default context
* @param crs Objet of type DerivedCRS or BoundCRSs (must not be NULL)
- * @param out_method_name Pointer to a string value to store the method
- * (projection) name. or NULL
- * @param out_method_auth_name Pointer to a string value to store the method
- * authority name. or NULL
- * @param out_method_code Pointer to a string value to store the method
- * code. or NULL
* @return Object of type SingleOperation that must be unreferenced with
* proj_obj_unref(), or NULL in case of error.
*/
-PJ_OBJ *proj_obj_crs_get_coordoperation(PJ_CONTEXT *ctx, const PJ_OBJ *crs,
- const char **out_method_name,
- const char **out_method_auth_name,
- const char **out_method_code) {
+PJ_OBJ *proj_obj_crs_get_coordoperation(PJ_CONTEXT *ctx, const PJ_OBJ *crs) {
SANITIZE_CTX(ctx);
assert(crs);
SingleOperationPtr co;
@@ -1945,7 +1936,41 @@ PJ_OBJ *proj_obj_crs_get_coordoperation(PJ_CONTEXT *ctx, const PJ_OBJ *crs,
}
}
- const auto &method = co->method();
+ return PJ_OBJ::create(NN_NO_CHECK(co));
+}
+
+// ---------------------------------------------------------------------------
+
+/** \brief Return informatin on the operation method of the SingleOperation.
+ *
+ * @param ctx PROJ context, or NULL for default context
+ * @param coordoperation Objet of type SingleOperation (typically a Conversion
+ * or Transformation) (must not be NULL)
+ * @param out_method_name Pointer to a string value to store the method
+ * (projection) name. or NULL
+ * @param out_method_auth_name Pointer to a string value to store the method
+ * authority name. or NULL
+ * @param out_method_code Pointer to a string value to store the method
+ * code. or NULL
+ * @return TRUE in case of success.
+ */
+int proj_coordoperation_get_method_info(PJ_CONTEXT *ctx,
+ const PJ_OBJ *coordoperation,
+ const char **out_method_name,
+ const char **out_method_auth_name,
+ const char **out_method_code) {
+ SANITIZE_CTX(ctx);
+ assert(coordoperation);
+
+ auto singleOp =
+ dynamic_cast<const SingleOperation *>(coordoperation->obj.get());
+ if (!singleOp) {
+ proj_log_error(ctx, __FUNCTION__,
+ "Object is not a DerivedCRS or BoundCRS");
+ return false;
+ }
+
+ const auto &method = singleOp->method();
const auto &method_ids = method->identifiers();
if (out_method_name) {
*out_method_name = method->name()->description()->c_str();
@@ -1964,7 +1989,7 @@ PJ_OBJ *proj_obj_crs_get_coordoperation(PJ_CONTEXT *ctx, const PJ_OBJ *crs,
*out_method_code = nullptr;
}
}
- return PJ_OBJ::create(NN_NO_CHECK(co));
+ return true;
}
// ---------------------------------------------------------------------------
diff --git a/src/proj.h b/src/proj.h
index 295ecc23..7dbd23c1 100644
--- a/src/proj.h
+++ b/src/proj.h
@@ -872,10 +872,13 @@ int PROJ_DLL proj_obj_prime_meridian_get_parameters(PJ_CONTEXT *ctx,
const char **out_unit_name);
PJ_OBJ PROJ_DLL *proj_obj_crs_get_coordoperation(PJ_CONTEXT *ctx,
- const PJ_OBJ *crs,
- const char **out_method_name,
- const char **out_method_auth_name,
- const char **out_method_code);
+ const PJ_OBJ *crs);
+
+int PROJ_DLL proj_coordoperation_get_method_info(PJ_CONTEXT *ctx,
+ const PJ_OBJ *coordoperation,
+ const char **out_method_name,
+ const char **out_method_auth_name,
+ const char **out_method_code);
int PROJ_DLL proj_coordoperation_is_instanciable(PJ_CONTEXT *ctx,
const PJ_OBJ *coordoperation);
diff --git a/test/unit/test_c_api.cpp b/test/unit/test_c_api.cpp
index cb355892..a49e9501 100644
--- a/test/unit/test_c_api.cpp
+++ b/test/unit/test_c_api.cpp
@@ -422,8 +422,7 @@ TEST_F(CApi, proj_obj_crs_create_bound_crs_to_WGS84) {
ObjectKeeper keeper_hub_crs(hub_crs);
ASSERT_NE(hub_crs, nullptr);
- auto transf =
- proj_obj_crs_get_coordoperation(m_ctxt, res, nullptr, nullptr, nullptr);
+ auto transf = proj_obj_crs_get_coordoperation(m_ctxt, res);
ObjectKeeper keeper_transf(transf);
ASSERT_NE(transf, nullptr);
@@ -998,24 +997,30 @@ TEST_F(CApi, conversion) {
ASSERT_NE(crs, nullptr);
ObjectKeeper keeper(crs);
+ // invalid object type
+ EXPECT_FALSE(proj_coordoperation_get_method_info(m_ctxt, crs, nullptr,
+ nullptr, nullptr));
+
{
- auto conv = proj_obj_crs_get_coordoperation(m_ctxt, crs, nullptr,
- nullptr, nullptr);
+ auto conv = proj_obj_crs_get_coordoperation(m_ctxt, crs);
ASSERT_NE(conv, nullptr);
ObjectKeeper keeper_conv(conv);
- ASSERT_EQ(proj_obj_crs_get_coordoperation(m_ctxt, conv, nullptr,
- nullptr, nullptr),
- nullptr);
+ ASSERT_EQ(proj_obj_crs_get_coordoperation(m_ctxt, conv), nullptr);
}
+ auto conv = proj_obj_crs_get_coordoperation(m_ctxt, crs);
+ ASSERT_NE(conv, nullptr);
+ ObjectKeeper keeper_conv(conv);
+
+ EXPECT_TRUE(proj_coordoperation_get_method_info(m_ctxt, conv, nullptr,
+ nullptr, nullptr));
+
const char *methodName = nullptr;
const char *methodAuthorityName = nullptr;
const char *methodCode = nullptr;
- auto conv = proj_obj_crs_get_coordoperation(
- m_ctxt, crs, &methodName, &methodAuthorityName, &methodCode);
- ASSERT_NE(conv, nullptr);
- ObjectKeeper keeper_conv(conv);
+ EXPECT_TRUE(proj_coordoperation_get_method_info(
+ m_ctxt, conv, &methodName, &methodAuthorityName, &methodCode));
ASSERT_NE(methodName, nullptr);
ASSERT_NE(methodAuthorityName, nullptr);
@@ -1069,8 +1074,7 @@ TEST_F(CApi, transformation_from_boundCRS) {
ASSERT_NE(crs, nullptr);
ObjectKeeper keeper(crs);
- auto transf =
- proj_obj_crs_get_coordoperation(m_ctxt, crs, nullptr, nullptr, nullptr);
+ auto transf = proj_obj_crs_get_coordoperation(m_ctxt, crs);
ASSERT_NE(transf, nullptr);
ObjectKeeper keeper_transf(transf);
}
@@ -2536,8 +2540,7 @@ TEST_F(CApi, proj_obj_convert_conversion_to_other_method) {
m_ctxt, projCRS, EPSG_CODE_METHOD_MERCATOR_VARIANT_B, nullptr),
nullptr);
- auto conv_in_proj = proj_obj_crs_get_coordoperation(
- m_ctxt, projCRS, nullptr, nullptr, nullptr);
+ auto conv_in_proj = proj_obj_crs_get_coordoperation(m_ctxt, projCRS);
ObjectKeeper keeper_conv_in_proj(conv_in_proj);
ASSERT_NE(conv_in_proj, nullptr);