Skip to content

Commit

Permalink
Support point and rectangle as geometry parameter values
Browse files Browse the repository at this point in the history
  • Loading branch information
dmarteau authored and nyalldawson committed Sep 14, 2020
1 parent 4eb7797 commit f2b8e69
Show file tree
Hide file tree
Showing 12 changed files with 390 additions and 33 deletions.
Expand Up @@ -86,8 +86,6 @@ Constructor for QgsReferencedGeometry.
};




class QgsReferencedRectangle : QgsRectangle, QgsReferencedGeometryBase
{
%Docstring
Expand Down
Expand Up @@ -851,6 +851,26 @@ Returns the coordinate reference system associated with an point parameter value
.. seealso:: :py:func:`parameterAsPoint`
%End

QgsGeometry parameterAsGeometry( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context,
const QgsCoordinateReferenceSystem &crs = QgsCoordinateReferenceSystem() ) const;
%Docstring
Evaluates the parameter with matching ``name`` to a geometry.

If ``crs`` is set then the geometry will be automatically
reprojected so that it is in the specified ``crs``.

.. seealso:: :py:func:`parameterAsGeometryCrs`
%End

QgsCoordinateReferenceSystem parameterAsGeometryCrs( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context );
%Docstring
Returns the coordinate reference system associated with a geometry parameter value.

.. seealso:: :py:func:`parameterAsGeometry`
%End



QString parameterAsFile( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const;
%Docstring
Evaluates the parameter with matching ``name`` to a file/folder name.
Expand Down
Expand Up @@ -1174,17 +1174,35 @@ Returns the coordinate reference system associated with an point parameter value
.. versionadded:: 3.8
%End

static QgsGeometry parameterAsGeometry( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context );
static QgsGeometry parameterAsGeometry( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs = QgsCoordinateReferenceSystem() );
%Docstring
Evaluates the parameter with matching ``definition`` to a geometry.

.. versionadded:: 3.16
%End

static QgsGeometry parameterAsGeometry( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context );
static QgsGeometry parameterAsGeometry( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs = QgsCoordinateReferenceSystem() );
%Docstring
Evaluates the parameter with matching ``definition`` and ``value`` to a geometry.

.. versionadded:: 3.16
%End

static QgsCoordinateReferenceSystem parameterAsGeometryCrs( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context );
%Docstring
Returns the coordinate reference system associated with a geometry parameter value.

.. seealso:: :py:func:`parameterAsGeometry`

.. versionadded:: 3.16
%End

static QgsCoordinateReferenceSystem parameterAsGeometryCrs( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context );
%Docstring
Returns the coordinate reference system associated with an point parameter value.

.. seealso:: :py:func:`parameterAsGeometry`

.. versionadded:: 3.16
%End

Expand Down
2 changes: 0 additions & 2 deletions src/core/geometry/qgsreferencedgeometry.h
Expand Up @@ -103,8 +103,6 @@ class CORE_EXPORT QgsReferencedGeometry : public QgsGeometry, public QgsReferenc

Q_DECLARE_METATYPE( QgsReferencedGeometry )



/**
* \ingroup core
* A QgsRectangle with associated coordinate reference system.
Expand Down
24 changes: 24 additions & 0 deletions src/core/processing/qgsprocessingalgorithm.cpp
Expand Up @@ -267,6 +267,20 @@ bool QgsProcessingAlgorithm::validateInputCrs( const QVariantMap &parameters, Qg
crs = pointCrs;
}
}
else if ( def->type() == QgsProcessingParameterGeometry::typeName() )
{
QgsCoordinateReferenceSystem geomCrs = QgsProcessingParameters::parameterAsGeometryCrs( def, parameters, context );
if ( foundCrs && geomCrs.isValid() && crs != geomCrs )
{
return false;
}
else if ( !foundCrs && geomCrs.isValid() )
{
foundCrs = true;
crs = geomCrs;
}
}

}
return true;
}
Expand Down Expand Up @@ -693,6 +707,16 @@ QgsCoordinateReferenceSystem QgsProcessingAlgorithm::parameterAsPointCrs( const
return QgsProcessingParameters::parameterAsPointCrs( parameterDefinition( name ), parameters, context );
}

QgsGeometry QgsProcessingAlgorithm::parameterAsGeometry( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs ) const
{
return QgsProcessingParameters::parameterAsGeometry( parameterDefinition( name ), parameters, context, crs );
}

QgsCoordinateReferenceSystem QgsProcessingAlgorithm::parameterAsGeometryCrs( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context )
{
return QgsProcessingParameters::parameterAsGeometryCrs( parameterDefinition( name ), parameters, context );
}

QString QgsProcessingAlgorithm::parameterAsFile( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
{
return QgsProcessingParameters::parameterAsFile( parameterDefinition( name ), parameters, context );
Expand Down
20 changes: 20 additions & 0 deletions src/core/processing/qgsprocessingalgorithm.h
Expand Up @@ -855,6 +855,26 @@ class CORE_EXPORT QgsProcessingAlgorithm
*/
QgsCoordinateReferenceSystem parameterAsPointCrs( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context );

/**
* Evaluates the parameter with matching \a name to a geometry.
*
* If \a crs is set then the geometry will be automatically
* reprojected so that it is in the specified \a crs.
*
* \see parameterAsGeometryCrs()
*/
QgsGeometry parameterAsGeometry( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context,
const QgsCoordinateReferenceSystem &crs = QgsCoordinateReferenceSystem() ) const;

/**
* Returns the coordinate reference system associated with a geometry parameter value.
*
* \see parameterAsGeometry()
*/
QgsCoordinateReferenceSystem parameterAsGeometryCrs( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context );



/**
* Evaluates the parameter with matching \a name to a file/folder name.
*/
Expand Down

0 comments on commit f2b8e69

Please sign in to comment.