Skip to content
Permalink
Browse files

Merge pull request #5204 from nirvn/saveselected_native

  • Loading branch information
nirvn committed Sep 16, 2017
2 parents f9bc925 + 0cdabb5 commit 01468d08794879a702b52bc0038e63037c8bfe51
@@ -499,11 +499,6 @@ qgis:reprojectlayer: >

Attributes are not modified by this algorithm.

qgis:saveselectedfeatures: >
This algorithm creates a new layer with all the selected features in a given vector layer.

If the selected layer has no selected features, all features will be added to the resulting feature.

qgis:selectbyattribute: >
This algorithm creates a selection in a vector layer. The criteria for selected features is defined based on the values of an attribute from the input layer.

@@ -129,7 +129,6 @@
from .Relief import Relief
from .ReverseLineDirection import ReverseLineDirection
from .Ruggedness import Ruggedness
from .SaveSelectedFeatures import SaveSelectedFeatures
from .SelectByAttribute import SelectByAttribute
from .SelectByExpression import SelectByExpression
from .ServiceAreaFromLayer import ServiceAreaFromLayer
@@ -266,7 +265,6 @@ def getAlgs(self):
Relief(),
ReverseLineDirection(),
Ruggedness(),
SaveSelectedFeatures(),
SelectByAttribute(),
SelectByExpression(),
ServiceAreaFromLayer(),

This file was deleted.

@@ -80,12 +80,63 @@ void QgsNativeAlgorithms::loadAlgorithms()
addAlgorithm( new QgsExtractByLocationAlgorithm() );
addAlgorithm( new QgsFixGeometriesAlgorithm() );
addAlgorithm( new QgsMergeLinesAlgorithm() );
addAlgorithm( new QgsSaveSelectedFeatures() );
addAlgorithm( new QgsSmoothAlgorithm() );
addAlgorithm( new QgsSimplifyAlgorithm() );
addAlgorithm( new QgsExtractByExtentAlgorithm() );
addAlgorithm( new QgsExtentToLayerAlgorithm() );
}

void QgsSaveSelectedFeatures::initAlgorithm( const QVariantMap & )
{
addParameter( new QgsProcessingParameterVectorLayer( QStringLiteral( "INPUT" ), QObject::tr( "Input layer" ) ) );
addParameter( new QgsProcessingParameterFeatureSink( QStringLiteral( "OUTPUT" ), QObject::tr( "Selected features" ), QgsProcessing::TypeVectorPoint ) );
}

QString QgsSaveSelectedFeatures::shortHelpString() const
{
return QObject::tr( "This algorithm creates a new layer with all the selected features in a given vector layer.\n\n"
"If the selected layer has no selected features, the newly created layer will be empty." );
}

QgsSaveSelectedFeatures *QgsSaveSelectedFeatures::createInstance() const
{
return new QgsSaveSelectedFeatures();
}

QVariantMap QgsSaveSelectedFeatures::processAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
{
QgsVectorLayer *selectLayer = parameterAsVectorLayer( parameters, QStringLiteral( "INPUT" ), context );

QString dest;
std::unique_ptr< QgsFeatureSink > sink( parameterAsSink( parameters, QStringLiteral( "OUTPUT" ), context, dest, selectLayer->fields(), selectLayer->wkbType(), selectLayer->sourceCrs() ) );
if ( !sink )
return QVariantMap();


int count = selectLayer->selectedFeatureCount();
int current = 0;
double step = count > 0 ? 100.0 / count : 1;

QgsFeatureIterator it = selectLayer->getSelectedFeatures();;
QgsFeature feat;
while ( it.nextFeature( feat ) )
{
if ( feedback->isCanceled() )
{
break;
}

sink->addFeature( feat, QgsFeatureSink::FastInsert );

feedback->setProgress( current++ * step );
}

QVariantMap outputs;
outputs.insert( QStringLiteral( "OUTPUT" ), dest );
return outputs;
}

void QgsCentroidAlgorithm::initAlgorithm( const QVariantMap & )
{
addParameter( new QgsProcessingParameterFeatureSource( QStringLiteral( "INPUT" ), QObject::tr( "Input layer" ) ) );
@@ -48,6 +48,29 @@ class QgsNativeAlgorithms: public QgsProcessingProvider

};

/**
* Native save selected features algorithm.
*/
class QgsSaveSelectedFeatures : public QgsProcessingAlgorithm
{

public:

QgsSaveSelectedFeatures() = default;
void initAlgorithm( const QVariantMap &configuration = QVariantMap() ) override;
QString name() const override { return QStringLiteral( "saveselectedfeatures" ); }
QString displayName() const override { return QObject::tr( "Save Selected Features" ); }
QStringList tags() const override { return QObject::tr( "selection,save" ).split( ',' ); }
QString group() const override { return QObject::tr( "Vector general" ); }
QString shortHelpString() const override;
QgsSaveSelectedFeatures *createInstance() const override SIP_FACTORY;

protected:

virtual QVariantMap processAlgorithm( const QVariantMap &parameters,
QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;
};

/**
* Native centroid algorithm.
*/

0 comments on commit 01468d0

Please sign in to comment.
You can’t perform that action at this time.