aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/c_api.cpp33
-rw-r--r--src/crs.cpp16
-rw-r--r--src/proj_experimental.h5
3 files changed, 54 insertions, 0 deletions
diff --git a/src/c_api.cpp b/src/c_api.cpp
index b09cbbf2..aa9d7e70 100644
--- a/src/c_api.cpp
+++ b/src/c_api.cpp
@@ -2415,6 +2415,39 @@ PJ_OBJ PROJ_DLL *proj_obj_alter_name(PJ_CONTEXT *ctx, const PJ_OBJ *obj,
// ---------------------------------------------------------------------------
+/** \brief Return a copy of the object with its identifier changed/set
+ *
+ * Currently, only implemented on CRS objects.
+ *
+ * The returned object must be unreferenced with proj_obj_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 obj Object of type CRS. Must not be NULL
+ * @param auth_name Authority name. Must not be NULL
+ * @param code Code. Must not be NULL
+ *
+ * @return Object that must be unreferenced with
+ * proj_obj_destroy(), or NULL in case of error.
+ */
+PJ_OBJ PROJ_DLL *proj_obj_alter_id(PJ_CONTEXT *ctx, const PJ_OBJ *obj,
+ const char *auth_name, const char *code) {
+ SANITIZE_CTX(ctx);
+ auto crs = dynamic_cast<const CRS *>(obj->obj.get());
+ if (!crs) {
+ return nullptr;
+ }
+ try {
+ return PJ_OBJ::create(crs->alterId(auth_name, code));
+ } catch (const std::exception &e) {
+ proj_log_error(ctx, __FUNCTION__, e.what());
+ }
+ return nullptr;
+}
+
+// ---------------------------------------------------------------------------
+
/** \brief Return a copy of the CRS with its geodetic CRS changed
*
* Currently, when obj is a GeodeticCRS, it returns a clone of new_geod_crs
diff --git a/src/crs.cpp b/src/crs.cpp
index 10bec815..d873e81b 100644
--- a/src/crs.cpp
+++ b/src/crs.cpp
@@ -574,6 +574,22 @@ CRSNNPtr CRS::alterName(const std::string &newName) const {
// ---------------------------------------------------------------------------
+//! @cond Doxygen_Suppress
+
+CRSNNPtr CRS::alterId(const std::string &authName,
+ const std::string &code) const {
+ auto crs = shallowClone();
+ auto props = util::PropertyMap();
+ props.set(metadata::Identifier::CODESPACE_KEY, authName)
+ .set(metadata::Identifier::CODE_KEY, code);
+ crs->setProperties(props);
+ return crs;
+}
+
+//! @endcond
+
+// ---------------------------------------------------------------------------
+
/** \brief Identify the CRS with reference CRSs.
*
* The candidate CRSs are either hard-coded, or looked in the database when
diff --git a/src/proj_experimental.h b/src/proj_experimental.h
index 84ea31d7..f3f5c529 100644
--- a/src/proj_experimental.h
+++ b/src/proj_experimental.h
@@ -177,6 +177,11 @@ PJ_OBJ PROJ_DLL *proj_obj_create_geocentric_crs_from_datum(
PJ_OBJ PROJ_DLL *proj_obj_alter_name(PJ_CONTEXT *ctx,
const PJ_OBJ* obj, const char* name);
+PJ_OBJ PROJ_DLL *proj_obj_alter_id(PJ_CONTEXT *ctx,
+ const PJ_OBJ* obj,
+ const char* auth_name,
+ const char* code);
+
PJ_OBJ PROJ_DLL *proj_obj_crs_alter_geodetic_crs(PJ_CONTEXT *ctx,
const PJ_OBJ* obj,
const PJ_OBJ* new_geod_crs);