Skip to content

Commit

Permalink
PROJ6: msOGRSpatialRef2ProjectionObj: avoid going through potentially…
Browse files Browse the repository at this point in the history
… lossy PROJ4 strings
  • Loading branch information
rouault committed Oct 1, 2019
1 parent b22b085 commit 75860fd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
20 changes: 20 additions & 0 deletions mapogr.cpp
Expand Up @@ -974,6 +974,26 @@ static int msOGRSpatialRef2ProjectionObj(OGRSpatialReferenceH hSRS,
return MS_SUCCESS;
}

#if PROJ_VERSION_MAJOR >= 6
// This could be done also in the < 6 case, but would be useless.
// Here this helps avoiding going through potentially lossy PROJ4 strings
const char* pszAuthName = OSRGetAuthorityName(hSRS, NULL);
if( pszAuthName && EQUAL(pszAuthName, "EPSG") )
{
const char* pszAuthCode = OSRGetAuthorityCode(hSRS, NULL);
if( pszAuthCode )
{
char szInitStr[32];
sprintf(szInitStr, "init=epsg:%d", atoi(pszAuthCode));

if( debug_flag )
msDebug( "AUTO = %s\n", szInitStr );

return msLoadProjectionString(proj, szInitStr) == 0 ? MS_SUCCESS : MS_FAILURE;
}
}
#endif

// Export OGR SRS to a PROJ4 string
char *pszProj = NULL;

Expand Down
3 changes: 1 addition & 2 deletions mapscript/python/tests/cases/map_test.py
Expand Up @@ -324,8 +324,7 @@ def testESRIWKT(self):
def testWellKnownGEOGCS(self):
self.map.setWKTProjection('WGS84')
proj4 = self.map.getProjection()
assert proj4.find('+proj=longlat') != -1, proj4
assert proj4.find('+datum=WGS84') != -1, proj4
assert ('+proj=longlat' in proj4 and '+datum=WGS84' in proj4) or proj4 == '+init=epsg:4326', proj4
assert (mapscript.projectionObj(proj4)).getUnits() != mapscript.MS_METERS


Expand Down

0 comments on commit 75860fd

Please sign in to comment.