Skip to content
Permalink
Browse files

Add geometry filter for processing geometry parameter

  • Loading branch information
dmarteau authored and nyalldawson committed Sep 14, 2020
1 parent f2b8e69 commit aa0a8ab6287842240c6b796937d0fd83e81bf0bf
@@ -51,45 +51,48 @@ no reference system is required.

};

class QgsReferencedGeometry : QgsGeometry, QgsReferencedGeometryBase
class QgsReferencedRectangle : QgsRectangle, QgsReferencedGeometryBase
{
%Docstring
A QgsGeometry with associated coordinate reference system.
A QgsRectangle with associated coordinate reference system.

.. versionadded:: 3.16
.. versionadded:: 3.0
%End

%TypeHeaderCode
#include "qgsreferencedgeometry.h"
%End
public:

QgsReferencedGeometry( const QgsGeometry &geometry, const QgsCoordinateReferenceSystem &crs );
QgsReferencedRectangle( const QgsRectangle &rectangle, const QgsCoordinateReferenceSystem &crs );
%Docstring
Constructor for QgsReferencedGeometry, with the specified initial ``geometry``
Constructor for QgsReferencedRectangle, with the specified initial ``rectangle``
and ``crs``.
%End

QgsReferencedGeometry();
QgsReferencedRectangle();
%Docstring
Constructor for QgsReferencedGeometry.
Constructor for QgsReferencedRectangle.
%End

operator QVariant() const;

bool operator==( const QgsReferencedRectangle &other );
bool operator!=( const QgsReferencedRectangle &other );

SIP_PYOBJECT __repr__();
%MethodCode
QString str = QStringLiteral( "<QgsReferencedGeometry: %1 (%2)>" ).arg( sipCpp->asWkt(), sipCpp->crs().authid() );
QString str = QStringLiteral( "<QgsReferencedRectangle: %1 (%2)>" ).arg( sipCpp->asWktCoordinates(), sipCpp->crs().authid() );
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
%End

};


class QgsReferencedRectangle : QgsRectangle, QgsReferencedGeometryBase
class QgsReferencedPointXY : QgsPointXY, QgsReferencedGeometryBase
{
%Docstring
A QgsRectangle with associated coordinate reference system.
A QgsPointXY with associated coordinate reference system.

.. versionadded:: 3.0
%End
@@ -99,70 +102,77 @@ A QgsRectangle with associated coordinate reference system.
%End
public:

QgsReferencedRectangle( const QgsRectangle &rectangle, const QgsCoordinateReferenceSystem &crs );
QgsReferencedPointXY( const QgsPointXY &point, const QgsCoordinateReferenceSystem &crs );
%Docstring
Constructor for QgsReferencedRectangle, with the specified initial ``rectangle``
Constructor for QgsReferencedPointXY, with the specified initial ``point``
and ``crs``.
%End

QgsReferencedRectangle();
QgsReferencedPointXY();
%Docstring
Constructor for QgsReferencedRectangle.
Constructor for QgsReferencedPointXY.
%End

operator QVariant() const;

bool operator==( const QgsReferencedRectangle &other );
bool operator!=( const QgsReferencedRectangle &other );
bool operator==( const QgsReferencedPointXY &other );
bool operator!=( const QgsReferencedPointXY &other );

SIP_PYOBJECT __repr__();
%MethodCode
QString str = QStringLiteral( "<QgsReferencedRectangle: %1 (%2)>" ).arg( sipCpp->asWktCoordinates(), sipCpp->crs().authid() );
QString str = QStringLiteral( "<QgsReferencedPointXY: %1 (%2)>" ).arg( sipCpp->asWkt(), sipCpp->crs().authid() );
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
%End

};


class QgsReferencedPointXY : QgsPointXY, QgsReferencedGeometryBase
class QgsReferencedGeometry : QgsGeometry, QgsReferencedGeometryBase
{
%Docstring
A QgsPointXY with associated coordinate reference system.
A QgsGeometry with associated coordinate reference system.

.. versionadded:: 3.0
.. versionadded:: 3.16
%End

%TypeHeaderCode
#include "qgsreferencedgeometry.h"
%End
public:

QgsReferencedPointXY( const QgsPointXY &point, const QgsCoordinateReferenceSystem &crs );
QgsReferencedGeometry( const QgsGeometry &geometry, const QgsCoordinateReferenceSystem &crs );
%Docstring
Constructor for QgsReferencedPointXY, with the specified initial ``point``
Constructor for QgsReferencedGeometry, with the specified initial ``geometry``
and ``crs``.
%End

QgsReferencedPointXY();
QgsReferencedGeometry();
%Docstring
Constructor for QgsReferencedPointXY.
Constructor for QgsReferencedGeometry.
%End

operator QVariant() const;

bool operator==( const QgsReferencedPointXY &other );
bool operator!=( const QgsReferencedPointXY &other );
static QgsReferencedGeometry fromReferencedPointXY( const QgsReferencedPointXY &point );
%Docstring
Construct a new QgsReferencedGeometry from referenced ``point``
%End

static QgsReferencedGeometry fromReferencedRect( const QgsReferencedRectangle &rectangle );
%Docstring
Construct a new QgsReferencedGeometry from ``referenced`` point
%End


SIP_PYOBJECT __repr__();
%MethodCode
QString str = QStringLiteral( "<QgsReferencedPointXY: %1 (%2)>" ).arg( sipCpp->asWkt(), sipCpp->crs().authid() );
QString str = QStringLiteral( "<QgsReferencedGeometry: %1 (%2)>" ).arg( sipCpp->asWkt(), sipCpp->crs().authid() );
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
%End

};



