diff options
| -rw-r--r-- | src/proj.h | 2 | ||||
| -rw-r--r-- | src/proj_4D_api.c | 20 | ||||
| -rw-r--r-- | test/unit/gie_self_tests.cpp | 44 |
3 files changed, 59 insertions, 7 deletions
@@ -341,7 +341,7 @@ int PROJ_DLL proj_context_get_use_proj4_init_rules(PJ_CONTEXT *ctx, int from_leg /* Manage the transformation definition object PJ */ PJ PROJ_DLL *proj_create (PJ_CONTEXT *ctx, const char *definition); PJ PROJ_DLL *proj_create_argv (PJ_CONTEXT *ctx, int argc, char **argv); -PJ PROJ_DLL *proj_create_crs_to_crs(PJ_CONTEXT *ctx, const char *srid_from, const char *srid_to, PJ_AREA *area); +PJ PROJ_DLL *proj_create_crs_to_crs(PJ_CONTEXT *ctx, const char *source_crs, const char *target_crs, PJ_AREA *area); PJ PROJ_DLL *proj_destroy (PJ *P); diff --git a/src/proj_4D_api.c b/src/proj_4D_api.c index 4d05530e..6afabcaa 100644 --- a/src/proj_4D_api.c +++ b/src/proj_4D_api.c @@ -715,14 +715,22 @@ int proj_context_get_use_proj4_init_rules(PJ_CONTEXT *ctx, int from_legacy_code_ /*****************************************************************************/ -PJ *proj_create_crs_to_crs (PJ_CONTEXT *ctx, const char *srid_from, const char *srid_to, PJ_AREA *area) { +PJ *proj_create_crs_to_crs (PJ_CONTEXT *ctx, const char *source_crs, const char *target_crs, PJ_AREA *area) { /****************************************************************************** Create a transformation pipeline between two known coordinate reference systems. - srid_from and srid_to should be the value part of a +init=... parameter - set, i.e. "EPSG:25833" or "IGNF:AMST63". Any projection definition that - can be found in a init-file in PROJ_LIB is a valid input to this function. + source_crs and target_crs can be : + - a "AUTHORITY:CODE", like EPSG:25832. When using that syntax for a source + CRS, the created pipeline will expect that the values passed to proj_trans() + respect the axis order and axis unit of the official definition ( + so for example, for EPSG:4326, with latitude first and longitude next, + in degrees). Similarly, when using that syntax for a target CRS, output + values will be emitted according to the official definition of this CRS. + - a PROJ string, like "+proj=longlat +datum=WGS84". + When using that syntax, the axis order and unit for geographic CRS will + be longitude, latitude, and the unit degrees. + - more generally any string accepted by proj_obj_create_from_user_input() An "area of use" can be specified in area. When it is supplied, the more accurate transformation between two given systems can be chosen. @@ -743,12 +751,12 @@ PJ *proj_create_crs_to_crs (PJ_CONTEXT *ctx, const char *srid_from, const char const char* const* optionsImportCRS = proj_context_get_use_proj4_init_rules(ctx, FALSE) ? optionsProj4Mode : NULL; - src = proj_obj_create_from_user_input(ctx, srid_from, optionsImportCRS); + src = proj_obj_create_from_user_input(ctx, source_crs, optionsImportCRS); if( !src ) { return NULL; } - dst = proj_obj_create_from_user_input(ctx, srid_to, optionsImportCRS); + dst = proj_obj_create_from_user_input(ctx, target_crs, optionsImportCRS); if( !dst ) { proj_obj_unref(src); return NULL; diff --git a/test/unit/gie_self_tests.cpp b/test/unit/gie_self_tests.cpp index 7aca3001..b7af926b 100644 --- a/test/unit/gie_self_tests.cpp +++ b/test/unit/gie_self_tests.cpp @@ -275,6 +275,50 @@ TEST_F(gieTest, proj_create_crs_to_crs) { // --------------------------------------------------------------------------- +TEST_F(gieTest, proj_create_crs_to_crs_EPSG_4326) { + + auto P = + proj_create_crs_to_crs(PJ_DEFAULT_CTX, "EPSG:4326", "EPSG:32631", NULL); + ASSERT_TRUE(P != nullptr); + PJ_COORD a, b; + + // Lat, long degrees + a.xy.x = 0.0; + a.xy.y = 3.0; + + b.xy.x = 500000.0; + b.xy.y = 0.0; + + a = proj_trans(P, PJ_FWD, a); + EXPECT_NEAR(a.xy.x, b.xy.x, 1e-9); + EXPECT_NEAR(a.xy.y, b.xy.y, 1e-9); + proj_destroy(P); +} + +// --------------------------------------------------------------------------- + +TEST_F(gieTest, proj_create_crs_to_crs_proj_longlat) { + + auto P = proj_create_crs_to_crs( + PJ_DEFAULT_CTX, "+proj=longlat +datum=WGS84", "EPSG:32631", NULL); + ASSERT_TRUE(P != nullptr); + PJ_COORD a, b; + + // Long, lat degrees + a.xy.x = 3.0; + a.xy.y = 0; + + b.xy.x = 500000.0; + b.xy.y = 0.0; + + a = proj_trans(P, PJ_FWD, a); + EXPECT_NEAR(a.xy.x, b.xy.x, 1e-9); + EXPECT_NEAR(a.xy.y, b.xy.y, 1e-9); + proj_destroy(P); +} + +// --------------------------------------------------------------------------- + TEST(gie, info_functions) { PJ_INFO info; PJ_PROJ_INFO pj_info; |
