Skip to content

Commit

Permalink
Merge pull request #1537 from rouault/add_scope_remarks_for_coordinat…
Browse files Browse the repository at this point in the history
…e_operation

Database: import scope/remarks for coordinate operation and add C API
  • Loading branch information
rouault authored Jul 2, 2019
2 parents fb8228a + 7493200 commit 3ae09c3
Show file tree
Hide file tree
Showing 13 changed files with 2,613 additions and 2,318 deletions.
418 changes: 209 additions & 209 deletions data/sql/concatenated_operation.sql

Large diffs are not rendered by default.

770 changes: 385 additions & 385 deletions data/sql/grid_transformation.sql

Large diffs are not rendered by default.

2,758 changes: 1,379 additions & 1,379 deletions data/sql/helmert_transformation.sql

Large diffs are not rendered by default.

620 changes: 310 additions & 310 deletions data/sql/other_transformation.sql

Large diffs are not rendered by default.

24 changes: 12 additions & 12 deletions scripts/build_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,8 @@ def fill_compound_crs(proj_db_cursor):
raise

def fill_helmert_transformation(proj_db_cursor):
proj_db_cursor.execute("SELECT coord_op_code, coord_op_name, coord_op_method_code, coord_op_method_name, source_crs_code, target_crs_code, area_of_use_code, coord_op_accuracy, coord_tfm_version, epsg_coordoperation.deprecated FROM epsg.epsg_coordoperation LEFT JOIN epsg.epsg_coordoperationmethod USING (coord_op_method_code) WHERE coord_op_type = 'transformation' AND coord_op_method_code IN (1031, 1032, 1033, 1034, 1035, 1037, 1038, 1039, 1053, 1054, 1055, 1056, 1057, 1058, 1061, 1062, 1063, 1065, 1066, 9603, 9606, 9607, 9636) ")
for (code, name, method_code, method_name, source_crs_code, target_crs_code, area_of_use_code, coord_op_accuracy, coord_tfm_version, deprecated) in proj_db_cursor.fetchall():
proj_db_cursor.execute("SELECT coord_op_code, coord_op_name, coord_op_method_code, coord_op_method_name, source_crs_code, target_crs_code, area_of_use_code, coord_op_accuracy, coord_tfm_version, epsg_coordoperation.deprecated, coord_op_scope, epsg_coordoperation.remarks FROM epsg.epsg_coordoperation LEFT JOIN epsg.epsg_coordoperationmethod USING (coord_op_method_code) WHERE coord_op_type = 'transformation' AND coord_op_method_code IN (1031, 1032, 1033, 1034, 1035, 1037, 1038, 1039, 1053, 1054, 1055, 1056, 1057, 1058, 1061, 1062, 1063, 1065, 1066, 9603, 9606, 9607, 9636) ")
for (code, name, method_code, method_name, source_crs_code, target_crs_code, area_of_use_code, coord_op_accuracy, coord_tfm_version, deprecated, scope, remarks) in proj_db_cursor.fetchall():
expected_order = 1
max_n_params = 15
param_auth_name = [None for i in range(max_n_params)]
Expand Down Expand Up @@ -320,7 +320,7 @@ def fill_helmert_transformation(proj_db_cursor):
assert param_uom_code[10] == param_uom_code[12]

arg = (EPSG_AUTHORITY, code, name,
None, None, # description + scope
remarks, scope,
EPSG_AUTHORITY, method_code, method_name,
EPSG_AUTHORITY, source_crs_code,
EPSG_AUTHORITY, target_crs_code,
Expand All @@ -343,8 +343,8 @@ def fill_helmert_transformation(proj_db_cursor):
'?,?,?, ?,?, ?,?,?, ?,?, ?,?, ?,?, ?, ?,?,?,?,?, ?,?,?,?,?, ?,?,?, ?,?,?,?,?, ?,?,?,?,?, ?,?,?, ?,?,?, ?,?,?,?,?, ?,?)', arg)

