23QString QgsAddXYFieldsAlgorithm::name()
const
25 return QStringLiteral(
"addxyfields" );
28QString QgsAddXYFieldsAlgorithm::displayName()
const
30 return QObject::tr(
"Add X/Y fields to layer" );
33QString QgsAddXYFieldsAlgorithm::shortHelpString()
const
35 return QObject::tr(
"Adds X and Y (or latitude/longitude) fields to a point layer. The X/Y fields can be calculated in a different CRS to the layer (e.g. creating latitude/longitude fields for a layer in a project CRS)." );
38QString QgsAddXYFieldsAlgorithm::shortDescription()
const
40 return QObject::tr(
"Adds X and Y (or latitude/longitude) fields to a point layer." );
43QStringList QgsAddXYFieldsAlgorithm::tags()
const
45 return QObject::tr(
"add,create,latitude,longitude,columns,attributes" ).split(
',' );
48QString QgsAddXYFieldsAlgorithm::group()
const
50 return QObject::tr(
"Vector table" );
53QString QgsAddXYFieldsAlgorithm::groupId()
const
55 return QStringLiteral(
"vectortable" );
58QString QgsAddXYFieldsAlgorithm::outputName()
const
60 return QObject::tr(
"Added fields" );
63QList<int> QgsAddXYFieldsAlgorithm::inputLayerTypes()
const
68QgsAddXYFieldsAlgorithm *QgsAddXYFieldsAlgorithm::createInstance()
const
70 return new QgsAddXYFieldsAlgorithm();
78void QgsAddXYFieldsAlgorithm::initParameters(
const QVariantMap &configuration )
80 mIsInPlace = configuration.value( QStringLiteral(
"IN_PLACE" ) ).toBool();
82 addParameter(
new QgsProcessingParameterCrs( QStringLiteral(
"CRS" ), QObject::tr(
"Coordinate system" ), QStringLiteral(
"EPSG:4326" ) ) );
88 addParameter(
new QgsProcessingParameterField( QStringLiteral(
"FIELD_X" ), QObject::tr(
"X field" ), QVariant(), QStringLiteral(
"INPUT" ) ) );
89 addParameter(
new QgsProcessingParameterField( QStringLiteral(
"FIELD_Y" ), QObject::tr(
"Y field" ), QVariant(), QStringLiteral(
"INPUT" ) ) );
97 mInPlaceXFieldIndex = inputFields.
lookupField( mInPlaceXField );
98 mInPlaceYFieldIndex = inputFields.
lookupField( mInPlaceYField );
103 const QString xFieldName = mPrefix +
'x';
104 const QString yFieldName = mPrefix +
'y';
107 outFields.
append(
QgsField( xFieldName, QMetaType::Type::Double, QString(), 20, 10 ) );
108 outFields.
append(
QgsField( yFieldName, QMetaType::Type::Double, QString(), 20, 10 ) );
115 mSourceCrs = inputCrs;
122 mPrefix = parameterAsString( parameters, QStringLiteral(
"PREFIX" ), context );
125 mInPlaceXField = parameterAsString( parameters, QStringLiteral(
"FIELD_X" ), context );
126 mInPlaceYField = parameterAsString( parameters, QStringLiteral(
"FIELD_Y" ), context );
129 mCrs = parameterAsCrs( parameters, QStringLiteral(
"CRS" ), context );
135 if ( mTransformNeedsInitialization )
138 mTransformNeedsInitialization =
false;
140 if ( mIsInPlace && mInPlaceXFieldIndex == -1 )
150 throw QgsProcessingException( QObject::tr(
"Multipoint features are not supported - please convert to single point features first." ) );
155 const QgsPointXY transformed = mTransform.transform( point );
161 feedback->
reportError( QObject::tr(
"Could not transform point to destination CRS" ) );
168 attributes << x << y;
172 attributes[mInPlaceXFieldIndex] = std::move( x );
173 attributes[mInPlaceYFieldIndex] = std::move( y );
179bool QgsAddXYFieldsAlgorithm::supportInPlaceEdit(
const QgsMapLayer *layer )
const
181 if (
const QgsVectorLayer *vl = qobject_cast<const QgsVectorLayer *>( layer ) )
@ VectorPoint
Vector point layers.
@ SkipGeometryValidityChecks
Invalid geometry checks should always be skipped. This flag can be useful for algorithms which always...
QFlags< ProcessingFeatureSourceFlag > ProcessingFeatureSourceFlags
Flags which control how QgsProcessingFeatureSource fetches features.
This class represents a coordinate reference system (CRS).
Custom exception class for Coordinate Reference System related exceptions.
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.
Encapsulate a field in an attribute table or data source.
Container of fields for a vector layer.
bool append(const QgsField &field, Qgis::FieldOrigin origin=Qgis::FieldOrigin::Provider, int originIndex=-1)
Appends a field.
Q_INVOKABLE int lookupField(const QString &fieldName) const
Looks up field's index from the field name.
QgsPointXY asPoint() const
Returns the contents of the geometry as a 2-dimensional point.
bool isMultipart() const
Returns true if WKB of the geometry is of WKBMulti* type.
Base class for all map layer types.
A class to represent a 2D point.
Contains information about the context in which a processing algorithm is executed.
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context.
Custom exception class for processing related exceptions.
Base class for providing feedback from a processing algorithm.
virtual void reportError(const QString &error, bool fatalError=false)
Reports that the algorithm encountered an error while executing.
A coordinate reference system parameter for processing algorithms.
A vector layer or feature source field parameter for processing algorithms.
A string parameter for processing algorithms.
Represents a vector layer which manages a vector based data sets.
QList< QgsFeature > QgsFeatureList