Skip to content

Commit

Permalink
Port drop geometries to c++
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Oct 12, 2017
1 parent 2951afa commit b5197c8
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 68 deletions.
7 changes: 7 additions & 0 deletions python/core/processing/qgsprocessingalgorithm.sip
Original file line number Diff line number Diff line change
Expand Up @@ -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

};


Expand Down
3 changes: 0 additions & 3 deletions python/plugins/processing/algs/help/qgis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
62 changes: 0 additions & 62 deletions python/plugins/processing/algs/qgis/DropGeometry.py

This file was deleted.

2 changes: 0 additions & 2 deletions python/plugins/processing/algs/qgis/QGISAlgorithmProvider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -186,7 +185,6 @@ def getAlgs(self):
DensifyGeometries(),
DensifyGeometriesInterval(),
Difference(),
DropGeometry(),
DropMZValues(),
EliminateSelection(),
EquivalentNumField(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2008,7 +2008,7 @@ tests:
geometry:
precision: 7

- algorithm: qgis:dropgeometries
- algorithm: native:dropgeometries
name: Drop geometries
params:
INPUT:
Expand Down
34 changes: 34 additions & 0 deletions src/core/processing/qgsnativealgorithms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ void QgsNativeAlgorithms::loadAlgorithms()
addAlgorithm( new QgsAssignProjectionAlgorithm() );
addAlgorithm( new QgsAddIncrementalFieldAlgorithm() );
addAlgorithm( new QgsBoundaryAlgorithm() );
addAlgorithm( new QgsDropGeometryAlgorithm() );
}

void QgsSaveSelectedFeatures::initAlgorithm( const QVariantMap & )
Expand Down Expand Up @@ -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

25 changes: 25 additions & 0 deletions src/core/processing/qgsnativealgorithms.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
5 changes: 5 additions & 0 deletions src/core/processing/qgsprocessingalgorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -718,3 +718,8 @@ QVariantMap QgsProcessingFeatureBasedAlgorithm::processAlgorithm( const QVariant
outputs.insert( QStringLiteral( "OUTPUT" ), dest );
return outputs;
}

QgsFeatureRequest QgsProcessingFeatureBasedAlgorithm::request() const
{
return QgsFeatureRequest();
}
6 changes: 6 additions & 0 deletions src/core/processing/qgsprocessingalgorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit b5197c8

Please sign in to comment.