mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-13 00:03:09 -04:00
Port drop M/Z algorithm to c++
This commit is contained in:
parent
b5197c8c53
commit
18f85d9e54
@ -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.
|
||||
|
@ -1,94 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
***************************************************************************
|
||||
DropMZValues.py
|
||||
--------------
|
||||
Date : July 2017
|
||||
Copyright : (C) 2017 by Nyall Dawson
|
||||
Email : nyall dot dawson at gmail dot com
|
||||
***************************************************************************
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
***************************************************************************
|
||||
"""
|
||||
|
||||
__author__ = 'Nyall Dawson'
|
||||
__date__ = 'July 2017'
|
||||
__copyright__ = '(C) 2017, Nyall Dawson'
|
||||
|
||||
# This will get replaced with a git SHA1 when you do a git archive323
|
||||
|
||||
__revision__ = '$Format:%H$'
|
||||
|
||||
import os
|
||||
|
||||
from qgis.core import (QgsGeometry,
|
||||
QgsWkbTypes,
|
||||
QgsProcessingParameterBoolean)
|
||||
|
||||
|
||||
from processing.algs.qgis.QgisAlgorithm import QgisFeatureBasedAlgorithm
|
||||
|
||||
pluginPath = os.path.split(os.path.split(os.path.dirname(__file__))[0])[0]
|
||||
|
||||
|
||||
class DropMZValues(QgisFeatureBasedAlgorithm):
|
||||
|
||||
DROP_M_VALUES = 'DROP_M_VALUES'
|
||||
DROP_Z_VALUES = 'DROP_Z_VALUES'
|
||||
|
||||
def group(self):
|
||||
return self.tr('Vector geometry')
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.drop_m = False
|
||||
self.drop_z = False
|
||||
|
||||
def name(self):
|
||||
return 'dropmzvalues'
|
||||
|
||||
def displayName(self):
|
||||
return self.tr('Drop M/Z values')
|
||||
|
||||
def outputName(self):
|
||||
return self.tr('Z/M Dropped')
|
||||
|
||||
def tags(self):
|
||||
return self.tr('drop,set,convert,m,measure,z,25d,3d,values').split(',')
|
||||
|
||||
def initParameters(self, config=None):
|
||||
self.addParameter(QgsProcessingParameterBoolean(self.DROP_M_VALUES,
|
||||
self.tr('Drop M Values'), defaultValue=False))
|
||||
self.addParameter(QgsProcessingParameterBoolean(self.DROP_Z_VALUES,
|
||||
self.tr('Drop Z Values'), defaultValue=False))
|
||||
|
||||
def outputWkbType(self, inputWkb):
|
||||
wkb = inputWkb
|
||||
if self.drop_m:
|
||||
wkb = QgsWkbTypes.dropM(wkb)
|
||||
if self.drop_z:
|
||||
wkb = QgsWkbTypes.dropZ(wkb)
|
||||
return wkb
|
||||
|
||||
def prepareAlgorithm(self, parameters, context, feedback):
|
||||
self.drop_m = self.parameterAsBool(parameters, self.DROP_M_VALUES, context)
|
||||
self.drop_z = self.parameterAsBool(parameters, self.DROP_Z_VALUES, context)
|
||||
return True
|
||||
|
||||
def processFeature(self, feature, feedback):
|
||||
input_geometry = feature.geometry()
|
||||
if input_geometry:
|
||||
new_geom = input_geometry.geometry().clone()
|
||||
if self.drop_m:
|
||||
new_geom.dropMValue()
|
||||
if self.drop_z:
|
||||
new_geom.dropZValue()
|
||||
feature.setGeometry(QgsGeometry(new_geom))
|
||||
|
||||
return feature
|
@ -57,7 +57,6 @@ from .DeleteHoles import DeleteHoles
|
||||
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 @@ class QGISAlgorithmProvider(QgsProcessingProvider):
|
||||
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 ¶meters, 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 ¶meters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;
|
||||
QgsFeature processFeature( const QgsFeature &feature, QgsProcessingFeedback *feedback ) override;
|
||||
|
||||
private:
|
||||
|
||||
bool mDropM = false;
|
||||
bool mDropZ = false;
|
||||
};
|
||||
|
||||
/**
|
||||
* Native transform algorithm.
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user