22QString QgsConvertGeometryTypeAlgorithm::name()
const
24 return QStringLiteral(
"convertgeometrytype" );
27QString QgsConvertGeometryTypeAlgorithm::displayName()
const
29 return QObject::tr(
"Convert geometry type" );
32QStringList QgsConvertGeometryTypeAlgorithm::tags()
const
34 return QObject::tr(
"polygon,line,point,centroids,nodes,convert,type,geometry" ).split(
',' );
37QString QgsConvertGeometryTypeAlgorithm::group()
const
39 return QObject::tr(
"Vector geometry" );
42QString QgsConvertGeometryTypeAlgorithm::groupId()
const
44 return QStringLiteral(
"vectorgeometry" );
47QString QgsConvertGeometryTypeAlgorithm::shortHelpString()
const
49 return QObject::tr(
"This algorithm generates a new layer based on an existing one, with a different type of geometry.\n\n"
50 "Not all conversions are possible. For instance, a line layer can be converted to a "
51 "point layer, but a point layer cannot be converted to a line layer.\n\n"
52 "See the \"Polygonize\" or \"Lines to polygons\" algorithms for alternative options." );
55QString QgsConvertGeometryTypeAlgorithm::shortDescription()
const
57 return QObject::tr(
"Converts the geometries from a vector layer to a different geometry type." );
60QgsConvertGeometryTypeAlgorithm *QgsConvertGeometryTypeAlgorithm::createInstance()
const
62 return new QgsConvertGeometryTypeAlgorithm();
65void QgsConvertGeometryTypeAlgorithm::initAlgorithm(
const QVariantMap & )
69 QStringList geometryTypes = QStringList() << QObject::tr(
"Centroids" )
70 << QObject::tr(
"Nodes" )
71 << QObject::tr(
"Linestrings" )
72 << QObject::tr(
"Multilinestrings" )
73 << QObject::tr(
"Polygons" );
81 std::unique_ptr<QgsProcessingFeatureSource> source( parameterAsSource( parameters, QStringLiteral(
"INPUT" ), context ) );
87 const int typeIndex = parameterAsEnum( parameters, QStringLiteral(
"TYPE" ), context );
94 else if ( typeIndex == 1 )
98 else if ( typeIndex == 2 )
102 else if ( typeIndex == 3 )
106 else if ( typeIndex == 4 )
122 std::unique_ptr<QgsFeatureSink> sink( parameterAsSink( parameters, QStringLiteral(
"OUTPUT" ), context, dest, source->fields(), outputWkbType, source->sourceCrs() ) );
129 const double step = source->featureCount() > 0 ? 100.0 / source->featureCount() : 0;
145 const QVector< QgsGeometry > geometries = convertGeometry( f.
geometry(), typeIndex, outputWkbType );
163 results.insert( QStringLiteral(
"OUTPUT" ), dest );
167const QVector< QgsGeometry > QgsConvertGeometryTypeAlgorithm::convertGeometry(
const QgsGeometry &geom,
const int typeIndex,
const Qgis::WkbType outputWkbType )
169 QVector< QgsGeometry > geometries;
170 if ( typeIndex == 0 )
176 geometries = geom.
coerceToType( outputWkbType, 0, 0,
false );
@ VectorAnyGeometry
Any vector layer with geometry.
WkbType
The WKB type describes the number of dimensions a geometry has.
@ MultiLineString
MultiLineString.
Wrapper for iterator of features from vector data provider or vector layer.
bool nextFeature(QgsFeature &f)
Fetch next feature and stores in f, returns true on success.
@ FastInsert
Use faster inserts, at the cost of updating the passed features to reflect changes made at the provid...
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
void setAttributes(const QgsAttributes &attrs)
Sets the feature's attributes.
bool hasGeometry() const
Returns true if the feature has an associated geometry.
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
bool isCanceled() const
Tells whether the operation has been canceled already.
void setProgress(double progress)
Sets the current progress for the feedback object.
A geometry is the spatial representation of a feature.
QgsGeometry centroid() const
Returns the center of mass of a geometry.
QVector< QgsGeometry > coerceToType(Qgis::WkbType type, double defaultZ=0, double defaultM=0, bool avoidDuplicates=true) const
Attempts to coerce this geometry into the specified destination type.
Contains information about the context in which a processing algorithm is executed.
Custom exception class for processing related exceptions.
Base class for providing feedback from a processing algorithm.
An enum based parameter for processing algorithms, allowing for selection from predefined values.
A feature sink output for processing algorithms.
An input feature source (such as vector layers) parameter for processing algorithms.
static Qgis::WkbType addM(Qgis::WkbType type)
Adds the m dimension to a WKB type and returns the new type.
static Qgis::WkbType addZ(Qgis::WkbType type)
Adds the z dimension to a WKB type and returns the new type.
static bool hasZ(Qgis::WkbType type)
Tests whether a WKB type contains the z-dimension.
static bool hasM(Qgis::WkbType type)
Tests whether a WKB type contains m values.