Skip to content

Commit 75860fd

Browse files
committed
PROJ6: msOGRSpatialRef2ProjectionObj: avoid going through potentially lossy PROJ4 strings
1 parent b22b085 commit 75860fd

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

mapogr.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,26 @@ static int msOGRSpatialRef2ProjectionObj(OGRSpatialReferenceH hSRS,
974974
return MS_SUCCESS;
975975
}
976976

977+
#if PROJ_VERSION_MAJOR >= 6
978+
// This could be done also in the < 6 case, but would be useless.
979+
// Here this helps avoiding going through potentially lossy PROJ4 strings
980+
const char* pszAuthName = OSRGetAuthorityName(hSRS, NULL);
981+
if( pszAuthName && EQUAL(pszAuthName, "EPSG") )
982+
{
983+
const char* pszAuthCode = OSRGetAuthorityCode(hSRS, NULL);
984+
if( pszAuthCode )
985+
{
986+
char szInitStr[32];
987+
sprintf(szInitStr, "init=epsg:%d", atoi(pszAuthCode));
988+
989+
if( debug_flag )
990+
msDebug( "AUTO = %s\n", szInitStr );
991+
992+
return msLoadProjectionString(proj, szInitStr) == 0 ? MS_SUCCESS : MS_FAILURE;
993+
}
994+
}
995+
#endif
996+
977997
// Export OGR SRS to a PROJ4 string
978998
char *pszProj = NULL;
979999

mapscript/python/tests/cases/map_test.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,7 @@ def testESRIWKT(self):
324324
def testWellKnownGEOGCS(self):
325325
self.map.setWKTProjection('WGS84')
326326
proj4 = self.map.getProjection()
327-
assert proj4.find('+proj=longlat') != -1, proj4
328-
assert proj4.find('+datum=WGS84') != -1, proj4
327+
assert ('+proj=longlat' in proj4 and '+datum=WGS84' in proj4) or proj4 == '+init=epsg:4326', proj4
329328
assert (mapscript.projectionObj(proj4)).getUnits() != mapscript.MS_METERS
330329

331330

0 commit comments

Comments
 (0)