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 Base class for all map layer types.
Base class for providing feedback from a processing algorithm.
Invalid geometry checks should always be skipped. This flag can be useful for algorithms which always...
bool isMultipart() const
Returns true if WKB of the geometry is of WKBMulti* type.
QList< QgsFeature > QgsFeatureList
A class to represent a 2D point.
Container of fields for a vector layer.
void setAttributes(const QgsAttributes &attrs)
Sets the feature's attributes.
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.
Custom exception class for processing related exceptions.
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context.
bool append(const QgsField &field, FieldOrigin origin=OriginProvider, int originIndex=-1)
Appends a field. The field must have unique name, otherwise it is rejected (returns false) ...
Encapsulate a field in an attribute table or data source.
A coordinate reference system parameter for processing algorithms.
Flag
Flags controlling how QgsProcessingFeatureSource fetches features.
QgsPointXY asPoint() const
Returns the contents of the geometry as a 2-dimensional point.
This class represents a coordinate reference system (CRS).
const QgsCoordinateReferenceSystem & outputCrs
virtual void reportError(const QString &error, bool fatalError=false)
Reports that the algorithm encountered an error while executing.
Custom exception class for Coordinate Reference System related exceptions.
Contains information about the context in which a processing algorithm is executed.
A string parameter for processing algorithms.