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
56 return QObject::tr(
"This algorithm takes a map layer and generates a new vector "
57 "layer with the minimum bounding box (rectangle polygon with "
58 "N-S orientation) that covers the input layer. Optionally, the "
59 "extent can be enlarged to a rounded value." );
62QString QgsExtentFromLayerAlgorithm::shortDescription()
const
64 return QObject::tr(
"Generates a vector layer with the minimum bounding box that covers the input layer." );
67QString QgsExtentFromLayerAlgorithm::svgIconPath()
const
72QIcon QgsExtentFromLayerAlgorithm::icon()
const
77QgsExtentFromLayerAlgorithm *QgsExtentFromLayerAlgorithm::createInstance()
const
79 return new QgsExtentFromLayerAlgorithm();
82void QgsExtentFromLayerAlgorithm::initAlgorithm(
const QVariantMap & )
86 auto roundParam = std::make_unique<QgsProcessingParameterDistance>( u
"ROUND_TO"_s, QObject::tr(
"Round values to" ), 0, u
"INPUT"_s, 0 );
88 addParameter( roundParam.release() );
95 QgsMapLayer *layer = parameterAsLayer( parameters, u
"INPUT"_s, context );
100 const double roundTo = parameterAsDouble( parameters, u
"ROUND_TO"_s, context );
111 fields.
append(
QgsField( u
"HEIGHT"_s, QMetaType::Type::Double ) );
115 std::unique_ptr<QgsFeatureSink> sink( parameterAsSink( parameters, u
"OUTPUT"_s, context, dest, fields,
Qgis::WkbType::Polygon, layer->
crs() ) );
119 if (
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( layer ) )
136 const double minX = rect.
xMinimum();
137 const double maxX = rect.
xMaximum();
138 const double minY = rect.
yMinimum();
139 const double maxY = rect.
yMaximum();
140 const double height = rect.
height();
141 const double width = rect.
width();
142 const double cntX = minX + width / 2.0;
143 const double cntY = minY + height / 2.0;
144 const double area = width * height;
145 const double perim = 2 * width + 2 * height;
156 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.