23 QString QgsAddXYFieldsAlgorithm::name()
const
25 return QStringLiteral(
"addxyfields" );
28 QString QgsAddXYFieldsAlgorithm::displayName()
const
30 return QObject::tr(
"Add X/Y fields to layer" );
33 QString 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)." );
38 QString QgsAddXYFieldsAlgorithm::shortDescription()
const
40 return QObject::tr(
"Adds X and Y (or latitude/longitude) fields to a point layer." );
43 QStringList QgsAddXYFieldsAlgorithm::tags()
const
45 return QObject::tr(
"add,create,latitude,longitude,columns,attributes" ).split(
',' );
48 QString QgsAddXYFieldsAlgorithm::group()
const
50 return QObject::tr(
"Vector table" );
53 QString QgsAddXYFieldsAlgorithm::groupId()
const
55 return QStringLiteral(
"vectortable" );
58 QString QgsAddXYFieldsAlgorithm::outputName()
const
60 return QObject::tr(
"Added fields" );
63 QList<int> QgsAddXYFieldsAlgorithm::inputLayerTypes()
const
68 QgsAddXYFieldsAlgorithm *QgsAddXYFieldsAlgorithm::createInstance()
const
70 return new QgsAddXYFieldsAlgorithm();
78 void QgsAddXYFieldsAlgorithm::initParameters(
const QVariantMap & )
80 addParameter(
new QgsProcessingParameterCrs( QStringLiteral(
"CRS" ), QObject::tr(
"Coordinate system" ), QStringLiteral(
"EPSG:4326" ) ) );
86 const QString xFieldName = mPrefix +
'x';
87 const QString yFieldName = mPrefix +
'y';
90 outFields.
append(
QgsField( xFieldName, QVariant::Double, QString(), 20, 10 ) );
91 outFields.
append(
QgsField( yFieldName, QVariant::Double, QString(), 20, 10 ) );
97 mSourceCrs = inputCrs;
103 mPrefix = parameterAsString( parameters, QStringLiteral(
"PREFIX" ), context );
104 mCrs = parameterAsCrs( parameters, QStringLiteral(
"CRS" ), context );
110 if ( mTransformNeedsInitialization )
113 mTransformNeedsInitialization =
false;
121 throw QgsProcessingException( QObject::tr(
"Multipoint features are not supported - please convert to single point features first." ) );
126 const QgsPointXY transformed = mTransform.transform( point );
132 feedback->
reportError( QObject::tr(
"Could not transform point to destination CRS" ) );
137 attributes << x << y;
142 bool QgsAddXYFieldsAlgorithm::supportInPlaceEdit(
const QgsMapLayer *layer )
const