25QString QgsRectanglesOvalsDiamondsAlgorithm::name()
const
27 return QStringLiteral(
"rectanglesovalsdiamonds" );
30QString QgsRectanglesOvalsDiamondsAlgorithm::displayName()
const
32 return QObject::tr(
"Rectangles, ovals, diamonds" );
35QStringList QgsRectanglesOvalsDiamondsAlgorithm::tags()
const
37 return QObject::tr(
"buffer,grow,fixed,variable,distance,rectangle,oval,diamond,point" ).split(
',' );
40QString QgsRectanglesOvalsDiamondsAlgorithm::group()
const
42 return QObject::tr(
"Vector geometry" );
45QString QgsRectanglesOvalsDiamondsAlgorithm::groupId()
const
47 return QStringLiteral(
"vectorgeometry" );
50QString QgsRectanglesOvalsDiamondsAlgorithm::shortHelpString()
const
52 return QObject::tr(
"Creates rectangle, oval or diamond-shaped polygons from the input point layer using "
53 "specified width, height and (optional) rotation values. Multipart inputs should be promoted "
54 "to singleparts first." );
57QIcon QgsRectanglesOvalsDiamondsAlgorithm::icon()
const
62QString QgsRectanglesOvalsDiamondsAlgorithm::svgIconPath()
const
67QString QgsRectanglesOvalsDiamondsAlgorithm::outputName()
const
69 return QObject::tr(
"Polygon" );
72QList<int> QgsRectanglesOvalsDiamondsAlgorithm::inputLayerTypes()
const
97QgsRectanglesOvalsDiamondsAlgorithm *QgsRectanglesOvalsDiamondsAlgorithm::createInstance()
const
99 return new QgsRectanglesOvalsDiamondsAlgorithm();
102void QgsRectanglesOvalsDiamondsAlgorithm::initParameters(
const QVariantMap & )
104 addParameter(
new QgsProcessingParameterEnum( QStringLiteral(
"SHAPE" ), QObject::tr(
"Shape" ), QStringList() << QObject::tr(
"Rectangle" ) << QObject::tr(
"Diamond" ) << QObject::tr(
"Oval" ),
false, 0 ) );
106 auto widthParam = std::make_unique < QgsProcessingParameterDistance >( QStringLiteral(
"WIDTH" ), QObject::tr(
"Width" ), 1.0, QStringLiteral(
"INPUT" ),
false, 0.0 );
107 widthParam->setIsDynamic(
true );
109 widthParam->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
110 addParameter( widthParam.release() );
112 auto heightParam = std::make_unique < QgsProcessingParameterDistance >( QStringLiteral(
"HEIGHT" ), QObject::tr(
"Height" ), 1.0, QStringLiteral(
"INPUT" ),
false, 0.0 );
113 heightParam->setIsDynamic(
true );
115 heightParam->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
116 addParameter( heightParam.release() );
118 auto rotationParam = std::make_unique < QgsProcessingParameterNumber >( QStringLiteral(
"ROTATION" ), QObject::tr(
"Rotation" ),
QgsProcessingParameterNumber::Double, 0.0,
true, -360.0, 360.0 );
119 rotationParam->setIsDynamic(
true );
121 rotationParam->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
122 addParameter( rotationParam.release() );
129 mShape = parameterAsEnum( parameters, QStringLiteral(
"SHAPE" ), context );
131 mWidth = parameterAsDouble( parameters, QStringLiteral(
"WIDTH" ), context );
134 mWidthProperty = parameters.value( QStringLiteral(
"WIDTH" ) ).value<
QgsProperty >();
136 mHeight = parameterAsDouble( parameters, QStringLiteral(
"HEIGHT" ), context );
138 if ( mDynamicHeight )
139 mHeightProperty = parameters.value( QStringLiteral(
"HEIGHT" ) ).value<
QgsProperty >();
141 mRotation = parameterAsDouble( parameters, QStringLiteral(
"ROTATION" ), context );
143 if ( mDynamicRotation )
144 mRotationProperty = parameters.value( QStringLiteral(
"ROTATION" ) ).value<
QgsProperty >();
146 mSegments = parameterAsDouble( parameters, QStringLiteral(
"SEGMENTS" ), context );
159 throw QgsProcessingException( QObject::tr(
"Multipart geometry. Please promote input layer to singleparts first." ) );
162 double width = mWidth;
166 double height = mHeight;
167 if ( mDynamicHeight )
170 double rotation = mRotation;
171 if ( mDynamicRotation )
174 if ( width == 0 || height == 0 )
179 const double phi = rotation * M_PI / 180;
180 const double xOffset = width / 2.0;
181 const double yOffset = height / 2.0;
183 const double x = point.
x();
184 const double y = point.
y();
186 QVector< double > ringX( 5 );
187 QVector< double > ringY( 5 );
193 ringX = { -xOffset + x, -xOffset + x, xOffset + x, xOffset + x, -xOffset + x };
194 ringY = { -yOffset + y, yOffset + y, yOffset + y, -yOffset + y, -yOffset + y };
198 ringX = { x, -xOffset + x, x, xOffset + x, x };
199 ringY = { -yOffset + y, y, yOffset + y, y, -yOffset + y };
203 ringX.resize( mSegments + 1 );
204 ringY.resize( mSegments + 1 );
205 for (
int i = 0; i < mSegments; i ++ )
207 const double t = ( 2 * M_PI ) / mSegments * i;
208 ringX[ i ] = xOffset * cos( t ) + x;
209 ringY[ i ] = yOffset * sin( t ) + y;
211 ringX[ mSegments ] = ringX.at( 0 );
212 ringY[ mSegments ] = ringY.at( 0 );
218 for (
int i = 0; i < ringX.size(); ++i )
220 const double px = ringX.at( i );
221 const double py = ringY.at( i );
222 ringX[ i ] = ( px - x ) * cos( phi ) + ( py - y ) * sin( phi ) + x;
223 ringY[ i ] = -( px - x ) * sin( phi ) + ( py - y ) * cos( phi ) + y;
227 std::unique_ptr< QgsPolygon > poly = std::make_unique< QgsPolygon >();
WkbType
The WKB type describes the number of dimensions a geometry has.
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.
A class to represent a 2D point.
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.
@ Double
Double/float values.
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...
SourceType
Data source types enum.
@ TypeVectorPolygon
Vector polygon layers.
@ TypeVectorPoint
Vector point layers.
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 bool hasZ(Qgis::WkbType type)
Tests whether a WKB type contains the z-dimension.
static bool hasM(Qgis::WkbType type)
Tests whether a WKB type contains m values.
QList< QgsFeature > QgsFeatureList