25using namespace Qt::StringLiterals;
29QString QgsExtentFromLayerAlgorithm::name()
const
31 return u
"polygonfromlayerextent"_s;
34QString QgsExtentFromLayerAlgorithm::displayName()
const
36 return QObject::tr(
"Extract layer extent" );
39QStringList QgsExtentFromLayerAlgorithm::tags()
const
41 return QObject::tr(
"polygon,vector,raster,extent,envelope,bounds,bounding,boundary,layer,round,rounded" ).split(
',' );
44QString QgsExtentFromLayerAlgorithm::group()
const
46 return QObject::tr(
"Layer tools" );
49QString QgsExtentFromLayerAlgorithm::groupId()
const
51 return u
"layertools"_s;
54QString QgsExtentFromLayerAlgorithm::shortHelpString()
const
57 "This algorithm takes a map layer and generates a new vector "
58 "layer with the minimum bounding box (rectangle polygon with "
59 "N-S orientation) that covers the input layer. Optionally, the "
60 "extent can be enlarged to a rounded value."
64QString QgsExtentFromLayerAlgorithm::shortDescription()
const
66 return QObject::tr(
"Generates a vector layer with the minimum bounding box that covers the input layer." );
69QString QgsExtentFromLayerAlgorithm::svgIconPath()
const
74QIcon QgsExtentFromLayerAlgorithm::icon()
const
79QgsExtentFromLayerAlgorithm *QgsExtentFromLayerAlgorithm::createInstance()
const
81 return new QgsExtentFromLayerAlgorithm();
84void QgsExtentFromLayerAlgorithm::initAlgorithm(
const QVariantMap & )
88 auto roundParam = std::make_unique<QgsProcessingParameterDistance>( u
"ROUND_TO"_s, QObject::tr(
"Round values to" ), 0, u
"INPUT"_s, 0 );
90 addParameter( roundParam.release() );
97 QgsMapLayer *layer = parameterAsLayer( parameters, u
"INPUT"_s, context );
102 const double roundTo = parameterAsDouble( parameters, u
"ROUND_TO"_s, context );
113 fields.
append(
QgsField( u
"HEIGHT"_s, QMetaType::Type::Double ) );
117 std::unique_ptr<QgsFeatureSink> sink( parameterAsSink( parameters, u
"OUTPUT"_s, context, dest, fields,
Qgis::WkbType::Polygon, layer->
crs() ) );
121 if (
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( layer ) )
138 const double minX = rect.
xMinimum();
139 const double maxX = rect.
xMaximum();
140 const double minY = rect.
yMinimum();
141 const double maxY = rect.
yMaximum();
142 const double height = rect.
height();
143 const double width = rect.
width();
144 const double cntX = minX + width / 2.0;
145 const double cntY = minY + height / 2.0;
146 const double area = width * height;
147 const double perim = 2 * width + 2 * height;
158 outputs.insert( u
"OUTPUT"_s, dest );
@ VectorPolygon
Vector polygon layers.
@ Advanced
Parameter is an advanced parameter which should be hidden from users by default.
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.
@ FastInsert
Use faster inserts, at the cost of updating the passed features to reflect changes made at the provid...
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
void setAttributes(const QgsAttributes &attrs)
Sets the feature's attributes.
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
Encapsulate a field in an attribute table or data source.
Container of fields for a vector layer.
bool append(const QgsField &field, Qgis::FieldOrigin origin=Qgis::FieldOrigin::Provider, int originIndex=-1)
Appends a field.
A geometry is the spatial representation of a feature.
static QgsGeometry fromRect(const QgsRectangle &rect)
Creates a new geometry from a QgsRectangle.
Base class for all map layer types.
virtual QgsRectangle extent() const
Returns the extent of the layer.
QgsCoordinateReferenceSystem crs
Contains information about the context in which a processing algorithm is executed.
Custom exception class for processing related exceptions.
Base class for providing feedback from a processing algorithm.
A feature sink output for processing algorithms.
A map layer parameter for processing algorithms.
A rectangle specified with double values.
void setYMinimum(double y)
Set the minimum y value.
void setXMinimum(double x)
Set the minimum x value.
void setYMaximum(double y)
Set the maximum y value.
void setXMaximum(double x)
Set the maximum x value.
Represents a vector layer which manages a vector based dataset.