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(
"This algorithm 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." );
57QString QgsRectanglesOvalsDiamondsAlgorithm::shortDescription()
const
59 return QObject::tr(
"Creates rectangle, oval or diamond-shaped polygons from an input point layer." );
62QIcon QgsRectanglesOvalsDiamondsAlgorithm::icon()
const
67QString QgsRectanglesOvalsDiamondsAlgorithm::svgIconPath()
const
72QString QgsRectanglesOvalsDiamondsAlgorithm::outputName()
const
74 return QObject::tr(
"Polygon" );
77QList<int> QgsRectanglesOvalsDiamondsAlgorithm::inputLayerTypes()
const
102QgsRectanglesOvalsDiamondsAlgorithm *QgsRectanglesOvalsDiamondsAlgorithm::createInstance()
const
104 return new QgsRectanglesOvalsDiamondsAlgorithm();
107void QgsRectanglesOvalsDiamondsAlgorithm::initParameters(
const QVariantMap & )
109 addParameter(
new QgsProcessingParameterEnum( QStringLiteral(
"SHAPE" ), QObject::tr(
"Shape" ), QStringList() << QObject::tr(
"Rectangle" ) << QObject::tr(
"Diamond" ) << QObject::tr(
"Oval" ),
false, 0 ) );
111 auto widthParam = std::make_unique<QgsProcessingParameterDistance>( QStringLiteral(
"WIDTH" ), QObject::tr(
"Width" ), 1.0, QStringLiteral(
"INPUT" ),
false, 0.0 );
112 widthParam->setIsDynamic(
true );
114 widthParam->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
115 addParameter( widthParam.release() );
117 auto heightParam = std::make_unique<QgsProcessingParameterDistance>( QStringLiteral(
"HEIGHT" ), QObject::tr(
"Height" ), 1.0, QStringLiteral(
"INPUT" ),
false, 0.0 );
118 heightParam->setIsDynamic(
true );
120 heightParam->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
121 addParameter( heightParam.release() );
124 rotationParam->setIsDynamic(
true );
126 rotationParam->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
127 addParameter( rotationParam.release() );
134 mShape = parameterAsEnum( parameters, QStringLiteral(
"SHAPE" ), context );
136 mWidth = parameterAsDouble( parameters, QStringLiteral(
"WIDTH" ), context );
139 mWidthProperty = parameters.value( QStringLiteral(
"WIDTH" ) ).value<
QgsProperty>();
141 mHeight = parameterAsDouble( parameters, QStringLiteral(
"HEIGHT" ), context );
143 if ( mDynamicHeight )
144 mHeightProperty = parameters.value( QStringLiteral(
"HEIGHT" ) ).value<
QgsProperty>();
146 mRotation = parameterAsDouble( parameters, QStringLiteral(
"ROTATION" ), context );
148 if ( mDynamicRotation )
149 mRotationProperty = parameters.value( QStringLiteral(
"ROTATION" ) ).value<
QgsProperty>();
151 mSegments = parameterAsDouble( parameters, QStringLiteral(
"SEGMENTS" ), context );
164 throw QgsProcessingException( QObject::tr(
"Multipart geometry. Please promote input layer to singleparts first." ) );
167 double width = mWidth;
171 double height = mHeight;
172 if ( mDynamicHeight )
175 double rotation = mRotation;
176 if ( mDynamicRotation )
179 if ( width == 0 || height == 0 )
184 const double phi = rotation * M_PI / 180;
185 const double xOffset = width / 2.0;
186 const double yOffset = height / 2.0;
188 const double x = point.
x();
189 const double y = point.
y();
191 QVector<double> ringX( 5 );
192 QVector<double> ringY( 5 );
198 ringX = { -xOffset + x, -xOffset + x, xOffset + x, xOffset + x, -xOffset + x };
199 ringY = { -yOffset + y, yOffset + y, yOffset + y, -yOffset + y, -yOffset + y };
203 ringX = { x, -xOffset + x, x, xOffset + x, x };
204 ringY = { -yOffset + y, y, yOffset + y, y, -yOffset + y };
208 ringX.resize( mSegments + 1 );
209 ringY.resize( mSegments + 1 );
210 for (
int i = 0; i < mSegments; i++ )
212 const double t = ( 2 * M_PI ) / mSegments * i;
213 ringX[i] = xOffset * cos( t ) + x;
214 ringY[i] = yOffset * sin( t ) + y;
216 ringX[mSegments] = ringX.at( 0 );
217 ringY[mSegments] = ringY.at( 0 );
223 for (
int i = 0; i < ringX.size(); ++i )
225 const double px = ringX.at( i );
226 const double py = ringY.at( i );
227 ringX[i] = ( px - x ) * cos( phi ) + ( py - y ) * sin( phi ) + x;
228 ringY[i] = -( px - x ) * sin( phi ) + ( py - y ) * cos( phi ) + y;
232 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 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