Change CRS serialization/deserialization for geometry parameter value

This commit is contained in:
David Marteau 2020-09-10 10:50:14 +02:00 committed by Nyall Dawson
parent 6262965df9
commit fc67ddc970
5 changed files with 13 additions and 18 deletions

View File

@ -160,7 +160,7 @@ Construct a new QgsReferencedGeometry from referenced ``point``
static QgsReferencedGeometry fromReferencedRect( const QgsReferencedRectangle &rectangle );
%Docstring
Construct a new QgsReferencedGeometry from ``referenced`` point
Construct a new QgsReferencedGeometry from referenced ``rectangle``
%End

View File

@ -179,7 +179,7 @@ class CORE_EXPORT QgsReferencedGeometry : public QgsGeometry, public QgsReferenc
static QgsReferencedGeometry fromReferencedPointXY( const QgsReferencedPointXY &point );
/**
* Construct a new QgsReferencedGeometry from \a referenced point
* Construct a new QgsReferencedGeometry from referenced \a rectangle
*/
static QgsReferencedGeometry fromReferencedRect( const QgsReferencedRectangle &rectangle );

View File

@ -1509,8 +1509,7 @@ QgsGeometry QgsProcessingParameters::parameterAsGeometry( const QgsProcessingPar
if ( valueAsString.isEmpty() )
return QgsGeometry();
// Match against EWKT
QRegularExpression rx( QStringLiteral( "^\\s*(?:SRID=(.*);)?(.*)$" ) );
QRegularExpression rx( QStringLiteral( "^\\s*(?:CRS=(.*);)?(.*)$" ) );
QRegularExpressionMatch match = rx.match( valueAsString );
if ( match.hasMatch() )
@ -1518,7 +1517,7 @@ QgsGeometry QgsProcessingParameters::parameterAsGeometry( const QgsProcessingPar
QgsGeometry g = QgsGeometry::fromWkt( match.captured( 2 ) );
if ( !g.isNull() )
{
QgsCoordinateReferenceSystem geomCrs( QStringLiteral( "EPSG:%1" ).arg( match.captured( 1 ) ) );
QgsCoordinateReferenceSystem geomCrs( QStringLiteral( "%1" ).arg( match.captured( 1 ) ) );
if ( crs.isValid() && geomCrs.isValid() && crs != geomCrs )
{
QgsCoordinateTransform ct( geomCrs, crs, context.project() );
@ -1575,13 +1574,13 @@ QgsCoordinateReferenceSystem QgsProcessingParameters::parameterAsGeometryCrs( co
}
// Match against EWKT
QRegularExpression rx( QStringLiteral( "^\\s*(?:SRID=(.*);)?(.*)$" ) );
QRegularExpression rx( QStringLiteral( "^\\s*(?:CRS=(.*);)?(.*)$" ) );
QString valueAsString = parameterAsString( definition, value, context );
QRegularExpressionMatch match = rx.match( valueAsString );
if ( match.hasMatch() )
{
QgsCoordinateReferenceSystem crs( QStringLiteral( "EPSG:%1" ).arg( match.captured( 1 ) ) );
QgsCoordinateReferenceSystem crs( QStringLiteral( "%1" ).arg( match.captured( 1 ) ) );
if ( crs.isValid() )
return crs;
}
@ -3012,7 +3011,7 @@ bool QgsProcessingParameterGeometry::checkValueIsAcceptable( const QVariant &inp
}
// Match against EWKT
QRegularExpression rx( QStringLiteral( "^\\s*(?:SRID=(.*);)?(.*)$" ) );
QRegularExpression rx( QStringLiteral( "^\\s*(?:CRS=(.*);)?(.*)$" ) );
QRegularExpressionMatch match = rx.match( input.toString() );
if ( match.hasMatch() )
@ -3037,8 +3036,7 @@ QString QgsProcessingParameterGeometry::valueAsPythonString( const QVariant &val
if ( authid.isEmpty() )
return QStringLiteral( "'%1'" ).arg( g.asWkt() );
else
// Output as EWKT
return QStringLiteral( "'%2;%1'" ).arg( g.asWkt(), authid.replace( "EPSG:", "SRID=" ) );
return QStringLiteral( "'CRS=%2;%1'" ).arg( g.asWkt(), authid );
};
if ( !value.isValid() )

View File

@ -3413,7 +3413,7 @@ void TestQgsProcessing::parameterGeometry()
QCOMPARE( geometry.asWkt(), QStringLiteral( "LineString (10 10, 20 20)" ) );
// with CRS as string
params.insert( "non_optional", QString( "SRID=4326;Point ( 1.1 2.2 )" ) );
params.insert( "non_optional", QString( "CRS=EPSG:4326;Point ( 1.1 2.2 )" ) );
geometry = QgsProcessingParameters::parameterAsGeometry( def.get(), params, context );
QPointF point = geometry.asQPointF();
QGSCOMPARENEAR( point.x(), 1.1, 0.001 );
@ -3500,7 +3500,7 @@ void TestQgsProcessing::parameterGeometry()
// With Srid as string
QCOMPARE( def->valueAsPythonString( QgsReferencedGeometry( QgsGeometry::fromWkt( QStringLiteral( "LineString( 10 10, 20 20)" ) ),
QgsCoordinateReferenceSystem( "EPSG:4326" ) ), context ),
QStringLiteral( "'SRID=4326;LineString (10 10, 20 20)'" ) );
QStringLiteral( "'CRS=EPSG:4326;LineString (10 10, 20 20)'" ) );
QString pythonCode = def->asPythonString();
QCOMPARE( pythonCode, QStringLiteral( "QgsProcessingParameterGeometry('non_optional', '', defaultValue='Point(1 2)')" ) );

View File

@ -33,7 +33,6 @@ from qgis.core import (
start_app()
class TestQgsProcessingParameters(unittest.TestCase):
@classmethod
@ -48,15 +47,13 @@ class TestQgsProcessingParameters(unittest.TestCase):
cls.registry = QgsApplication.instance().processingRegistry()
def test_qgsprocessinggometry(self): # spellok
""" Test QgsProcessingParameterGeometry initialisation
"""
""" Test QgsProcessingParameterGeometry initialization """
geomtypes = [QgsWkbTypes.PointGeometry, QgsWkbTypes.PolygonGeometry]
param = QgsProcessingParameterGeometry( name='test', geometryTypes=geomtypes)
param = QgsProcessingParameterGeometry(name='test', geometryTypes=geomtypes)
types = param.geometryTypes()
self.assertEqual( param.geometryTypes(), geomtypes)
self.assertEqual(param.geometryTypes(), geomtypes)
if __name__ == '__main__':