Skip to content

Commit

Permalink
Merge 668d882 into 36fb1cb
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed Sep 26, 2019
2 parents 36fb1cb + 668d882 commit 055f738
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/4D_api.cpp
Expand Up @@ -1137,6 +1137,8 @@ PJ *proj_create_crs_to_crs_from_pj (PJ_CONTEXT *ctx, const PJ *source_crs, cons

try
{
bool skipDefaultTransforms = true;

// Iterate over source->target candidate transformations and reproject
// their long-lat bounding box into the source CRS.
for( int i = 0; i < op_count; i++ )
Expand All @@ -1149,12 +1151,25 @@ PJ *proj_create_crs_to_crs_from_pj (PJ_CONTEXT *ctx, const PJ *source_crs, cons
double north_lat = 0.0;

const char* name = proj_get_name(op);
if( name && (strstr(name, "Ballpark geographic offset") ||
bool canUseOp = true;
if( skipDefaultTransforms &&
name && (strstr(name, "Ballpark geographic offset") ||
strstr(name, "Ballpark geocentric translation")) )
{
// Skip default transformations
// Skip default transformations unless there is already one at
// the beginning (in which case all of them will have one)
if( i == 0 )
{
skipDefaultTransforms = false;
}
else
{
canUseOp = false;
}
}
else if( proj_get_area_of_use(ctx, op,

if( canUseOp &&
proj_get_area_of_use(ctx, op,
&west_lon, &south_lat, &east_lon, &north_lat, nullptr) )
{
if( west_lon <= east_lon )
Expand Down
26 changes: 26 additions & 0 deletions test/unit/test_c_api.cpp
Expand Up @@ -3811,4 +3811,30 @@ TEST_F(CApi, proj_crs_create_projected_3D_crs_from_2D) {
}
}

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

TEST_F(CApi, proj_create_crs_to_crs_with_only_ballpark_transformations) {
// ETRS89 / UTM zone 31N + EGM96 height to WGS 84 (G1762)
auto P =
proj_create_crs_to_crs(m_ctxt, "EPSG:25831+5773", "EPSG:7665", nullptr);
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);

PJ_COORD coord;
coord.xyzt.x = 500000;
coord.xyzt.y = 4500000;
coord.xyzt.z = 0;
coord.xyzt.t = 0;
coord = proj_trans(Pnormalized, PJ_FWD, coord);
EXPECT_NEAR(coord.xyzt.x, 3.0, 1e-9);
EXPECT_NEAR(coord.xyzt.y, 40.65085651660555, 1e-9);
if (coord.xyzt.z != 0) {
// z will depend if the egm96_15.gtx grid is there or not
EXPECT_NEAR(coord.xyzt.z, 47.04784081844435, 1e-3);
}
}

} // namespace

0 comments on commit 055f738

Please sign in to comment.