22 QString QgsSnapToGridAlgorithm::name()
const 24 return QStringLiteral(
"snappointstogrid" );
27 QString QgsSnapToGridAlgorithm::displayName()
const 29 return QObject::tr(
"Snap points to grid" );
32 QStringList QgsSnapToGridAlgorithm::tags()
const 34 return QObject::tr(
"snapped,grid,simplify,round,precision" ).split(
',' );
37 QString QgsSnapToGridAlgorithm::group()
const 39 return QObject::tr(
"Vector geometry" );
42 QString QgsSnapToGridAlgorithm::groupId()
const 44 return QStringLiteral(
"vectorgeometry" );
47 QString QgsSnapToGridAlgorithm::outputName()
const 49 return QObject::tr(
"Snapped" );
52 QString QgsSnapToGridAlgorithm::shortHelpString()
const 54 return QObject::tr(
"This algorithm modifies the coordinates of geometries in a vector layer, so that all points " 55 "or vertices are snapped to the closest point of the grid.\n\n" 56 "If the snapped geometry cannot be calculated (or is totally collapsed) the feature's " 57 "geometry will be cleared.\n\n" 58 "Note that snapping to grid may generate an invalid geometry in some corner cases.\n\n" 59 "Snapping can be performed on the X, Y, Z or M axis. A grid spacing of 0 for any axis will " 60 "disable snapping for that axis." );
63 QgsSnapToGridAlgorithm *QgsSnapToGridAlgorithm::createInstance()
const 65 return new QgsSnapToGridAlgorithm();
68 void QgsSnapToGridAlgorithm::initParameters(
const QVariantMap & )
86 mIntervalX = parameterAsDouble( parameters, QStringLiteral(
"HSPACING" ), context );
87 mIntervalY = parameterAsDouble( parameters, QStringLiteral(
"VSPACING" ), context );
88 mIntervalZ = parameterAsDouble( parameters, QStringLiteral(
"ZSPACING" ), context );
89 mIntervalM = parameterAsDouble( parameters, QStringLiteral(
"MSPACING" ), context );
99 if ( !outputGeometry )
101 feedback->
reportError( QObject::tr(
"Error snapping geometry %1" ).arg( feature.
id() ) );
Base class for providing feedback from a processing algorithm.
QList< QgsFeature > QgsFeatureList
A geometry is the spatial representation of a feature.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
bool hasGeometry() const
Returns true if the feature has an associated geometry.
QgsGeometry geometry() const
Returns the geometry associated with this feature.
A numeric parameter for processing algorithms.
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
QgsGeometry snappedToGrid(double hSpacing, double vSpacing, double dSpacing=0, double mSpacing=0) const
Returns a new geometry with all points or vertices snapped to the closest point of the grid...
Contains information about the context in which a processing algorithm is executed.
virtual void reportError(const QString &error, bool fatalError=false)
Reports that the algorithm encountered an error while executing.