QGIS API Documentation
3.26.3-Buenos Aires (65e4edfdad)
|
Go to the documentation of this file.
24 QString QgsExtentFromLayerAlgorithm::name()
const
26 return QStringLiteral(
"polygonfromlayerextent" );
29 QString QgsExtentFromLayerAlgorithm::displayName()
const
31 return QObject::tr(
"Extract layer extent" );
34 QStringList QgsExtentFromLayerAlgorithm::tags()
const
36 return QObject::tr(
"polygon,vector,raster,extent,envelope,bounds,bounding,boundary,layer,round,rounded" ).split(
',' );
39 QString QgsExtentFromLayerAlgorithm::group()
const
41 return QObject::tr(
"Layer tools" );
44 QString QgsExtentFromLayerAlgorithm::groupId()
const
46 return QStringLiteral(
"layertools" );
49 QString QgsExtentFromLayerAlgorithm::shortHelpString()
const
51 return QObject::tr(
"This algorithm takes a map layer and generates a new vector "
52 "layer with the minimum bounding box (rectangle polygon with "
53 "N-S orientation) that covers the input layer. Optionally, the "
54 "extent can be enlarged to a rounded value." );
57 QString QgsExtentFromLayerAlgorithm::svgIconPath()
const
62 QIcon QgsExtentFromLayerAlgorithm::icon()
const
67 QgsExtentFromLayerAlgorithm *QgsExtentFromLayerAlgorithm::createInstance()
const
69 return new QgsExtentFromLayerAlgorithm();
72 void QgsExtentFromLayerAlgorithm::initAlgorithm(
const QVariantMap & )
76 auto roundParam = std::make_unique < QgsProcessingParameterDistance >( QStringLiteral(
"ROUND_TO" ), QObject::tr(
"Round values to" ), 0, QStringLiteral(
"INPUT" ), 0 );
78 addParameter( roundParam.release() );
85 QgsMapLayer *layer = parameterAsLayer( parameters, QStringLiteral(
"INPUT" ), context );
90 const double roundTo = parameterAsDouble( parameters, QStringLiteral(
"ROUND_TO" ), context );
93 fields.
append(
QgsField( QStringLiteral(
"MINX" ), QVariant::Double ) );
94 fields.
append(
QgsField( QStringLiteral(
"MINY" ), QVariant::Double ) );
95 fields.
append(
QgsField( QStringLiteral(
"MAXX" ), QVariant::Double ) );
96 fields.
append(
QgsField( QStringLiteral(
"MAXY" ), QVariant::Double ) );
97 fields.
append(
QgsField( QStringLiteral(
"CNTX" ), QVariant::Double ) );
98 fields.
append(
QgsField( QStringLiteral(
"CNTY" ), QVariant::Double ) );
99 fields.
append(
QgsField( QStringLiteral(
"AREA" ), QVariant::Double ) );
100 fields.
append(
QgsField( QStringLiteral(
"PERIM" ), QVariant::Double ) );
101 fields.
append(
QgsField( QStringLiteral(
"HEIGHT" ), QVariant::Double ) );
102 fields.
append(
QgsField( QStringLiteral(
"WIDTH" ), QVariant::Double ) );
105 std::unique_ptr< QgsFeatureSink > sink( parameterAsSink( parameters, QStringLiteral(
"OUTPUT" ), context, dest, fields,
QgsWkbTypes::Polygon, layer->
crs() ) );
109 if (
QgsVectorLayer *vl = qobject_cast< QgsVectorLayer * >( layer ) )
126 const double minX = rect.
xMinimum();
127 const double maxX = rect.
xMaximum();
128 const double minY = rect.
yMinimum();
129 const double maxY = rect.
yMaximum();
130 const double height = rect.
height();
131 const double width = rect.
width();
132 const double cntX = minX + width / 2.0;
133 const double cntY = minY + height / 2.0;
134 const double area = width * height;
135 const double perim = 2 * width + 2 * height;
144 outputs.insert( QStringLiteral(
"OUTPUT" ), dest );
QgsCoordinateReferenceSystem crs
double height() const SIP_HOLDGIL
Returns the height of the rectangle.
Base class for providing feedback from a processing algorithm.
@ TypeVectorPolygon
Vector polygon layers.
Container of fields for a vector layer.
double yMinimum() const SIP_HOLDGIL
Returns the y minimum value (bottom side of rectangle).
@ FlagAdvanced
Parameter is an advanced parameter which should be hidden from users by default.
A map layer parameter for processing algorithms.
bool append(const QgsField &field, FieldOrigin origin=OriginProvider, int originIndex=-1)
Appends a field. The field must have unique name, otherwise it is rejected (returns false)
static QString iconPath(const QString &iconFile)
Returns path to the desired icon file.
A rectangle specified with double values.
A feature sink output for processing algorithms.
double xMaximum() const SIP_HOLDGIL
Returns the x maximum value (right side of rectangle).
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
Contains information about the context in which a processing algorithm is executed.
virtual QgsRectangle extent() const
Returns the extent of the layer.
void setXMinimum(double x) SIP_HOLDGIL
Set the minimum x value.
double xMinimum() const SIP_HOLDGIL
Returns the x minimum value (left side of rectangle).
void setXMaximum(double x) SIP_HOLDGIL
Set the maximum x value.
void setYMaximum(double y) SIP_HOLDGIL
Set the maximum y value.
double yMaximum() const SIP_HOLDGIL
Returns the y maximum value (top side of rectangle).
void setYMinimum(double y) SIP_HOLDGIL
Set the minimum y value.
A geometry is the spatial representation of a feature.
Represents a vector layer which manages a vector based data sets.
double width() const SIP_HOLDGIL
Returns the width of the rectangle.
Base class for all map layer types. This is the base class for all map layer types (vector,...
static QgsGeometry fromRect(const QgsRectangle &rect) SIP_HOLDGIL
Creates a new geometry from a QgsRectangle.
A vector of attributes. Mostly equal to QVector<QVariant>.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
void setAttributes(const QgsAttributes &attrs)
Sets the feature's attributes.
Custom exception class for processing related exceptions.
@ FastInsert
Use faster inserts, at the cost of updating the passed features to reflect changes made at the provid...
Encapsulate a field in an attribute table or data source.