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 = qgis::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 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 ) )
130 double height = rect.
height();
131 double width = rect.
width();
132 double cntX = minX + width / 2.0;
133 double cntY = minY + height / 2.0;
134 double area = width * height;
135 double perim = 2 * width + 2 * height;
143 outputs.insert( QStringLiteral(
"OUTPUT" ), dest );