24QString QgsAddXYFieldsAlgorithm::name()
const
26 return QStringLiteral(
"addxyfields" );
29QString QgsAddXYFieldsAlgorithm::displayName()
const
31 return QObject::tr(
"Add X/Y fields to layer" );
34QString QgsAddXYFieldsAlgorithm::shortHelpString()
const
36 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)." );
39QString QgsAddXYFieldsAlgorithm::shortDescription()
const
41 return QObject::tr(
"Adds X and Y (or latitude/longitude) fields to a point layer." );
44QStringList QgsAddXYFieldsAlgorithm::tags()
const
46 return QObject::tr(
"add,create,latitude,longitude,columns,attributes" ).split(
',' );
49QString QgsAddXYFieldsAlgorithm::group()
const
51 return QObject::tr(
"Vector table" );
54QString QgsAddXYFieldsAlgorithm::groupId()
const
56 return QStringLiteral(
"vectortable" );
59QString QgsAddXYFieldsAlgorithm::outputName()
const
61 return QObject::tr(
"Added fields" );
64QList<int> QgsAddXYFieldsAlgorithm::inputLayerTypes()
const
69QgsAddXYFieldsAlgorithm *QgsAddXYFieldsAlgorithm::createInstance()
const
71 return new QgsAddXYFieldsAlgorithm();
79void QgsAddXYFieldsAlgorithm::initParameters(
const QVariantMap &configuration )
81 mIsInPlace = configuration.value( QStringLiteral(
"IN_PLACE" ) ).toBool();
83 addParameter(
new QgsProcessingParameterCrs( QStringLiteral(
"CRS" ), QObject::tr(
"Coordinate system" ), QStringLiteral(
"EPSG:4326" ) ) );
89 addParameter(
new QgsProcessingParameterField( QStringLiteral(
"FIELD_X" ), QObject::tr(
"X field" ), QVariant(), QStringLiteral(
"INPUT" ) ) );
90 addParameter(
new QgsProcessingParameterField( QStringLiteral(
"FIELD_Y" ), QObject::tr(
"Y field" ), QVariant(), QStringLiteral(
"INPUT" ) ) );
98 mInPlaceXFieldIndex = inputFields.
lookupField( mInPlaceXField );
99 mInPlaceYFieldIndex = inputFields.
lookupField( mInPlaceYField );
104 const QString xFieldName = mPrefix +
'x';
105 const QString yFieldName = mPrefix +
'y';
108 outFields.
append(
QgsField( xFieldName, QVariant::Double, QString(), 20, 10 ) );
109 outFields.
append(
QgsField( yFieldName, QVariant::Double, QString(), 20, 10 ) );
116 mSourceCrs = inputCrs;
123 mPrefix = parameterAsString( parameters, QStringLiteral(
"PREFIX" ), context );
126 mInPlaceXField = parameterAsString( parameters, QStringLiteral(
"FIELD_X" ), context );
127 mInPlaceYField = parameterAsString( parameters, QStringLiteral(
"FIELD_Y" ), context );
130 mCrs = parameterAsCrs( parameters, QStringLiteral(
"CRS" ), context );
136 if ( mTransformNeedsInitialization )
139 mTransformNeedsInitialization =
false;
141 if ( mIsInPlace && mInPlaceXFieldIndex == -1 )
151 throw QgsProcessingException( QObject::tr(
"Multipoint features are not supported - please convert to single point features first." ) );
156 const QgsPointXY transformed = mTransform.transform( point );
162 feedback->
reportError( QObject::tr(
"Could not transform point to destination CRS" ) );
169 attributes << x << y;
173 attributes[mInPlaceXFieldIndex] = x;
174 attributes[mInPlaceYFieldIndex] = y;
180bool QgsAddXYFieldsAlgorithm::supportInPlaceEdit(
const QgsMapLayer *layer )
const
182 if (
const QgsVectorLayer *vl = qobject_cast< const QgsVectorLayer * >( layer ) )
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, FieldOrigin origin=OriginProvider, int originIndex=-1)
Appends a field. The field must have unique name, otherwise it is rejected (returns false)
int lookupField(const QString &fieldName) const
Looks up field's index from the field name.
bool isMultipart() const SIP_HOLDGIL
Returns true if WKB of the geometry is of WKBMulti* type.
QgsPointXY asPoint() const
Returns the contents of the geometry as a 2-dimensional point.
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.
Flag
Flags controlling how QgsProcessingFeatureSource fetches features.
@ FlagSkipGeometryValidityChecks
Invalid geometry checks should always be skipped. This flag can be useful for algorithms which always...
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.
@ TypeVectorPoint
Vector point layers.
Represents a vector layer which manages a vector based data sets.
QList< QgsFeature > QgsFeatureList
const QgsCoordinateReferenceSystem & outputCrs