Skip to content

Commit

Permalink
add proj_get_geoid_models_from_database to C API
Browse files Browse the repository at this point in the history
  • Loading branch information
jjimenezshaw committed Apr 23, 2021
1 parent 779e366 commit f2e66ec
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 0 deletions.
1 change: 1 addition & 0 deletions scripts/reference_exported_symbols.txt
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,7 @@ proj_get_crs_info_list_from_database
proj_get_crs_list_parameters_create
proj_get_crs_list_parameters_destroy
proj_get_ellipsoid
proj_get_geoid_models_from_database
proj_get_id_auth_name
proj_get_id_code
proj_get_insert_statements
Expand Down
43 changes: 43 additions & 0 deletions src/iso19111/c_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9162,3 +9162,46 @@ PROJ_STRING_LIST proj_get_insert_statements(
}
return nullptr;
}

// ---------------------------------------------------------------------------

/** \brief Returns a list of geoid models available for that crs
*
* The list includes the geoid models connected directly with the crs,
* or via "Height Depth Reversal" or "Change of Vertical Unit" transformations.
* The returned list is NULL terminated and must be freed with
* proj_string_list_destroy().
*
* @param ctx Context, or NULL for default context.
* @param auth_name Authority name (must not be NULL)
* @param code Object code (must not be NULL)
* @param options should be set to NULL for now
* @return list of geoid models names (to be freed with
* proj_string_list_destroy()), or NULL in case of error.
* @since 8.1
*/
PROJ_STRING_LIST
proj_get_geoid_models_from_database(PJ_CONTEXT *ctx, const char *auth_name,
const char *code,
const char *const *options) {
SANITIZE_CTX(ctx);
if (!auth_name || !code) {
proj_context_errno_set(ctx, PROJ_ERR_OTHER_API_MISUSE);
proj_log_error(ctx, __FUNCTION__, "missing required input");
return nullptr;
}
(void)options;
try {
const std::string codeStr(code);
auto factory = AuthorityFactory::create(getDBcontext(ctx), auth_name);
auto geoidModels = factory->getGeoidModels(codeStr);
ctx->safeAutoCloseDbIfNeeded();
return to_string_list(std::move(geoidModels));
} catch (const std::exception &e) {
proj_log_error(ctx, __FUNCTION__, e.what());
}
ctx->safeAutoCloseDbIfNeeded();
return nullptr;
}

// ---------------------------------------------------------------------------
6 changes: 6 additions & 0 deletions src/proj.h
Original file line number Diff line number Diff line change
Expand Up @@ -1188,6 +1188,12 @@ PJ_OBJ_LIST PROJ_DLL *proj_identify(PJ_CONTEXT *ctx,
const char* const *options,
int **out_confidence);

PROJ_STRING_LIST PROJ_DLL proj_get_geoid_models_from_database(
PJ_CONTEXT *ctx,
const char *auth_name,
const char *code,
const char *const *options);

void PROJ_DLL proj_int_list_destroy(int* list);

/* ------------------------------------------------------------------------- */
Expand Down
60 changes: 60 additions & 0 deletions test/unit/test_c_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5619,5 +5619,65 @@ TEST_F(CApi, proj_get_insert_statements) {
proj_insert_object_session_destroy(m_ctxt, session);
}
}
// ---------------------------------------------------------------------------

TEST_F(CApi, proj_get_geoid_models_from_database) {

This comment has been minimized.

Copy link
@rouault

rouault Apr 23, 2021

Member

As the C++ method is extensively tested, I would just reduce the testing here to the strictest minimum to just test the C wrapper.


const std::string GEOID12B{"GEOID12B"};
const std::string GEOID18{"GEOID18"};
const std::string OSGM15{"OSGM15"};

auto findInList = [](PROJ_STRING_LIST list, const std::string &ref) {
while (list && *list) {
if (std::string(*list) == ref) {
return true;
}
list++;
}
return false;
};

{
auto list = proj_get_geoid_models_from_database(m_ctxt, "EPSG", "4326",
nullptr);
ListFreer freer(list);
ASSERT_NE(list, nullptr);
EXPECT_EQ(list[0], nullptr);
}

{
auto list = proj_get_geoid_models_from_database(m_ctxt, "EPSG", "5703",
nullptr);
ListFreer freer(list);
EXPECT_TRUE(findInList(list, GEOID12B));
EXPECT_TRUE(findInList(list, GEOID18));
EXPECT_FALSE(findInList(list, OSGM15));
}
{
auto list = proj_get_geoid_models_from_database(m_ctxt, "EPSG", "8228",
nullptr);
ListFreer freer(list);
EXPECT_TRUE(findInList(list, GEOID12B));
EXPECT_TRUE(findInList(list, GEOID18));
EXPECT_FALSE(findInList(list, OSGM15));
}
{
auto list = proj_get_geoid_models_from_database(m_ctxt, "EPSG", "6358",
nullptr);
ListFreer freer(list);
EXPECT_TRUE(findInList(list, GEOID12B));
EXPECT_TRUE(findInList(list, GEOID18));
EXPECT_FALSE(findInList(list, OSGM15));
}

{
auto list = proj_get_geoid_models_from_database(m_ctxt, "EPSG", "5701",
nullptr);
ListFreer freer(list);
EXPECT_FALSE(findInList(list, GEOID12B));
EXPECT_FALSE(findInList(list, GEOID18));
EXPECT_TRUE(findInList(list, OSGM15));
}
}

} // namespace

0 comments on commit f2e66ec

Please sign in to comment.