diff options
| -rw-r--r-- | src/iso19111/c_api.cpp | 27 | ||||
| -rw-r--r-- | test/unit/test_c_api.cpp | 23 |
2 files changed, 44 insertions, 6 deletions
diff --git a/src/iso19111/c_api.cpp b/src/iso19111/c_api.cpp index 27a727dc..ac3a5f11 100644 --- a/src/iso19111/c_api.cpp +++ b/src/iso19111/c_api.cpp @@ -7434,14 +7434,19 @@ int proj_cs_get_axis_info(PJ_CONTEXT *ctx, const PJ *cs, int index, /** \brief Returns a PJ* object whose axis order is the one expected for * visualization purposes. * - * The input object must be a coordinate operation, that has been created with - * proj_create_crs_to_crs(). - * If the axis order of its source or target CRS is northing,easting, then an - * axis swap operation will be inserted. + * The input object must be either: + * <ul> + * <li>a coordinate operation, that has been created with + * proj_create_crs_to_crs(). If the axis order of its source or target CRS + * is northing,easting, then an axis swap operation will be inserted.</li> + * <li>or a CRS. The axis order of geographic CRS will be longitude, latitude + * [,height], and the one of projected CRS will be easting, northing + * [, height]</li> + * </ul> * * @param ctx PROJ context, or NULL for default context - * @param obj Object of type CoordinateOperation, - * created with proj_create_crs_to_crs() (must not be NULL) + * @param obj Object of type CRS, or CoordinateOperation created with + * proj_create_crs_to_crs() (must not be NULL) * @return a new PJ* object to free with proj_destroy() in case of success, or * nullptr in case of error */ @@ -7499,6 +7504,16 @@ PJ *proj_normalize_for_visualization(PJ_CONTEXT *ctx, const PJ *obj) { } } + auto crs = dynamic_cast<const CRS *>(obj->iso_obj.get()); + if (crs) { + try { + return pj_obj_create(ctx, crs->normalizeForVisualization()); + } catch (const std::exception &e) { + proj_log_debug(ctx, __FUNCTION__, e.what()); + return nullptr; + } + } + auto co = dynamic_cast<const CoordinateOperation *>(obj->iso_obj.get()); if (!co) { proj_log_error(ctx, __FUNCTION__, "Object is not a CoordinateOperation " diff --git a/test/unit/test_c_api.cpp b/test/unit/test_c_api.cpp index b4c620ce..40122cb2 100644 --- a/test/unit/test_c_api.cpp +++ b/test/unit/test_c_api.cpp @@ -3454,6 +3454,29 @@ TEST_F(CApi, proj_normalize_for_visualization_with_alternatives_reverse) { // --------------------------------------------------------------------------- +TEST_F(CApi, proj_normalize_for_visualization_on_crs) { + + auto P = proj_create(m_ctxt, "EPSG:4326"); + ObjectKeeper keeper_P(P); + ASSERT_NE(P, nullptr); + auto Pnormalized = proj_normalize_for_visualization(m_ctxt, P); + ObjectKeeper keeper_Pnormalized(Pnormalized); + ASSERT_NE(Pnormalized, nullptr); + EXPECT_EQ(proj_get_id_code(Pnormalized, 0), nullptr); + + auto cs = proj_crs_get_coordinate_system(m_ctxt, Pnormalized); + ASSERT_NE(cs, nullptr); + ObjectKeeper keeperCs(cs); + + const char *name = nullptr; + ASSERT_TRUE(proj_cs_get_axis_info(m_ctxt, cs, 0, &name, nullptr, nullptr, + nullptr, nullptr, nullptr, nullptr)); + ASSERT_NE(name, nullptr); + EXPECT_EQ(std::string(name), "Geodetic longitude"); +} + +// --------------------------------------------------------------------------- + TEST_F(CApi, proj_get_remarks) { auto co = proj_create_from_database(m_ctxt, "EPSG", "8048", PJ_CATEGORY_COORDINATE_OPERATION, false, |
