26using namespace Qt::StringLiterals;
30QString QgsRectanglesOvalsDiamondsAlgorithm::name()
const
32 return u
"rectanglesovalsdiamonds"_s;
35QString QgsRectanglesOvalsDiamondsAlgorithm::displayName()
const
37 return QObject::tr(
"Rectangles, ovals, diamonds" );
40QStringList QgsRectanglesOvalsDiamondsAlgorithm::tags()
const
42 return QObject::tr(
"buffer,grow,fixed,variable,distance,rectangle,oval,diamond,point" ).split(
',' );
45QString QgsRectanglesOvalsDiamondsAlgorithm::group()
const
47 return QObject::tr(
"Vector geometry" );
50QString QgsRectanglesOvalsDiamondsAlgorithm::groupId()
const
52 return u
"vectorgeometry"_s;
55QString QgsRectanglesOvalsDiamondsAlgorithm::shortHelpString()
const
57 return QObject::tr(
"This algorithm creates rectangle, oval or diamond-shaped polygons from the input point layer using "
58 "specified width, height and (optional) rotation values. Multipart inputs should be promoted "
59 "to singleparts first." );
62QString QgsRectanglesOvalsDiamondsAlgorithm::shortDescription()
const
64 return QObject::tr(
"Creates rectangle, oval or diamond-shaped polygons from an input point layer." );
67QIcon QgsRectanglesOvalsDiamondsAlgorithm::icon()
const
72QString QgsRectanglesOvalsDiamondsAlgorithm::svgIconPath()
const
77QString QgsRectanglesOvalsDiamondsAlgorithm::outputName()
const
79 return QObject::tr(
"Polygon" );
82QList<int> QgsRectanglesOvalsDiamondsAlgorithm::inputLayerTypes()
const
104 return outputWkbType;
107QgsRectanglesOvalsDiamondsAlgorithm *QgsRectanglesOvalsDiamondsAlgorithm::createInstance()
const
109 return new QgsRectanglesOvalsDiamondsAlgorithm();
112void QgsRectanglesOvalsDiamondsAlgorithm::initParameters(
const QVariantMap & )
114 addParameter(
new QgsProcessingParameterEnum( u
"SHAPE"_s, QObject::tr(
"Shape" ), QStringList() << QObject::tr(
"Rectangle" ) << QObject::tr(
"Diamond" ) << QObject::tr(
"Oval" ),
false, 0 ) );
116 auto widthParam = std::make_unique<QgsProcessingParameterDistance>( u
"WIDTH"_s, QObject::tr(
"Width" ), 1.0, u
"INPUT"_s,
false, 0.0 );
117 widthParam->setIsDynamic(
true );
119 widthParam->setDynamicLayerParameterName( u
"INPUT"_s );
120 addParameter( widthParam.release() );
122 auto heightParam = std::make_unique<QgsProcessingParameterDistance>( u
"HEIGHT"_s, QObject::tr(
"Height" ), 1.0, u
"INPUT"_s,
false, 0.0 );
123 heightParam->setIsDynamic(
true );
125 heightParam->setDynamicLayerParameterName( u
"INPUT"_s );
126 addParameter( heightParam.release() );
129 rotationParam->setIsDynamic(
true );
131 rotationParam->setDynamicLayerParameterName( u
"INPUT"_s );
132 addParameter( rotationParam.release() );
139 mShape = parameterAsEnum( parameters, u
"SHAPE"_s, context );
141 mWidth = parameterAsDouble( parameters, u
"WIDTH"_s, context );
144 mWidthProperty = parameters.value( u
"WIDTH"_s ).value<
QgsProperty>();
146 mHeight = parameterAsDouble( parameters, u
"HEIGHT"_s, context );
148 if ( mDynamicHeight )
149 mHeightProperty = parameters.value( u
"HEIGHT"_s ).value<
QgsProperty>();
151 mRotation = parameterAsDouble( parameters, u
"ROTATION"_s, context );
153 if ( mDynamicRotation )
154 mRotationProperty = parameters.value( u
"ROTATION"_s ).value<
QgsProperty>();
156 mSegments = parameterAsDouble( parameters, u
"SEGMENTS"_s, context );
169 throw QgsProcessingException( QObject::tr(
"Multipart geometry. Please promote input layer to singleparts first." ) );
172 double width = mWidth;
176 double height = mHeight;
177 if ( mDynamicHeight )
180 double rotation = mRotation;
181 if ( mDynamicRotation )
184 if ( width == 0 || height == 0 )
189 const double phi = rotation * M_PI / 180;
190 const double xOffset = width / 2.0;
191 const double yOffset = height / 2.0;
193 const double x = point.
x();
194 const double y = point.
y();
196 QVector<double> ringX( 5 );
197 QVector<double> ringY( 5 );
203 ringX = { -xOffset + x, -xOffset + x, xOffset + x, xOffset + x, -xOffset + x };
204 ringY = { -yOffset + y, yOffset + y, yOffset + y, -yOffset + y, -yOffset + y };
208 ringX = { x, -xOffset + x, x, xOffset + x, x };
209 ringY = { -yOffset + y, y, yOffset + y, y, -yOffset + y };
213 ringX.resize( mSegments + 1 );
214 ringY.resize( mSegments + 1 );
215 for (
int i = 0; i < mSegments; i++ )
217 const double t = ( 2 * M_PI ) / mSegments * i;
218 ringX[i] = xOffset * cos( t ) + x;
219 ringY[i] = yOffset * sin( t ) + y;
221 ringX[mSegments] = ringX.at( 0 );
222 ringY[mSegments] = ringY.at( 0 );
228 for (
int i = 0; i < ringX.size(); ++i )
230 const double px = ringX.at( i );
231 const double py = ringY.at( i );
232 ringX[i] = ( px - x ) * cos( phi ) + ( py - y ) * sin( phi ) + x;
233 ringY[i] = -( px - x ) * sin( phi ) + ( py - y ) * cos( phi ) + y;
237 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