Skip to content

Commit

Permalink
Port drop M/Z algorithm to c++
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Oct 12, 2017
1 parent b5197c8 commit 18f85d9
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 102 deletions.
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:dropmzvalues: >
This algorithm can remove any measure (M) or Z values from input geometries.

qgis:eliminateselectedpolygons: >
This algorithm combines selected polygons of the input layer with certain adjacent polygons by erasing their common boundary. The adjacent polygon can be either the one with the largest or smallest area or the one sharing the largest common boundary with the polygon to be eliminated. The selected features will always be eliminated whether the option "Use only selected features" is set or not.
Eliminate is normally used to get rid of sliver polygons, i.e. tiny polygons that are a result of polygon intersection processes where boundaries of the inputs are similar but not identical.
Expand Down
94 changes: 0 additions & 94 deletions python/plugins/processing/algs/qgis/DropMZValues.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 .DropMZValues import DropMZValues
from .EliminateSelection import EliminateSelection
from .EquivalentNumField import EquivalentNumField
from .ExecuteSQL import ExecuteSQL
Expand Down Expand Up @@ -185,7 +184,6 @@ def getAlgs(self):
DensifyGeometries(),
DensifyGeometriesInterval(),
Difference(),
DropMZValues(),
EliminateSelection(),
EquivalentNumField(),
ExecuteSQL(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,7 @@ tests:
name: expected/set_z_value.shp
type: vector

- algorithm: qgis:dropmzvalues
- algorithm: native:dropmzvalues
name: Drop M Value
params:
INPUT:
Expand All @@ -746,7 +746,7 @@ tests:
name: expected/m_dropped.shp
type: vector

- algorithm: qgis:dropmzvalues
- algorithm: native:dropmzvalues
name: Drop Z Value
params:
INPUT:
Expand All @@ -759,7 +759,7 @@ tests:
name: expected/z_dropped.shp
type: vector

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

void QgsSaveSelectedFeatures::initAlgorithm( const QVariantMap & )
Expand Down Expand Up @@ -3295,6 +3296,56 @@ QgsFeature QgsDropGeometryAlgorithm::processFeature( const QgsFeature &feature,
return f;
}

QString QgsDropMZValuesAlgorithm::shortHelpString() const
{
return QObject::tr( "This algorithm can remove any measure (M) or Z values from input geometries." );
}

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

void QgsDropMZValuesAlgorithm::initParameters( const QVariantMap & )
{
addParameter( new QgsProcessingParameterBoolean( QStringLiteral( "DROP_M_VALUES" ), QObject::tr( "Drop M Values" ), false ) );
addParameter( new QgsProcessingParameterBoolean( QStringLiteral( "DROP_Z_VALUES" ), QObject::tr( "Drop Z Values" ), false ) );
}

QgsWkbTypes::Type QgsDropMZValuesAlgorithm::outputWkbType( QgsWkbTypes::Type inputWkbType ) const
{
QgsWkbTypes::Type wkb = inputWkbType;
if ( mDropM )
wkb = QgsWkbTypes::dropM( wkb );
if ( mDropZ )
wkb = QgsWkbTypes::dropZ( wkb );
return wkb;
}

bool QgsDropMZValuesAlgorithm::prepareAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback * )
{
mDropM = parameterAsBool( parameters, QStringLiteral( "DROP_M_VALUES" ), context );
mDropZ = parameterAsBool( parameters, QStringLiteral( "DROP_Z_VALUES" ), context );
return true;
}

QgsFeature QgsDropMZValuesAlgorithm::processFeature( const QgsFeature &feature, QgsProcessingFeedback * )
{
QgsFeature f = feature;
if ( f.hasGeometry() )
{
std::unique_ptr< QgsAbstractGeometry > newGeom( f.geometry().geometry()->clone() );
if ( mDropM )
newGeom->dropMValue();
if ( mDropZ )
newGeom->dropZValue();
f.setGeometry( QgsGeometry( newGeom.release() ) );
}

return f;
}

///@endcond



30 changes: 30 additions & 0 deletions src/core/processing/qgsnativealgorithms.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,36 @@ class QgsDropGeometryAlgorithm : public QgsProcessingFeatureBasedAlgorithm
QgsFeature processFeature( const QgsFeature &feature, QgsProcessingFeedback *feedback ) override;
};

/**
* Native drop M/Z values algorithm.
*/
class QgsDropMZValuesAlgorithm : public QgsProcessingFeatureBasedAlgorithm
{

public:

QgsDropMZValuesAlgorithm() = default;
QString name() const override { return QStringLiteral( "dropmzvalues" ); }
QString displayName() const override { return QObject::tr( "Drop M/Z values" ); }
QStringList tags() const override { return QObject::tr( "drop,set,convert,m,measure,z,25d,3d,values" ).split( ',' ); }
QString group() const override { return QObject::tr( "Vector geometry" ); }
QString shortHelpString() const override;
QgsDropMZValuesAlgorithm *createInstance() const override SIP_FACTORY;

protected:

void initParameters( const QVariantMap &configuration = QVariantMap() ) override;
QString outputName() const override { return QObject::tr( "Z/M Dropped" ); }
QgsWkbTypes::Type outputWkbType( QgsWkbTypes::Type inputWkbType ) const override;
bool prepareAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;
QgsFeature processFeature( const QgsFeature &feature, QgsProcessingFeedback *feedback ) override;

private:

bool mDropM = false;
bool mDropZ = false;
};

/**
* Native transform algorithm.
*/
Expand Down

0 comments on commit 18f85d9

Please sign in to comment.