@@ -83,6 +83,7 @@ void QgsNativeAlgorithms::loadAlgorithms()
83
83
addAlgorithm ( new QgsSmoothAlgorithm () );
84
84
addAlgorithm ( new QgsSimplifyAlgorithm () );
85
85
addAlgorithm ( new QgsExtractByExtentAlgorithm () );
86
+ addAlgorithm ( new QgsExtentToLayerAlgorithm () );
86
87
}
87
88
88
89
void QgsCentroidAlgorithm::initAlgorithm ( const QVariantMap & )
@@ -1884,5 +1885,49 @@ QVariantMap QgsExtractByExtentAlgorithm::processAlgorithm( const QVariantMap &pa
1884
1885
return outputs;
1885
1886
}
1886
1887
1887
- // /@endcond
1888
1888
1889
+ void QgsExtentToLayerAlgorithm::initAlgorithm ( const QVariantMap & )
1890
+ {
1891
+ addParameter ( new QgsProcessingParameterExtent ( QStringLiteral ( " INPUT" ), QObject::tr ( " Extent" ) ) );
1892
+ addParameter ( new QgsProcessingParameterFeatureSink ( QStringLiteral ( " OUTPUT" ), QObject::tr ( " Extent" ), QgsProcessing::TypeVectorPolygon ) );
1893
+ }
1894
+
1895
+ QString QgsExtentToLayerAlgorithm::shortHelpString () const
1896
+ {
1897
+ return QObject::tr ( " This algorithm creates a new vector layer that contains a single feature with geometry matching an extent parameter.\n\n "
1898
+ " It can be used in models to convert an extent into a layer which can be used for other algorithms which require "
1899
+ " a layer based input." );
1900
+ }
1901
+
1902
+ QgsExtentToLayerAlgorithm *QgsExtentToLayerAlgorithm::createInstance () const
1903
+ {
1904
+ return new QgsExtentToLayerAlgorithm ();
1905
+ }
1906
+
1907
+ QVariantMap QgsExtentToLayerAlgorithm::processAlgorithm ( const QVariantMap ¶meters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
1908
+ {
1909
+ QgsCoordinateReferenceSystem crs = parameterAsExtentCrs ( parameters, QStringLiteral ( " INPUT" ), context );
1910
+ QgsGeometry geom = parameterAsExtentGeometry ( parameters, QStringLiteral ( " INPUT" ), context );
1911
+
1912
+ QgsFields fields;
1913
+ fields.append ( QgsField ( QStringLiteral ( " id" ), QVariant::Int ) );
1914
+
1915
+ QString dest;
1916
+ std::unique_ptr< QgsFeatureSink > sink ( parameterAsSink ( parameters, QStringLiteral ( " OUTPUT" ), context, dest, fields, QgsWkbTypes::Polygon, crs ) );
1917
+ if ( !sink )
1918
+ return QVariantMap ();
1919
+
1920
+ QgsFeature f;
1921
+ f.setAttributes ( QgsAttributes () << 1 );
1922
+ f.setGeometry ( geom );
1923
+ sink->addFeature ( f, QgsFeatureSink::FastInsert );
1924
+
1925
+ feedback->setProgress ( 100 );
1926
+
1927
+ QVariantMap outputs;
1928
+ outputs.insert ( QStringLiteral ( " OUTPUT" ), dest );
1929
+ return outputs;
1930
+ }
1931
+
1932
+
1933
+ // /@endcond
0 commit comments