def fill_grid_transformation(proj_db_cursor):
proj_db_cursor.execute("SELECT coord_op_code, coord_op_name, coord_op_method_code, coord_op_method_name, source_crs_code, target_crs_code, area_of_use_code, coord_op_accuracy, coord_tfm_version, epsg_coordoperation.deprecated FROM epsg.epsg_coordoperation LEFT JOIN epsg.epsg_coordoperationmethod USING (coord_op_method_code) WHERE coord_op_type = 'transformation' AND (coord_op_method_name LIKE 'Geographic3D to%' OR coord_op_method_name LIKE 'Geog3D to%' OR coord_op_method_name LIKE 'Point motion by grid%' OR coord_op_method_name LIKE 'Vertical Offset by Grid Interpolation%' OR coord_op_method_name IN ('NADCON', 'NTv1', 'NTv2', 'VERTCON'))")
for (code, name, method_code, method_name, source_crs_code, target_crs_code, area_of_use_code, coord_op_accuracy, coord_tfm_version, deprecated) in proj_db_cursor.fetchall():
proj_db_cursor.execute("SELECT coord_op_code, coord_op_name, coord_op_method_code, coord_op_method_name, source_crs_code, target_crs_code, area_of_use_code, coord_op_accuracy, coord_tfm_version, epsg_coordoperation.deprecated, coord_op_scope, epsg_coordoperation.remarks FROM epsg.epsg_coordoperation LEFT JOIN epsg.epsg_coordoperationmethod USING (coord_op_method_code) WHERE coord_op_type = 'transformation' AND (coord_op_method_name LIKE 'Geographic3D to%' OR coord_op_method_name LIKE 'Geog3D to%' OR coord_op_method_name LIKE 'Point motion by grid%' OR coord_op_method_name LIKE 'Vertical Offset by Grid Interpolation%' OR coord_op_method_name IN ('NADCON', 'NTv1', 'NTv2', 'VERTCON'))")
for (code, name, method_code, method_name, source_crs_code, target_crs_code, area_of_use_code, coord_op_accuracy, coord_tfm_version, deprecated, scope, remarks) in proj_db_cursor.fetchall():
expected_order = 1
max_n_params = 2
param_auth_name = [None for i in range(max_n_params)]
Expand Down Expand Up @@ -393,7 +393,7 @@ def fill_grid_transformation(proj_db_cursor):