/************************************************************************
* This file has been generated automatically from *
* *
@@ -1574,9 +1574,12 @@ A geometry parameter for processing algorithms.
%End
public:

QgsProcessingParameterGeometry( const QString &name, const QString &description = QString(), const QVariant &defaultValue = QVariant(), bool optional = false );
QgsProcessingParameterGeometry( const QString &name, const QString &description = QString(), const QVariant &defaultValue = QVariant(), bool optional = false, const QList<QgsWkbTypes::GeometryType> &geometryTypes = QList<QgsWkbTypes::GeometryType>() );
%Docstring
Constructor for QgsProcessingParameterGeometry.

The ``geometryTypes`` argument allows for specifying a list of geometry types acceptable for this
parameter. Passing a empty list will allow for any type of geometry.
%End

static QString typeName();
@@ -1590,6 +1593,28 @@ Returns the type name for the parameter class.

virtual QString valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const;

virtual QString asScriptCode() const;

virtual QString asPythonString( QgsProcessing::PythonOutputType outputType = QgsProcessing::PythonQgsProcessingAlgorithmSubclass ) const;

virtual QVariantMap toVariantMap() const;

virtual bool fromVariantMap( const QVariantMap &map );


QList<QgsWkbTypes::GeometryType> geometryTypes() const;
%Docstring
Returns the parameter allowed geometries.

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

void setGeometryTypes( QList<QgsWkbTypes::GeometryType> geometryTypes );
%Docstring
Sets the allowed ``geometryTypes``.

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

static QgsProcessingParameterGeometry *fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) /Factory/;
%Docstring
@@ -30,6 +30,7 @@
QgsExpression,
QgsProject,
QgsRectangle,
QgsWkbTypes,
QgsVectorFileWriter,
QgsProcessing,
QgsProcessingUtils,
@@ -134,6 +135,11 @@ def getParameterFromString(s, context=''):
elif clazz == QgsProcessingParameterGeometry:
if len(params) > 3:
params[3] = True if params[3].lower() == 'true' else False
if len(params) > 4:
try:
params[4] = [int(p) for p in params[4].split(';')]
except:
params[4] = [getattr(QgsWkbTypes, p.split(".")[1]) for p in params[4].split(';')]
elif clazz == QgsProcessingParameterCrs:
if len(params) > 3:
params[3] = True if params[3].lower() == 'true' else False
@@ -56,4 +56,13 @@ QgsReferencedGeometry::QgsReferencedGeometry( const QgsGeometry &geom, const Qgs
, QgsReferencedGeometryBase( crs )
{}

QgsReferencedGeometry QgsReferencedGeometry::fromReferencedPointXY( const QgsReferencedPointXY &point )
{
return QgsReferencedGeometry( QgsGeometry::fromPointXY( point ), point.crs() );
}

QgsReferencedGeometry QgsReferencedGeometry::fromReferencedRect( const QgsReferencedRectangle &rectangle )
{
return QgsReferencedGeometry( QgsGeometry::fromRect( rectangle ), rectangle.crs() );
}

@@ -67,123 +67,133 @@ class CORE_EXPORT QgsReferencedGeometryBase

/**
* \ingroup core
* A QgsGeometry with associated coordinate reference system.
* \since QGIS 3.16
* A QgsRectangle with associated coordinate reference system.
* \since QGIS 3.0
*/
class CORE_EXPORT QgsReferencedGeometry : public QgsGeometry, public QgsReferencedGeometryBase
class CORE_EXPORT QgsReferencedRectangle : public QgsRectangle, public QgsReferencedGeometryBase
{
public:

/**
* Constructor for QgsReferencedGeometry, with the specified initial \a geometry
* Constructor for QgsReferencedRectangle, with the specified initial \a rectangle
* and \a crs.
*/
QgsReferencedGeometry( const QgsGeometry &geometry, const QgsCoordinateReferenceSystem &crs );
QgsReferencedRectangle( const QgsRectangle &rectangle, const QgsCoordinateReferenceSystem &crs );

/**
* Constructor for QgsReferencedGeometry.
* Constructor for QgsReferencedRectangle.
*/
QgsReferencedGeometry() = default;
QgsReferencedRectangle() = default;

//! Allows direct construction of QVariants from geometry.
//! Allows direct construction of QVariants from rectangle.
operator QVariant() const
{
return QVariant::fromValue( *this );
}

bool operator==( const QgsReferencedRectangle &other );
bool operator!=( const QgsReferencedRectangle &other );

#ifdef SIP_RUN
SIP_PYOBJECT __repr__();
% MethodCode
QString str = QStringLiteral( "<QgsReferencedGeometry: %1 (%2)>" ).arg( sipCpp->asWkt(), sipCpp->crs().authid() );
QString str = QStringLiteral( "<QgsReferencedRectangle: %1 (%2)>" ).arg( sipCpp->asWktCoordinates(), sipCpp->crs().authid() );
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
% End
#endif

};

