aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEven Rouault <even.rouault@spatialys.com>2018-12-07 18:22:53 +0100
committerEven Rouault <even.rouault@spatialys.com>2018-12-07 18:37:08 +0100
commit29b522b4b80b43fe03cb1a955789676eec8051e7 (patch)
treeff8f3fd0352a147c590acdc9edf3137d5426d9f4
parent263b259b276edd075b0abcd6aad0e923230c2d15 (diff)
downloadPROJ-29b522b4b80b43fe03cb1a955789676eec8051e7.tar.gz
PROJ-29b522b4b80b43fe03cb1a955789676eec8051e7.zip
Experimental C API: add proj_obj_query_geodetic_crs_from_datum() (for GDAL Idrisi driver)
-rw-r--r--src/c_api.cpp36
-rw-r--r--src/proj_experimental.h7
-rw-r--r--test/unit/test_c_api.cpp19
3 files changed, 62 insertions, 0 deletions
diff --git a/src/c_api.cpp b/src/c_api.cpp
index 03a0c0bd..9d66071b 100644
--- a/src/c_api.cpp
+++ b/src/c_api.cpp
@@ -522,6 +522,42 @@ PJ_OBJ *proj_obj_create_from_database(PJ_CONTEXT *ctx, const char *auth_name,
// ---------------------------------------------------------------------------
+/** \brief Return GeodeticCRS that use the specified datum.
+ *
+ * @param ctx Context, or NULL for default context.
+ * @param crs_auth_name CRS authority name, or NULL.
+ * @param datum_auth_name Datum authority name (must not be NULL)
+ * @param datum_code Datum code (must not be NULL)
+ * @param crs_type "geographic 2D", "geographic 3D", "geocentric" or NULL
+ * @return a result set that must be unreferenced with
+ * proj_obj_list_unref(), or NULL in case of error.
+ */
+PJ_OBJ_LIST *proj_obj_query_geodetic_crs_from_datum(PJ_CONTEXT *ctx,
+ const char *crs_auth_name,
+ const char *datum_auth_name,
+ const char *datum_code,
+ const char *crs_type) {
+ assert(datum_auth_name);
+ assert(datum_code);
+ SANITIZE_CTX(ctx);
+ try {
+ auto factory = AuthorityFactory::create(
+ getDBcontext(ctx), crs_auth_name ? crs_auth_name : "");
+ auto res = factory->createGeodeticCRSFromDatum(
+ datum_auth_name, datum_code, crs_type ? crs_type : "");
+ std::vector<IdentifiedObjectNNPtr> objects;
+ for (const auto &obj : res) {
+ objects.push_back(obj);
+ }
+ return new PJ_OBJ_LIST(std::move(objects));
+ } catch (const std::exception &e) {
+ proj_log_error(ctx, __FUNCTION__, e.what());
+ }
+ return nullptr;
+}
+
+// ---------------------------------------------------------------------------
+
/** \brief Drops a reference on an object.
*
* This method should be called one and exactly one for each function
diff --git a/src/proj_experimental.h b/src/proj_experimental.h
index 9af7c389..698b235b 100644
--- a/src/proj_experimental.h
+++ b/src/proj_experimental.h
@@ -123,6 +123,13 @@ PJ_OBJ PROJ_DLL *proj_obj_create_ellipsoidal_2D_cs(PJ_CONTEXT *ctx,
const char* unit_name,
double unit_conv_factor);
+PJ_OBJ_LIST PROJ_DLL *proj_obj_query_geodetic_crs_from_datum(
+ PJ_CONTEXT *ctx,
+ const char *crs_auth_name,
+ const char *datum_auth_name,
+ const char *datum_code,
+ const char *crs_type);
+
PJ_OBJ PROJ_DLL *proj_obj_create_geographic_crs(
PJ_CONTEXT *ctx,
const char *crs_name,
diff --git a/test/unit/test_c_api.cpp b/test/unit/test_c_api.cpp
index f3ba66df..e9782ae8 100644
--- a/test/unit/test_c_api.cpp
+++ b/test/unit/test_c_api.cpp
@@ -2566,4 +2566,23 @@ TEST_F(CApi, proj_obj_get_non_deprecated) {
EXPECT_EQ(proj_obj_list_get_count(list), 2);
}
+// ---------------------------------------------------------------------------
+
+TEST_F(CApi, proj_obj_query_geodetic_crs_from_datum) {
+ {
+ auto list = proj_obj_query_geodetic_crs_from_datum(
+ m_ctxt, nullptr, "EPSG", "6326", nullptr);
+ ASSERT_NE(list, nullptr);
+ ObjListKeeper keeper_list(list);
+ EXPECT_GE(proj_obj_list_get_count(list), 3);
+ }
+ {
+ auto list = proj_obj_query_geodetic_crs_from_datum(
+ m_ctxt, "EPSG", "EPSG", "6326", "geographic 2D");
+ ASSERT_NE(list, nullptr);
+ ObjListKeeper keeper_list(list);
+ EXPECT_EQ(proj_obj_list_get_count(list), 1);
+ }
+}
+
} // namespace