[Qgis-developer] crs comparison inconsistencies

Carson Farmer carson.farmer at gmail.com
Wed Mar 16 13:57:09 EDT 2011


Hi devs,

I've noticed something with CRS comparison that (I think) bears
consideration. Below is an example from the QGIS Python console:

>>> mc = qgis.utils.iface.mapCanvas()
>>> first_layer = mc.layer(0)
>>> second_layer = mc.layer(1)
>>> first_layer.crs().toProj4()
PyQt4.QtCore.QString(u'+proj=tmerc +lat_0=53.5 +lon_0=-8 +k=1.000035
+x_0=200000 +y_0=250000 +ellps=mod_airy +units=m +no_defs')
>>> second_layer.crs().toProj4()
PyQt4.QtCore.QString(u'+proj=tmerc +lat_0=53.5 +lon_0=-8 +k=1.000035
+x_0=200000 +y_0=250000 +ellps=mod_airy +units=m +no_defs')
>>> first_layer.crs().toProj4() == second_layer.crs().toProj4()
True
>>> first_layer.crs() == second_layer.crs()
False

Ok, so that seems funny, so I checked further, turns out one is a user
defined CRS:
>>> first_layer.crs().authid()
PyQt4.QtCore.QString(u'EPSG:29902')
>>> second_layer.crs().authid()
PyQt4.QtCore.QString(u'USER:100000')
>>> first_layer.crs().toWkt()
PyQt4.QtCore.QString(u'PROJCS["unnamed",GEOGCS["unnamed
ellipse",DATUM["unknown",SPHEROID["unnamed",6377340.189,299.3249645999944]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",53.5],PARAMETER["central_meridian",-8],PARAMETER["scale_factor",1.000035],PARAMETER["false_easting",200000],PARAMETER["false_northing",250000],UNIT["Meter",1]]')
>>> second_layer.crs().toWkt()
PyQt4.QtCore.QString(u'PROJCS["unnamed",GEOGCS["Modified
Airy",DATUM["unknown",SPHEROID["mod_airy",6377340.189,299.3249373654873]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",53.5],PARAMETER["central_meridian",-8],PARAMETER["scale_factor",1.000035],PARAMETER["false_easting",200000],PARAMETER["false_northing",250000],UNIT["Meter",1]]')

Ok, so they aren't technically *exactly* the same... but for all
intents and purposes, they are equivalent. According to the docs, the
'equal()' function "use[s] OGR isSameCRS() or isSameGeoCRS() methods
as appropriate. Additionally logic may also be applied if the result
from the OGR methods is inconclusive." Has any additional logic been
applied? Would it perhaps be more appropriate to check for similarity
on multiple levels? I.E. something like:
if not crs1 == crs2:
    ok, but they might still be equivalent...
    if crs1.toProj4() == crs2.toProj4():
        return see, I told you!
    else:
        return fine, you were right all along
else:
    return aha, I knew it
return nope, sorry they aren't the same

Carson

-- 
Carson J. Q. Farmer
ISSP Doctoral Fellow
National Centre for Geocomputation
National University of Ireland, Maynooth,
http://www.carsonfarmer.com/


More information about the Qgis-developer mailing list