Skip to content
Permalink
Browse files

Port drop geometries to c++

  • Loading branch information
nyalldawson committed Oct 12, 2017
1 parent 2951afa commit b5197c8c53f593409e59aa2d293cffda144a7ca5
@@ -896,6 +896,13 @@ class QgsProcessingFeatureBasedAlgorithm : QgsProcessingAlgorithm
virtual QVariantMap processAlgorithm( const QVariantMap &parameters,
QgsProcessingContext &context, QgsProcessingFeedback *feedback );

virtual QgsFeatureRequest request() const;
%Docstring
Returns the feature request used for fetching features to process from the
source layer. The default implementation requests all attributes and geometry.
:rtype: QgsFeatureRequest
%End

};


@@ -153,9 +153,6 @@ qgis:distancetonearesthub: >

The resulting layer can contain only source points with an additional field indicating the distance to the nearest point and the name of the destination point, or lines linking each source point with its nearest destination point.

qgis:dropgeometries: >
This algorithm removes any geometries from an input layer and returns a layer containing only the feature attributes.

qgis:dropmzvalues: >
This algorithm can remove any measure (M) or Z values from input geometries.

This file was deleted.

@@ -57,7 +57,6 @@
from .DensifyGeometries import DensifyGeometries
from .DensifyGeometriesInterval import DensifyGeometriesInterval
from .Difference import Difference
from .DropGeometry import DropGeometry
from .DropMZValues import DropMZValues
from .EliminateSelection import EliminateSelection
from .EquivalentNumField import EquivalentNumField
@@ -186,7 +185,6 @@ def getAlgs(self):
DensifyGeometries(),
DensifyGeometriesInterval(),
Difference(),
DropGeometry(),
DropMZValues(),
EliminateSelection(),
EquivalentNumField(),
@@ -2008,7 +2008,7 @@ tests:
geometry:
precision: 7

- algorithm: qgis:dropgeometries
- algorithm: native:dropgeometries
name: Drop geometries
params:
INPUT:
@@ -95,6 +95,7 @@ void QgsNativeAlgorithms::loadAlgorithms()
addAlgorithm( new QgsAssignProjectionAlgorithm() );
addAlgorithm( new QgsAddIncrementalFieldAlgorithm() );
addAlgorithm( new QgsBoundaryAlgorithm() );
addAlgorithm( new QgsDropGeometryAlgorithm() );
}

void QgsSaveSelectedFeatures::initAlgorithm( const QVariantMap & )
@@ -3262,5 +3263,38 @@ QgsFeature QgsBoundaryAlgorithm::processFeature( const QgsFeature &feature, QgsP
return outFeature;
}

QString QgsDropGeometryAlgorithm::shortHelpString() const
{
return QObject::tr( "This algorithm removes any geometries from an input layer and returns a layer containing only the feature attributes." );
}

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

QgsCoordinateReferenceSystem QgsDropGeometryAlgorithm::outputCrs( const QgsCoordinateReferenceSystem & ) const
{
return QgsCoordinateReferenceSystem();
}

QgsWkbTypes::Type QgsDropGeometryAlgorithm::outputWkbType( QgsWkbTypes::Type ) const
{
return QgsWkbTypes::NoGeometry;
}

QgsFeatureRequest QgsDropGeometryAlgorithm::request() const
{
return QgsFeatureRequest().setFlags( QgsFeatureRequest::NoGeometry );
}

QgsFeature QgsDropGeometryAlgorithm::processFeature( const QgsFeature &feature, QgsProcessingFeedback * )
{
QgsFeature f = feature;
f.clearGeometry();
return f;
}


///@endcond

@@ -122,6 +122,31 @@ class QgsBoundaryAlgorithm : public QgsProcessingFeatureBasedAlgorithm
QgsFeature processFeature( const QgsFeature &feature, QgsProcessingFeedback *feedback ) override;
};

/**
* Native drop geometries algorithm.
*/
class QgsDropGeometryAlgorithm : public QgsProcessingFeatureBasedAlgorithm
{

public:

QgsDropGeometryAlgorithm() = default;
QString name() const override { return QStringLiteral( "dropgeometries" ); }
QString displayName() const override { return QObject::tr( "Drop geometries" ); }
QStringList tags() const override { return QObject::tr( "remove,drop,delete,geometry,objects" ).split( ',' ); }
QString group() const override { return QObject::tr( "Vector general" ); }
QString shortHelpString() const override;
QgsDropGeometryAlgorithm *createInstance() const override SIP_FACTORY;
QgsCoordinateReferenceSystem outputCrs( const QgsCoordinateReferenceSystem &inputCrs ) const override;

protected:

QString outputName() const override { return QObject::tr( "Dropped geometries" ); }
QgsWkbTypes::Type outputWkbType( QgsWkbTypes::Type inputWkbType ) const override;
QgsFeatureRequest request() const override;
QgsFeature processFeature( const QgsFeature &feature, QgsProcessingFeedback *feedback ) override;
};

/**
* Native transform algorithm.
*/
@@ -718,3 +718,8 @@ QVariantMap QgsProcessingFeatureBasedAlgorithm::processAlgorithm( const QVariant
outputs.insert( QStringLiteral( "OUTPUT" ), dest );
return outputs;
}

QgsFeatureRequest QgsProcessingFeatureBasedAlgorithm::request() const
{
return QgsFeatureRequest();
}
@@ -877,6 +877,12 @@ class CORE_EXPORT QgsProcessingFeatureBasedAlgorithm : public QgsProcessingAlgor
virtual QVariantMap processAlgorithm( const QVariantMap &parameters,
QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;

/**
* Returns the feature request used for fetching features to process from the
* source layer. The default implementation requests all attributes and geometry.
*/
virtual QgsFeatureRequest request() const;

private:

std::unique_ptr< QgsProcessingFeatureSource > mSource;

0 comments on commit b5197c8

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