26QString QgsRectanglesOvalsDiamondsAlgorithm::name()
const
28 return QStringLiteral(
"rectanglesovalsdiamonds" );
31QString QgsRectanglesOvalsDiamondsAlgorithm::displayName()
const
33 return QObject::tr(
"Rectangles, ovals, diamonds" );
36QStringList QgsRectanglesOvalsDiamondsAlgorithm::tags()
const
38 return QObject::tr(
"buffer,grow,fixed,variable,distance,rectangle,oval,diamond,point" ).split(
',' );
41QString QgsRectanglesOvalsDiamondsAlgorithm::group()
const
43 return QObject::tr(
"Vector geometry" );
46QString QgsRectanglesOvalsDiamondsAlgorithm::groupId()
const
48 return QStringLiteral(
"vectorgeometry" );
51QString QgsRectanglesOvalsDiamondsAlgorithm::shortHelpString()
const
53 return QObject::tr(
"This algorithm creates rectangle, oval or diamond-shaped polygons from the input point layer using "
54 "specified width, height and (optional) rotation values. Multipart inputs should be promoted "
55 "to singleparts first." );
58QString QgsRectanglesOvalsDiamondsAlgorithm::shortDescription()
const
60 return QObject::tr(
"Creates rectangle, oval or diamond-shaped polygons from an input point layer." );
63QIcon QgsRectanglesOvalsDiamondsAlgorithm::icon()
const
68QString QgsRectanglesOvalsDiamondsAlgorithm::svgIconPath()
const
73QString QgsRectanglesOvalsDiamondsAlgorithm::outputName()
const
75 return QObject::tr(
"Polygon" );
78QList<int> QgsRectanglesOvalsDiamondsAlgorithm::inputLayerTypes()
const
100 return outputWkbType;
103QgsRectanglesOvalsDiamondsAlgorithm *QgsRectanglesOvalsDiamondsAlgorithm::createInstance()
const
105 return new QgsRectanglesOvalsDiamondsAlgorithm();
108void QgsRectanglesOvalsDiamondsAlgorithm::initParameters(
const QVariantMap & )
110 addParameter(
new QgsProcessingParameterEnum( QStringLiteral(
"SHAPE" ), QObject::tr(
"Shape" ), QStringList() << QObject::tr(
"Rectangle" ) << QObject::tr(
"Diamond" ) << QObject::tr(
"Oval" ),
false, 0 ) );
112 auto widthParam = std::make_unique<QgsProcessingParameterDistance>( QStringLiteral(
"WIDTH" ), QObject::tr(
"Width" ), 1.0, QStringLiteral(
"INPUT" ),
false, 0.0 );
113 widthParam->setIsDynamic(
true );
115 widthParam->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
116 addParameter( widthParam.release() );
118 auto heightParam = std::make_unique<QgsProcessingParameterDistance>( QStringLiteral(
"HEIGHT" ), QObject::tr(
"Height" ), 1.0, QStringLiteral(
"INPUT" ),
false, 0.0 );
119 heightParam->setIsDynamic(
true );
121 heightParam->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
122 addParameter( heightParam.release() );
125 rotationParam->setIsDynamic(
true );
127 rotationParam->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
128 addParameter( rotationParam.release() );
135 mShape = parameterAsEnum( parameters, QStringLiteral(
"SHAPE" ), context );
137 mWidth = parameterAsDouble( parameters, QStringLiteral(
"WIDTH" ), context );
140 mWidthProperty = parameters.value( QStringLiteral(
"WIDTH" ) ).value<
QgsProperty>();
142 mHeight = parameterAsDouble( parameters, QStringLiteral(
"HEIGHT" ), context );
144 if ( mDynamicHeight )
145 mHeightProperty = parameters.value( QStringLiteral(
"HEIGHT" ) ).value<
QgsProperty>();
147 mRotation = parameterAsDouble( parameters, QStringLiteral(
"ROTATION" ), context );
149 if ( mDynamicRotation )
150 mRotationProperty = parameters.value( QStringLiteral(
"ROTATION" ) ).value<
QgsProperty>();
152 mSegments = parameterAsDouble( parameters, QStringLiteral(
"SEGMENTS" ), context );
165 throw QgsProcessingException( QObject::tr(
"Multipart geometry. Please promote input layer to singleparts first." ) );
168 double width = mWidth;
172 double height = mHeight;
173 if ( mDynamicHeight )
176 double rotation = mRotation;
177 if ( mDynamicRotation )
180 if ( width == 0 || height == 0 )
185 const double phi = rotation * M_PI / 180;
186 const double xOffset = width / 2.0;
187 const double yOffset = height / 2.0;
189 const double x = point.
x();
190 const double y = point.
y();
192 QVector<double> ringX( 5 );
193 QVector<double> ringY( 5 );
199 ringX = { -xOffset + x, -xOffset + x, xOffset + x, xOffset + x, -xOffset + x };
200 ringY = { -yOffset + y, yOffset + y, yOffset + y, -yOffset + y, -yOffset + y };
204 ringX = { x, -xOffset + x, x, xOffset + x, x };
205 ringY = { -yOffset + y, y, yOffset + y, y, -yOffset + y };
209 ringX.resize( mSegments + 1 );
210 ringY.resize( mSegments + 1 );
211 for (
int i = 0; i < mSegments; i++ )
213 const double t = ( 2 * M_PI ) / mSegments * i;
214 ringX[i] = xOffset * cos( t ) + x;
215 ringY[i] = yOffset * sin( t ) + y;
217 ringX[mSegments] = ringX.at( 0 );
218 ringY[mSegments] = ringY.at( 0 );
224 for (
int i = 0; i < ringX.size(); ++i )
226 const double px = ringX.at( i );
227 const double py = ringY.at( i );
228 ringX[i] = ( px - x ) * cos( phi ) + ( py - y ) * sin( phi ) + x;
229 ringY[i] = -( px - x ) * sin( phi ) + ( py - y ) * cos( phi ) + y;
233 auto poly = std::make_unique<QgsPolygon>();
ProcessingSourceType
Processing data source types.
@ VectorPoint
Vector point layers.
@ VectorPolygon
Vector polygon layers.
WkbType
The WKB type describes the number of dimensions a geometry has.
@ Double
Double/float values.
bool isMeasure() const
Returns true if the geometry contains m values.
bool is3D() const
Returns true if the geometry is 3D and contains a z-value.
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
static QString iconPath(const QString &iconFile)
Returns path to the desired icon file.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
bool hasGeometry() const
Returns true if the feature has an associated geometry.
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
A geometry is the spatial representation of a feature.
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
QgsPointXY asPoint() const
Returns the contents of the geometry as a 2-dimensional point.
bool isMultipart() const
Returns true if WKB of the geometry is of WKBMulti* type.
Line string geometry type, with support for z-dimension and m-values.
Point geometry type, with support for z-dimension and m-values.
Contains information about the context in which a processing algorithm is executed.
QgsExpressionContext & expressionContext()
Returns the expression context.
Custom exception class for processing related exceptions.
Base class for providing feedback from a processing algorithm.
An enum based parameter for processing algorithms, allowing for selection from predefined values.
A numeric parameter for processing algorithms.
static bool isDynamic(const QVariantMap ¶meters, const QString &name)
Returns true if the parameter with matching name is a dynamic parameter, and must be evaluated once f...
Definition for a property.
@ Double
Double value (including negative values).
@ DoublePositive
Positive double value (including 0).
A store for object properties.
double valueAsDouble(const QgsExpressionContext &context, double defaultValue=0.0, bool *ok=nullptr) const
Calculates the current value of the property and interprets it as a double.
static Qgis::WkbType addM(Qgis::WkbType type)
Adds the m dimension to a WKB type and returns the new type.
static Qgis::WkbType addZ(Qgis::WkbType type)
Adds the z dimension to a WKB type and returns the new type.
static Q_INVOKABLE bool hasZ(Qgis::WkbType type)
Tests whether a WKB type contains the z-dimension.
static Q_INVOKABLE bool hasM(Qgis::WkbType type)
Tests whether a WKB type contains m values.
QList< QgsFeature > QgsFeatureList