Skip to content
Permalink
Browse files

Improve python repr string for QgsCoordinateReferenceSystem

- Indicate invalid crses
- If crs doesn't have an authid, use wkt representation
  • Loading branch information
nyalldawson committed Jan 11, 2021
1 parent e0ad337 commit f8e5e0bf7e334098870ce9f2df9a6381e56a499f
@@ -860,7 +860,8 @@ Returns auth id of related geographic CRS

SIP_PYOBJECT __repr__();
%MethodCode
QString str = QStringLiteral( "<QgsCoordinateReferenceSystem: %1>" ).arg( sipCpp->authid() );
const QString str = sipCpp->isValid() ? QStringLiteral( "<QgsCoordinateReferenceSystem: %1>" ).arg( !sipCpp->authid().isEmpty() ? sipCpp->authid() : sipCpp->toWkt( QgsCoordinateReferenceSystem::WKT_PREFERRED ) )
: QStringLiteral( "<QgsCoordinateReferenceSystem: invalid>" );
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
%End

@@ -792,7 +792,8 @@ class CORE_EXPORT QgsCoordinateReferenceSystem
#ifdef SIP_RUN
SIP_PYOBJECT __repr__();
% MethodCode
QString str = QStringLiteral( "<QgsCoordinateReferenceSystem: %1>" ).arg( sipCpp->authid() );
const QString str = sipCpp->isValid() ? QStringLiteral( "<QgsCoordinateReferenceSystem: %1>" ).arg( !sipCpp->authid().isEmpty() ? sipCpp->authid() : sipCpp->toWkt( QgsCoordinateReferenceSystem::WKT_PREFERRED ) )
: QStringLiteral( "<QgsCoordinateReferenceSystem: invalid>" );
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
% End
#endif
@@ -182,6 +182,8 @@ def testQgsReferencedGeometryRepr(self):
self.assertEqual(g.__repr__(), '<QgsReferencedGeometry: Point (1 2) (EPSG:4326)>')

def testQgsCoordinateReferenceSystem(self):
crs = QgsCoordinateReferenceSystem()
self.assertEqual(crs.__repr__(), '<QgsCoordinateReferenceSystem: invalid>')
crs = QgsCoordinateReferenceSystem('EPSG:4326')
self.assertEqual(crs.__repr__(), '<QgsCoordinateReferenceSystem: EPSG:4326>')
crs = QgsCoordinateReferenceSystem('EPSG:3111')

0 comments on commit f8e5e0b

Please sign in to comment.
You can’t perform that action at this time.