Q_DECLARE_METATYPE( QgsReferencedGeometry )
Q_DECLARE_METATYPE( QgsReferencedRectangle )

/**
* \ingroup core
* A QgsRectangle with associated coordinate reference system.
* A QgsPointXY with associated coordinate reference system.
* \since QGIS 3.0
*/
class CORE_EXPORT QgsReferencedRectangle : public QgsRectangle, public QgsReferencedGeometryBase
class CORE_EXPORT QgsReferencedPointXY : public QgsPointXY, public QgsReferencedGeometryBase
{
public:

/**
* Constructor for QgsReferencedRectangle, with the specified initial \a rectangle
* Constructor for QgsReferencedPointXY, with the specified initial \a point
* and \a crs.
*/
QgsReferencedRectangle( const QgsRectangle &rectangle, const QgsCoordinateReferenceSystem &crs );
QgsReferencedPointXY( const QgsPointXY &point, const QgsCoordinateReferenceSystem &crs );

/**
* Constructor for QgsReferencedRectangle.
* Constructor for QgsReferencedPointXY.
*/
QgsReferencedRectangle() = default;
QgsReferencedPointXY() = default;

//! Allows direct construction of QVariants from rectangle.
//! Allows direct construction of QVariants from point.
operator QVariant() const
{
return QVariant::fromValue( *this );
}

bool operator==( const QgsReferencedRectangle &other );
bool operator!=( const QgsReferencedRectangle &other );
bool operator==( const QgsReferencedPointXY &other );
bool operator!=( const QgsReferencedPointXY &other );

#ifdef SIP_RUN
SIP_PYOBJECT __repr__();
% MethodCode
QString str = QStringLiteral( "<QgsReferencedRectangle: %1 (%2)>" ).arg( sipCpp->asWktCoordinates(), sipCpp->crs().authid() );
QString str = QStringLiteral( "<QgsReferencedPointXY: %1 (%2)>" ).arg( sipCpp->asWkt(), sipCpp->crs().authid() );
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
% End
#endif

};

Q_DECLARE_METATYPE( QgsReferencedRectangle )
Q_DECLARE_METATYPE( QgsReferencedPointXY )

/**
* \ingroup core
* A QgsPointXY with associated coordinate reference system.
* \since QGIS 3.0
* A QgsGeometry with associated coordinate reference system.
* \since QGIS 3.16
*/
class CORE_EXPORT QgsReferencedPointXY : public QgsPointXY, public QgsReferencedGeometryBase
class CORE_EXPORT QgsReferencedGeometry : public QgsGeometry, public QgsReferencedGeometryBase
{
public:

/**
* Constructor for QgsReferencedPointXY, with the specified initial \a point
* Constructor for QgsReferencedGeometry, with the specified initial \a geometry
* and \a crs.
*/
QgsReferencedPointXY( const QgsPointXY &point, const QgsCoordinateReferenceSystem &crs );
QgsReferencedGeometry( const QgsGeometry &geometry, const QgsCoordinateReferenceSystem &crs );

/**
* Constructor for QgsReferencedPointXY.
* Constructor for QgsReferencedGeometry.
*/
QgsReferencedPointXY() = default;
QgsReferencedGeometry() = default;

//! Allows direct construction of QVariants from point.
//! Allows direct construction of QVariants from geometry.
operator QVariant() const
{
return QVariant::fromValue( *this );
}

bool operator==( const QgsReferencedPointXY &other );
bool operator!=( const QgsReferencedPointXY &other );
/**
* Construct a new QgsReferencedGeometry from referenced \a point
*/
static QgsReferencedGeometry fromReferencedPointXY( const QgsReferencedPointXY &point );

/**
* Construct a new QgsReferencedGeometry from \a referenced point
*/
static QgsReferencedGeometry fromReferencedRect( const QgsReferencedRectangle &rectangle );


#ifdef SIP_RUN
SIP_PYOBJECT __repr__();
% MethodCode
QString str = QStringLiteral( "<QgsReferencedPointXY: %1 (%2)>" ).arg( sipCpp->asWkt(), sipCpp->crs().authid() );
QString str = QStringLiteral( "<QgsReferencedGeometry: %1 (%2)>" ).arg( sipCpp->asWkt(), sipCpp->crs().authid() );
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
% End
#endif

};

Q_DECLARE_METATYPE( QgsReferencedPointXY )

Q_DECLARE_METATYPE( QgsReferencedGeometry )

#endif // QGSREFERENCEDGEOMETRY_H

0 comments on commit aa0a8ab

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