Skip to content
Permalink
Browse files

Change CRS serialization/deserialization for geometry parameter value

  • Loading branch information
dmarteau authored and nyalldawson committed Sep 14, 2020
1 parent 6262965 commit fc67ddc970a53f7e949330f60edb150c460565e4
@@ -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


@@ -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 );

@@ -1509,16 +1509,15 @@ 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() )
{
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() )
@@ -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)')" ) );
@@ -33,7 +33,6 @@
start_app()



class TestQgsProcessingParameters(unittest.TestCase):

@classmethod
@@ -48,15 +47,13 @@ def setUpClass(cls):
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__':

0 comments on commit fc67ddc

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