25 QString QgsRectanglesOvalsDiamondsAlgorithm::name()
const
27 return QStringLiteral(
"rectanglesovalsdiamonds" );
30 QString QgsRectanglesOvalsDiamondsAlgorithm::displayName()
const
32 return QObject::tr(
"Rectangles, ovals, diamonds" );
35 QStringList QgsRectanglesOvalsDiamondsAlgorithm::tags()
const
37 return QObject::tr(
"buffer,grow,fixed,variable,distance,rectangle,oval,diamond,point" ).split(
',' );
40 QString QgsRectanglesOvalsDiamondsAlgorithm::group()
const
42 return QObject::tr(
"Vector geometry" );
45 QString QgsRectanglesOvalsDiamondsAlgorithm::groupId()
const
47 return QStringLiteral(
"vectorgeometry" );
50 QString 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." );
57 QString QgsRectanglesOvalsDiamondsAlgorithm::outputName()
const
59 return QObject::tr(
"Polygon" );
62 QList<int> QgsRectanglesOvalsDiamondsAlgorithm::inputLayerTypes()
const
87 QgsRectanglesOvalsDiamondsAlgorithm *QgsRectanglesOvalsDiamondsAlgorithm::createInstance()
const
89 return new QgsRectanglesOvalsDiamondsAlgorithm();
92 void QgsRectanglesOvalsDiamondsAlgorithm::initParameters(
const QVariantMap & )
94 addParameter(
new QgsProcessingParameterEnum( QStringLiteral(
"SHAPE" ), QObject::tr(
"Shape" ), QStringList() << QObject::tr(
"Rectangle" ) << QObject::tr(
"Diamond" ) << QObject::tr(
"Oval" ),
false, 0 ) );
96 auto widthParam = std::make_unique < QgsProcessingParameterDistance >( QStringLiteral(
"WIDTH" ), QObject::tr(
"Width" ), 1.0, QStringLiteral(
"INPUT" ),
false, 0.0 );
97 widthParam->setIsDynamic(
true );
99 widthParam->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
100 addParameter( widthParam.release() );
102 auto heightParam = std::make_unique < QgsProcessingParameterDistance >( QStringLiteral(
"HEIGHT" ), QObject::tr(
"Height" ), 1.0, QStringLiteral(
"INPUT" ),
false, 0.0 );
103 heightParam->setIsDynamic(
true );
105 heightParam->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
106 addParameter( heightParam.release() );
108 auto rotationParam = std::make_unique < QgsProcessingParameterNumber >( QStringLiteral(
"ROTATION" ), QObject::tr(
"Rotation" ),
QgsProcessingParameterNumber::Double, 0.0,
true, -360.0, 360.0 );
109 rotationParam->setIsDynamic(
true );
111 rotationParam->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
112 addParameter( rotationParam.release() );
119 mShape = parameterAsEnum( parameters, QStringLiteral(
"SHAPE" ), context );
121 mWidth = parameterAsDouble( parameters, QStringLiteral(
"WIDTH" ), context );
124 mWidthProperty = parameters.value( QStringLiteral(
"WIDTH" ) ).value<
QgsProperty >();
126 mHeight = parameterAsDouble( parameters, QStringLiteral(
"HEIGHT" ), context );
128 if ( mDynamicHeight )
129 mHeightProperty = parameters.value( QStringLiteral(
"HEIGHT" ) ).value<
QgsProperty >();
131 mRotation = parameterAsDouble( parameters, QStringLiteral(
"ROTATION" ), context );
133 if ( mDynamicRotation )
134 mRotationProperty = parameters.value( QStringLiteral(
"ROTATION" ) ).value<
QgsProperty >();
136 mSegments = parameterAsDouble( parameters, QStringLiteral(
"SEGMENTS" ), context );
149 throw QgsProcessingException( QObject::tr(
"Multipart geometry. Please promote input layer to singleparts first." ) );
152 double width = mWidth;
156 double height = mHeight;
157 if ( mDynamicHeight )
160 double rotation = mRotation;
161 if ( mDynamicRotation )
164 if ( width == 0 || height == 0 )
169 double phi = rotation * M_PI / 180;
170 double xOffset = width / 2.0;
171 double yOffset = height / 2.0;
173 double x = point.
x();
174 double y = point.
y();
176 QVector< double > ringX( 5 );
177 QVector< double > ringY( 5 );
183 ringX = { -xOffset + x, -xOffset + x, xOffset + x, xOffset + x, -xOffset + x };
184 ringY = { -yOffset + y, yOffset + y, yOffset + y, -yOffset + y, -yOffset + y };
188 ringX = { x, -xOffset + x, x, xOffset + x, x };
189 ringY = { -yOffset + y, y, yOffset + y, y, -yOffset + y };
193 ringX.resize( mSegments + 1 );
194 ringY.resize( mSegments + 1 );
195 for (
int i = 0; i < mSegments; i ++ )
197 double t = ( 2 * M_PI ) / mSegments * i;
198 ringX[ i ] = xOffset * cos( t ) + x;
199 ringY[ i ] = yOffset * sin( t ) + y;
201 ringX[ mSegments ] = ringX.at( 0 );
202 ringY[ mSegments ] = ringY.at( 0 );
208 for (
int i = 0; i < ringX.size(); ++i )
210 double px = ringX.at( i );
211 double py = ringY.at( i );
212 ringX[ i ] = ( px - x ) * cos( phi ) + ( py - y ) * sin( phi ) + x;
213 ringY[ i ] = -( px - x ) * sin( phi ) + ( py - y ) * cos( phi ) + y;
217 std::unique_ptr< QgsPolygon > poly = std::make_unique< QgsPolygon >();
bool is3D() const SIP_HOLDGIL
Returns true if the geometry is 3D and contains a z-value.
bool isMeasure() const SIP_HOLDGIL
Returns true if the geometry contains m values.
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 SIP_HOLDGIL
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
bool isMultipart() const SIP_HOLDGIL
Returns true if WKB of the geometry is of WKBMulti* type.
QgsPointXY asPoint() const
Returns the contents of the geometry as a 2-dimensional point.
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 bool hasM(Type type) SIP_HOLDGIL
Tests whether a WKB type contains m values.
Type
The WKB type describes the number of dimensions a geometry has.
static Type addZ(Type type) SIP_HOLDGIL
Adds the z dimension to a WKB type and returns the new type.
static bool hasZ(Type type) SIP_HOLDGIL
Tests whether a WKB type contains the z-dimension.
static Type addM(Type type) SIP_HOLDGIL
Adds the m dimension to a WKB type and returns the new type.
QList< QgsFeature > QgsFeatureList