Permalink
Browse files

OGRSpatialReference::FindMatches(): if the input SRS has a EPSG code,…

… check that its definition and the EPSG one actually matches (fixes #990)
  • Loading branch information...
rouault committed Oct 9, 2018
1 parent 2957de2 commit a7e53cdbe5aa932d36a25c760cd22e928382344b
Showing with 58 additions and 15 deletions.
  1. +38 −0 autotest/osr/osr_epsg.py
  2. +20 −15 gdal/ogr/ogr_fromepsg.cpp
View
@@ -400,6 +400,44 @@ def osr_epsg_13():
gdaltest.post_reason('fail')
return 'fail'
# WKT has EPSG code but the definition doesn't match with the official
# one (namely linear units are different)
# https://github.com/OSGeo/gdal/issues/990
sr = osr.SpatialReference()
sr.SetFromUserInput("""PROJCS["NAD83 / Ohio North",
GEOGCS["NAD83",
DATUM["North_American_Datum_1983",
SPHEROID["GRS 1980",6378137,298.257222101,
AUTHORITY["EPSG","7019"]],
TOWGS84[0,0,0,0,0,0,0],
AUTHORITY["EPSG","6269"]],
PRIMEM["Greenwich",0,
AUTHORITY["EPSG","8901"]],
UNIT["degree",0.0174532925199433,
AUTHORITY["EPSG","9122"]],
AUTHORITY["EPSG","4269"]],
PROJECTION["Lambert_Conformal_Conic_2SP"],
PARAMETER["standard_parallel_1",41.7],
PARAMETER["standard_parallel_2",40.43333333333333],
PARAMETER["latitude_of_origin",39.66666666666666],
PARAMETER["central_meridian",-82.5],
PARAMETER["false_easting",1968503.937007874],
PARAMETER["false_northing",0],
UNIT["International Foot",0.3048,
AUTHORITY["EPSG","9002"]],
AXIS["X",EAST],
AXIS["Y",NORTH],
AUTHORITY["EPSG","32122"]]
""")
matches = sr.FindMatches()
if len(matches) != 1 or matches[0][1] != 50:
gdaltest.post_reason('fail')
print(matches)
return 'fail'
if matches[0][0].IsSame(sr) == 1:
gdaltest.post_reason('fail')
return 'fail'
return 'success'
###############################################################################
View
@@ -3420,24 +3420,29 @@ OGRSpatialReferenceH* OGRSpatialReference::FindMatches(
if( ppanMatchConfidence )
*ppanMatchConfidence = nullptr;
OGRSpatialReference oSRSClone(*this);
if( oSRSClone.AutoIdentifyEPSG() == OGRERR_NONE )
{
const char* pszCode = oSRSClone.GetAuthorityCode(nullptr);
if( pszCode )
oSRSClone.importFromEPSG(atoi(pszCode));
OGRSpatialReferenceH* pahRet =
static_cast<OGRSpatialReferenceH*>(
CPLCalloc(sizeof(OGRSpatialReferenceH), 2));
pahRet[0] = reinterpret_cast<OGRSpatialReferenceH>(oSRSClone.Clone());
if( pnEntries )
*pnEntries = 1;
if( ppanMatchConfidence )
OGRSpatialReference oSRSClone(*this);
if( oSRSClone.AutoIdentifyEPSG() == OGRERR_NONE )
{
*ppanMatchConfidence = static_cast<int*>(CPLMalloc(sizeof(int)));
(*ppanMatchConfidence)[0] = 100;
const char* pszCode = oSRSClone.GetAuthorityCode(nullptr);
if( pszCode )
oSRSClone.importFromEPSG(atoi(pszCode));
if( IsSame( &oSRSClone ) )
{
OGRSpatialReferenceH* pahRet =
static_cast<OGRSpatialReferenceH*>(
CPLCalloc(sizeof(OGRSpatialReferenceH), 2));
pahRet[0] = reinterpret_cast<OGRSpatialReferenceH>(oSRSClone.Clone());
if( pnEntries )
*pnEntries = 1;
if( ppanMatchConfidence )
{
*ppanMatchConfidence = static_cast<int*>(CPLMalloc(sizeof(int)));
(*ppanMatchConfidence)[0] = 100;
}
return pahRet;
}
}
return pahRet;
}
const char* pszSRSType = "";

0 comments on commit a7e53cd

Please sign in to comment.