Skip to content
Permalink
Browse files

Port drop M/Z algorithm to c++

  • Loading branch information
nyalldawson committed Oct 12, 2017
1 parent b5197c8 commit 18f85d9e54e311f6a3e789ef564df879bd899edd
@@ -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.

This file was deleted.

@@ -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
@@ -185,7 +184,6 @@ def getAlgs(self):
DensifyGeometries(),
DensifyGeometriesInterval(),
Difference(),
DropMZValues(),
EliminateSelection(),
EquivalentNumField(),
ExecuteSQL(),
@@ -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:
@@ -746,7 +746,7 @@ tests:
name: expected/m_dropped.shp
type: vector

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

- algorithm: qgis:dropmzvalues
- algorithm: native:dropmzvalues
name: Drop ZM Value
params:
INPUT:
@@ -96,6 +96,7 @@ void QgsNativeAlgorithms::loadAlgorithms()
addAlgorithm( new QgsAddIncrementalFieldAlgorithm() );
addAlgorithm( new QgsBoundaryAlgorithm() );
addAlgorithm( new QgsDropGeometryAlgorithm() );
addAlgorithm( new QgsDropMZValuesAlgorithm() );
}

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



@@ -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.
*/

0 comments on commit 18f85d9

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