Skip to content

Commit

Permalink
Database: import scope/remarks for coordinate operation and add C API
Browse files Browse the repository at this point in the history
- Import scope and remarks for coordinate operations of the EPSG dataset.
  Database size goes from 5.2 MB to 5.55 MB
- Add proj_get_scope() and proj_get_remarks()
  • Loading branch information
rouault committed Jun 29, 2019
1 parent 7a131de commit abab3b8
Show file tree
Hide file tree
Showing 13 changed files with 2,474 additions and 2,316 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
2 changes: 2 additions & 0 deletions scripts/reference_exported_symbols.txt
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,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
54 changes: 54 additions & 0 deletions src/iso19111/c_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1092,6 +1092,25 @@ const char *proj_get_name(const PJ *obj) {

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

/** \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 alived 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 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 alived 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
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
55 changes: 47 additions & 8 deletions src/iso19111/factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1222,6 +1222,13 @@ struct AuthorityFactory::Private {
const std::string &area_of_use_auth_name,
const std::string &area_of_use_code);

util::PropertyMap createProperties(const std::string &code,
const std::string &name, bool deprecated,
const std::string &remarks,
const std::string &scope,
const std::string &area_of_use_auth_name,
const std::string &area_of_use_code);

SQLResultSet run(const std::string &sql,
const ListOfParams &parameters = ListOfParams());

Expand Down Expand Up @@ -1307,6 +1314,26 @@ util::PropertyMap AuthorityFactory::Private::createProperties(

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

util::PropertyMap AuthorityFactory::Private::createProperties(
const std::string &code, const std::string &name, bool deprecated,
const std::string &remarks, const std::string &scope,
const std::string &area_of_use_auth_name,
const std::string &area_of_use_code) {
auto props = createProperties(code, name, deprecated,
area_of_use_auth_name.empty()
? nullptr
: createFactory(area_of_use_auth_name)
->createExtent(area_of_use_code)
.as_nullable());
if (!remarks.empty())
props.set(common::IdentifiedObject::REMARKS_KEY, remarks);
if (!scope.empty())
props.set(common::ObjectUsage::SCOPE_KEY, scope);
return props;
}

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

bool AuthorityFactory::Private::rejectOpDueToMissingGrid(
const operation::CoordinateOperationNNPtr &op, bool discardIfMissingGrid) {
if (discardIfMissingGrid) {
Expand Down Expand Up @@ -2604,7 +2631,8 @@ operation::CoordinateOperationNNPtr AuthorityFactory::createCoordinateOperation(
if (type == "helmert_transformation") {

auto res = d->runWithCodeParam(
"SELECT name, method_auth_name, method_code, method_name, "
"SELECT name, description, scope, "
"method_auth_name, method_code, method_name, "
"source_crs_auth_name, source_crs_code, target_crs_auth_name, "
"target_crs_code, area_of_use_auth_name, area_of_use_code, "
"accuracy, tx, ty, tz, translation_uom_auth_name, "
Expand All @@ -2629,6 +2657,8 @@ operation::CoordinateOperationNNPtr AuthorityFactory::createCoordinateOperation(
const auto &row = res.front();
size_t idx = 0;
const auto &name = row[idx++];
const auto &description = row[idx++];
const auto &scope = row[idx++];
const auto &method_auth_name = row[idx++];
const auto &method_code = row[idx++];
const auto &method_name = row[idx++];
Expand Down Expand Up @@ -2817,7 +2847,7 @@ operation::CoordinateOperationNNPtr AuthorityFactory::createCoordinateOperation(
}

auto props =
d->createProperties(code, name, deprecated,
d->createProperties(code, name, deprecated, description, scope,
area_of_use_auth_name, area_of_use_code);
if (!operation_version.empty()) {
props.set(operation::CoordinateOperation::OPERATION_VERSION_KEY,
Expand Down Expand Up @@ -2846,7 +2876,8 @@ operation::CoordinateOperationNNPtr AuthorityFactory::createCoordinateOperation(

if (type == "grid_transformation") {
auto res = d->runWithCodeParam(
"SELECT name, method_auth_name, method_code, method_name, "
"SELECT name, description, scope, "
"method_auth_name, method_code, method_name, "
"source_crs_auth_name, source_crs_code, target_crs_auth_name, "
"target_crs_code, area_of_use_auth_name, area_of_use_code, "
"accuracy, grid_param_auth_name, grid_param_code, grid_param_name, "
Expand All @@ -2866,6 +2897,8 @@ operation::CoordinateOperationNNPtr AuthorityFactory::createCoordinateOperation(
const auto &row = res.front();
size_t idx = 0;
const auto &name = row[idx++];
const auto &description = row[idx++];
const auto &scope = row[idx++];
const auto &method_auth_name = row[idx++];
const auto &method_code = row[idx++];
const auto &method_name = row[idx++];
Expand Down Expand Up @@ -2930,7 +2963,7 @@ operation::CoordinateOperationNNPtr AuthorityFactory::createCoordinateOperation(
}

auto props =
d->createProperties(code, name, deprecated,
d->createProperties(code, name, deprecated, description, scope,
area_of_use_auth_name, area_of_use_code);
if (!operation_version.empty()) {
props.set(operation::CoordinateOperation::OPERATION_VERSION_KEY,
Expand Down Expand Up @@ -2964,7 +2997,8 @@ operation::CoordinateOperationNNPtr AuthorityFactory::createCoordinateOperation(
std::ostringstream buffer;
buffer.imbue(std::locale::classic());
buffer
<< "SELECT name, method_auth_name, method_code, method_name, "
<< "SELECT name, description, scope, "
"method_auth_name, method_code, method_name, "
"source_crs_auth_name, source_crs_code, target_crs_auth_name, "
"target_crs_code, area_of_use_auth_name, area_of_use_code, "
"accuracy";
Expand All @@ -2990,6 +3024,8 @@ operation::CoordinateOperationNNPtr AuthorityFactory::createCoordinateOperation(
const auto &row = res.front();
size_t idx = 0;
const auto &name = row[idx++];
const auto &description = row[idx++];
const auto &scope = row[idx++];
const auto &method_auth_name = row[idx++];
const auto &method_code = row[idx++];
const auto &method_name = row[idx++];
Expand Down Expand Up @@ -3044,7 +3080,7 @@ operation::CoordinateOperationNNPtr AuthorityFactory::createCoordinateOperation(
->createCoordinateReferenceSystem(target_crs_code);

auto props =
d->createProperties(code, name, deprecated,
d->createProperties(code, name, deprecated, description, scope,
area_of_use_auth_name, area_of_use_code);
if (!operation_version.empty()) {
props.set(operation::CoordinateOperation::OPERATION_VERSION_KEY,
Expand Down Expand Up @@ -3099,7 +3135,8 @@ operation::CoordinateOperationNNPtr AuthorityFactory::createCoordinateOperation(

if (allowConcatenated && type == "concatenated_operation") {
auto res = d->runWithCodeParam(
"SELECT name, source_crs_auth_name, source_crs_code, "
"SELECT name, description, scope, "
"source_crs_auth_name, source_crs_code, "
"target_crs_auth_name, target_crs_code, "
"area_of_use_auth_name, area_of_use_code, accuracy, "
"step1_auth_name, step1_code, step2_auth_name, step2_code, "
Expand All @@ -3115,6 +3152,8 @@ operation::CoordinateOperationNNPtr AuthorityFactory::createCoordinateOperation(
const auto &row = res.front();
size_t idx = 0;
const auto &name = row[idx++];
const auto &description = row[idx++];
const auto &scope = row[idx++];
const auto &source_crs_auth_name = row[idx++];
const auto &source_crs_code = row[idx++];
const auto &target_crs_auth_name = row[idx++];
Expand Down Expand Up @@ -3160,7 +3199,7 @@ operation::CoordinateOperationNNPtr AuthorityFactory::createCoordinateOperation(
operations);

auto props =
d->createProperties(code, name, deprecated,
d->createProperties(code, name, deprecated, description, scope,
area_of_use_auth_name, area_of_use_code);
if (!operation_version.empty()) {
props.set(operation::CoordinateOperation::OPERATION_VERSION_KEY,
Expand Down
4 changes: 4 additions & 0 deletions src/proj.h
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,10 @@ const char PROJ_DLL* proj_get_id_auth_name(const PJ *obj, int index);

const char PROJ_DLL* proj_get_id_code(const PJ *obj, int index);

const char PROJ_DLL* proj_get_remarks(const PJ *obj);

const char PROJ_DLL* proj_get_scope(const PJ *obj);

int PROJ_DLL proj_get_area_of_use(PJ_CONTEXT *ctx,
const PJ *obj,
double* out_west_lon_degree,
Expand Down
Loading

0 comments on commit abab3b8

Please sign in to comment.