arg = (EPSG_AUTHORITY, code, name,
None, None, # description + scope
remarks, scope,
EPSG_AUTHORITY, method_code, method_name,
EPSG_AUTHORITY, source_crs_code,
EPSG_AUTHORITY, target_crs_code,
Expand All @@ -417,8 +417,8 @@ def fill_other_transformation(proj_db_cursor):
# 9619: Geographic2D offsets
# 9624: Affine Parametric Transformation
# 9660: Geographic3D offsets
proj_db_cursor.execute("SELECT coord_op_code, coord_op_name, coord_op_method_code, coord_op_method_name, source_crs_code, target_crs_code, area_of_use_code, coord_op_accuracy, coord_tfm_version, epsg_coordoperation.deprecated FROM epsg.epsg_coordoperation LEFT JOIN epsg.epsg_coordoperationmethod USING (coord_op_method_code) WHERE coord_op_type = 'transformation' AND coord_op_method_code IN (9601, 9616, 9618, 9619, 9624, 9660)")
for (code, name, method_code, method_name, source_crs_code, target_crs_code, area_of_use_code, coord_op_accuracy, coord_tfm_version, deprecated) in proj_db_cursor.fetchall():
proj_db_cursor.execute("SELECT coord_op_code, coord_op_name, coord_op_method_code, coord_op_method_name, source_crs_code, target_crs_code, area_of_use_code, coord_op_accuracy, coord_tfm_version, epsg_coordoperation.deprecated, coord_op_scope, epsg_coordoperation.remarks FROM epsg.epsg_coordoperation LEFT JOIN epsg.epsg_coordoperationmethod USING (coord_op_method_code) WHERE coord_op_type = 'transformation' AND coord_op_method_code IN (9601, 9616, 9618, 9619, 9624, 9660)")
for (code, name, method_code, method_name, source_crs_code, target_crs_code, area_of_use_code, coord_op_accuracy, coord_tfm_version, deprecated, scope, remarks) in proj_db_cursor.fetchall():
expected_order = 1
max_n_params = 7
param_auth_name = [None for i in range(max_n_params)]
Expand All @@ -441,7 +441,7 @@ def fill_other_transformation(proj_db_cursor):
expected_order += 1

arg = (EPSG_AUTHORITY, code, name,
None, None, # description + scope
remarks, scope,
EPSG_AUTHORITY, method_code, method_name,
EPSG_AUTHORITY, source_crs_code,
EPSG_AUTHORITY, target_crs_code,
Expand Down Expand Up @@ -470,8 +470,8 @@ def fill_other_transformation(proj_db_cursor):
'?,?,?,?,?,?, ?,?,?,?,?,?, ?,?,?,?,?,?, ?,?,?,?,?,?, ?,?)', arg)

def fill_concatenated_operation(proj_db_cursor):
proj_db_cursor.execute("SELECT coord_op_code, coord_op_name, coord_op_method_code, coord_op_method_name, source_crs_code, target_crs_code, area_of_use_code, coord_op_accuracy, coord_tfm_version, epsg_coordoperation.deprecated FROM epsg.epsg_coordoperation LEFT JOIN epsg.epsg_coordoperationmethod USING (coord_op_method_code) WHERE coord_op_type = 'concatenated operation'")
for (code, name, method_code, method_name, source_crs_code, target_crs_code, area_of_use_code, coord_op_accuracy, coord_tfm_version, deprecated) in proj_db_cursor.fetchall():
proj_db_cursor.execute("SELECT coord_op_code, coord_op_name, coord_op_method_code, coord_op_method_name, source_crs_code, target_crs_code, area_of_use_code, coord_op_accuracy, coord_tfm_version, epsg_coordoperation.deprecated, coord_op_scope, epsg_coordoperation.remarks FROM epsg.epsg_coordoperation LEFT JOIN epsg.epsg_coordoperationmethod USING (coord_op_method_code) WHERE coord_op_type = 'concatenated operation'")
for (code, name, method_code, method_name, source_crs_code, target_crs_code, area_of_use_code, coord_op_accuracy, coord_tfm_version, deprecated, scope, remarks) in proj_db_cursor.fetchall():
expected_order = 1
max_n_params = 3
step_code = [None for i in range(max_n_params)]
Expand All @@ -488,7 +488,7 @@ def fill_concatenated_operation(proj_db_cursor):
assert n_params in (2, 3), (code, n_params)

arg = (EPSG_AUTHORITY, code, name,
None, None, # description + scope
remarks, scope,
EPSG_AUTHORITY, source_crs_code,
EPSG_AUTHORITY, target_crs_code,
EPSG_AUTHORITY, area_of_use_code,
Expand Down
4 changes: 4 additions & 0 deletions scripts/reference_exported_symbols.txt
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,8 @@ proj_as_proj_string
proj_assign_context
proj_as_wkt
proj_clone
proj_concatoperation_get_step
proj_concatoperation_get_step_count
proj_context_create
proj_context_delete_cpp_context(projCppContext*)
proj_context_destroy
Expand Down Expand Up @@ -912,6 +914,8 @@ proj_get_id_code
proj_get_name
proj_get_non_deprecated
proj_get_prime_meridian
proj_get_remarks
proj_get_scope
proj_get_source_crs
proj_get_target_crs
proj_get_type
Expand Down
117 changes: 115 additions & 2 deletions src/iso19111/c_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1085,13 +1085,32 @@ const char *proj_get_name(const PJ *obj) {
if (!desc.has_value()) {
return nullptr;
}
// The object will still be alived after the function call.
// The object will still be alive after the function call.
// cppcheck-suppress stlcstr
return desc->c_str();
}

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

/** \brief Get the remarks of an object.
*
* The lifetime of the returned string is the same as the input obj parameter.
*
* @param obj Object (must not be NULL)
* @return a string, or NULL in case of error.
*/
const char *proj_get_remarks(const PJ *obj) {
assert(obj);
if (!obj->iso_obj) {
return nullptr;
}
// The object will still be alive after the function call.
// cppcheck-suppress stlcstr
return obj->iso_obj->remarks().c_str();
}

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

/** \brief Get the authority name / codespace of an identifier of an object.
*
* The lifetime of the returned string is the same as the input obj parameter.
Expand All @@ -1113,7 +1132,7 @@ const char *proj_get_id_auth_name(const PJ *obj, int index) {
if (!codeSpace.has_value()) {
return nullptr;
}
// The object will still be alived after the function call.
// The object will still be alive after the function call.
// cppcheck-suppress stlcstr
return codeSpace->c_str();
}
Expand Down Expand Up @@ -1295,7 +1314,42 @@ const char *proj_as_proj_string(PJ_CONTEXT *ctx, const PJ *obj,

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

/** \brief Get the scope of an object.
*
* In case of multiple usages, this will be the one of first usage.
*
* The lifetime of the returned string is the same as the input obj parameter.
*
* @param obj Object (must not be NULL)
* @return a string, or NULL in case of error or missing scope.
*/
const char *proj_get_scope(const PJ *obj) {
assert(obj);
if (!obj->iso_obj) {
return nullptr;
}
auto objectUsage = dynamic_cast<const ObjectUsage *>(obj->iso_obj.get());
if (!objectUsage) {
return nullptr;
}
const auto &domains = objectUsage->domains();
if (domains.empty()) {
return nullptr;
}
const auto &scope = domains[0]->scope();
if (!scope.has_value()) {
return nullptr;
}
// The object will still be alive after the function call.
// cppcheck-suppress stlcstr
return scope->c_str();
}

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

/** \brief Return the area of use of an object.
*
* In case of multiple usages, this will be the one of first usage.
*
* @param ctx PROJ context, or NULL for default context
* @param obj Object (must not be NULL)
Expand Down Expand Up @@ -6922,3 +6976,62 @@ PJ *proj_normalize_for_visualization(PJ_CONTEXT *ctx, const PJ *obj) {
return nullptr;
}
}

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

/** \brief Returns the number of steps of a concatenated operation.
*
* The input object must be a concatenated operation.
*
* @param ctx PROJ context, or NULL for default context
* @param concatoperation Concatenated operation (must not be NULL)
* @return the number of steps, or 0 in case of error.
*/
int proj_concatoperation_get_step_count(PJ_CONTEXT *ctx,
const PJ *concatoperation) {
SANITIZE_CTX(ctx);
assert(concatoperation);
auto l_co = dynamic_cast<const ConcatenatedOperation *>(
concatoperation->iso_obj.get());
if (!l_co) {
proj_log_error(ctx, __FUNCTION__,
"Object is not a ConcatenatedOperation");
return false;
}
return static_cast<int>(l_co->operations().size());
}
// ---------------------------------------------------------------------------

/** \brief Returns a step of a concatenated operation.
*
* The input object must be a concatenated operation.
*
* The returned object must be unreferenced with proj_destroy() after
* use.
* It should be used by at most one thread at a time.
*
* @param ctx PROJ context, or NULL for default context
* @param concatoperation Concatenated operation (must not be NULL)
* @param i_step Index of the step to extract. Between 0 and
* proj_concatoperation_get_step_count()-1
* @return Object that must be unreferenced with proj_destroy(), or NULL
* in case of error.
*/
PJ *proj_concatoperation_get_step(PJ_CONTEXT *ctx, const PJ *concatoperation,
int i_step) {
SANITIZE_CTX(ctx);
assert(concatoperation);
auto l_co = dynamic_cast<const ConcatenatedOperation *>(
concatoperation->iso_obj.get());
if (!l_co) {
proj_log_error(ctx, __FUNCTION__,
"Object is not a ConcatenatedOperation");
return nullptr;
}
const auto &steps = l_co->operations();
if (i_step < 0 || static_cast<size_t>(i_step) >= steps.size()) {
proj_log_error(ctx, __FUNCTION__, "Invalid step index");
return nullptr;
}
return pj_obj_create(ctx, steps[i_step]);
}
5 changes: 5 additions & 0 deletions src/iso19111/coordinateoperation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7342,6 +7342,11 @@ createPropertiesForInverse(const CoordinateOperation *op, bool derivedFrom,
map.set(common::IdentifiedObject::NAME_KEY, name);
}

const std::string &remarks = op->remarks();
if (!remarks.empty()) {
map.set(common::IdentifiedObject::REMARKS_KEY, remarks);
}

addModifiedIdentifier(map, op, true, derivedFrom);

return map;
Expand Down
Loading

0 comments on commit 3ae09c3

Please sign in to comment.