24using namespace Qt::StringLiterals;
28QString QgsPointsLayerFromTableAlgorithm::name()
const
30 return u
"createpointslayerfromtable"_s;
33QString QgsPointsLayerFromTableAlgorithm::displayName()
const
35 return QObject::tr(
"Create points layer from table" );
38QStringList QgsPointsLayerFromTableAlgorithm::tags()
const
40 return QObject::tr(
"points,create,values,attributes" ).split(
',' );
43QString QgsPointsLayerFromTableAlgorithm::group()
const
45 return QObject::tr(
"Vector creation" );
48QString QgsPointsLayerFromTableAlgorithm::groupId()
const
50 return u
"vectorcreation"_s;
53QString QgsPointsLayerFromTableAlgorithm::shortHelpString()
const
55 return QObject::tr(
"This algorithm generates a point layer based on the coordinates from an input table." )
57 + QObject::tr(
"The table must contain a field with the X coordinate of each point and another "
58 "one with the Y coordinate, as well as optional fields with Z and M values. A CRS "
59 "for the output layer has to be specified, and the coordinates in the table are "
60 "assumed to be expressed in the units used by that CRS. The attributes table of "
61 "the resulting layer will be the input table." );
64QString QgsPointsLayerFromTableAlgorithm::shortDescription()
const
66 return QObject::tr(
"Generates a point layer based on the coordinates from an input table." );
74QgsPointsLayerFromTableAlgorithm *QgsPointsLayerFromTableAlgorithm::createInstance()
const
76 return new QgsPointsLayerFromTableAlgorithm();
79void QgsPointsLayerFromTableAlgorithm::initAlgorithm(
const QVariantMap & )
93 std::unique_ptr<QgsProcessingFeatureSource> featureSource( parameterAsSource( parameters, u
"INPUT"_s, context ) );
97 const QgsFields fields = featureSource->fields();
98 const QString xFieldName = parameterAsString( parameters, u
"XFIELD"_s, context );
99 const int xFieldIndex = fields.
lookupField( xFieldName );
100 if ( xFieldIndex < 0 )
103 const QString yFieldName = parameterAsString( parameters, u
"YFIELD"_s, context );
104 const int yFieldIndex = fields.
lookupField( yFieldName );
105 if ( yFieldIndex < 0 )
108 QString fieldName = parameterAsString( parameters, u
"ZFIELD"_s, context );
109 int zFieldIndex = -1;
110 if ( !fieldName.isEmpty() )
113 if ( zFieldIndex < 0 )
117 fieldName = parameterAsString( parameters, u
"MFIELD"_s, context );
118 int mFieldIndex = -1;
119 if ( !fieldName.isEmpty() )
122 if ( mFieldIndex < 0 )
127 if ( zFieldIndex >= 0 )
129 if ( mFieldIndex >= 0 )
139 const double step = featureSource->featureCount() > 0 ? 100.0 / featureSource->featureCount() : 1;
158 const double x = attrs.at( xFieldIndex ).toDouble( &xOk );
159 const double y = attrs.at( yFieldIndex ).toDouble( &yOk );
166 point.addZValue( attrs.at( zFieldIndex ).toDouble() );
169 point.addMValue( attrs.at( mFieldIndex ).toDouble() );
174 if ( !sink->addFeature( f ) )
183 outputs.insert( u
"OUTPUT"_s, dest );
@ Vector
Tables (i.e. vector layers with or without geometry). When used for a sink this indicates the sink ha...
@ VectorPoint
Vector point layers.
@ NoGeometry
Geometry is not required. It may still be returned if e.g. required for a filter condition.
@ RegeneratesPrimaryKey
Algorithm always drops any existing primary keys or FID values and regenerates them in outputs.
QFlags< ProcessingAlgorithmDocumentationFlag > ProcessingAlgorithmDocumentationFlags
Flags describing algorithm behavior for documentation purposes.
@ SkipGeometryValidityChecks
Invalid geometry checks should always be skipped. This flag can be useful for algorithms which always...
WkbType
The WKB type describes the number of dimensions a geometry has.
Represents a coordinate reference system (CRS).
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.
Wraps a request for features to a vector layer (or directly its vector data provider).
QgsFeatureRequest & setFlags(Qgis::FeatureRequestFlags flags)
Sets flags that affect how features will be fetched.
@ RegeneratePrimaryKey
This flag indicates, that a primary key field cannot be guaranteed to be unique and the sink should i...
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
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.
Container of fields for a vector layer.
Q_INVOKABLE int lookupField(const QString &fieldName) const
Looks up field's index from the field name.
A geometry is the spatial representation of a feature.
Point geometry type, with support for z-dimension and m-values.
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.
A coordinate reference system parameter for processing algorithms.
A feature sink output for processing algorithms.
An input feature source (such as vector layers) parameter for processing algorithms.
A vector layer or feature source field parameter for processing algorithms.
static bool isNull(const QVariant &variant, bool silenceNullWarnings=false)
Returns true if the specified variant should be considered a NULL value.
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.