26 , mGeocoder( geocoder )
32 return QObject::tr(
"geocode" ).split(
',' );
37 return QObject::tr(
"Vector general" );
42 return QStringLiteral(
"vectorgeneral" );
47 mIsInPlace = configuration.value( QStringLiteral(
"IN_PLACE" ) ).toBool();
54 for (
const QgsField &newField : newFields )
66 if (
const QgsVectorLayer *vl = qobject_cast<const QgsVectorLayer *>( layer ) )
75 return QObject::tr(
"Geocoded" );
80 mAddressField =
parameterAsString( parameters, QStringLiteral(
"FIELD" ), context );
85 for (
const QgsField &newField : newFields )
86 mInPlaceFieldMap.insert( newField.name(),
parameterAsString( parameters, newField.name(), context ) );
99 mOutputCrs = inputCrs;
109 mAdditionalFields = newFields.
names();
123 const QString address = f.
attribute( mAddressField ).toString();
124 if ( address.isEmpty() )
127 feedback->
pushWarning( QObject::tr(
"Empty address field for feature %1" ).arg( feature.
id() ) );
132 const QList<QgsGeocoderResult> results = mGeocoder->
geocodeString( address, geocodeContext, feedback );
133 if ( results.empty() )
136 feedback->
pushWarning( QObject::tr(
"No result for %1" ).arg( address ) );
140 if ( !results.at( 0 ).isValid() )
143 feedback->
reportError( QObject::tr(
"Error geocoding %1: %2" ).arg( address, results.at( 0 ).error() ) );
148 const QVariantMap additionalAttributes = results.at( 0 ).additionalAttributes();
151 for (
const QString &additionalField : mAdditionalFields )
153 attr.append( additionalAttributes.value( additionalField ) );
159 for (
auto it = mInPlaceFieldMap.constBegin(); it != mInPlaceFieldMap.constEnd(); ++it )
161 if ( !it.value().isEmpty() )
163 f.
setAttribute( it.value(), additionalAttributes.value( it.key() ) );
176 feedback->
reportError( QObject::tr(
"Error transforming %1 to layer CRS" ).arg( address ) );
@ Vector
Tables (i.e. vector layers with or without geometry). When used for a sink this indicates the sink ha...
@ String
Accepts string fields.
WkbType
The WKB type describes the number of dimensions a geometry has.
bool prepareAlgorithm(const QVariantMap ¶meters, QgsProcessingContext &context, QgsProcessingFeedback *feedback) override
Prepares the algorithm to run using the specified parameters.
QgsFeatureList processFeature(const QgsFeature &feature, QgsProcessingContext &, QgsProcessingFeedback *feedback) override
Processes an individual input feature from the source.
void initParameters(const QVariantMap &configuration=QVariantMap()) override
Initializes any extra parameters added by the algorithm subclass.
QString group() const override
Returns the name of the group this algorithm belongs to.
QString outputName() const override
Returns the translated, user visible name for any layers created by this algorithm.
QgsCoordinateReferenceSystem outputCrs(const QgsCoordinateReferenceSystem &inputCrs) const override
Maps the input source coordinate reference system (inputCrs) to a corresponding output CRS generated ...
QgsBatchGeocodeAlgorithm(QgsGeocoderInterface *geocoder)
Constructor for QgsBatchGeocodeAlgorithm.
QgsFields outputFields(const QgsFields &inputFields) const override
Maps the input source fields (inputFields) to corresponding output fields generated by the algorithm.
QString groupId() const override
Returns the unique ID of the group this algorithm belongs to.
QStringList tags() const override
Returns a list of tags which relate to the algorithm, and are used to assist users in searching for s...
bool supportInPlaceEdit(const QgsMapLayer *layer) const override
Checks whether this algorithm supports in-place editing on the given layer Default implementation ret...
Qgis::WkbType outputWkbType(Qgis::WkbType inputWkbType) const override
Maps the input WKB geometry type (inputWkbType) to the corresponding output WKB type generated by the...
QList< int > inputLayerTypes() const override
Returns the valid input layer types for the source layer for this algorithm.
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...
Q_INVOKABLE bool setAttribute(int field, const QVariant &attr)
Sets an attribute's value by field index.
void setAttributes(const QgsAttributes &attrs)
Sets the feature's attributes.
void padAttributes(int count)
Resizes the attributes attached to this feature by appending the specified count of NULL values to th...
Q_INVOKABLE QVariant attribute(const QString &name) const
Lookup attribute value by attribute name.
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
Encapsulate a field in an attribute table or data source.
Container of fields for a vector layer.
Encapsulates the context of a geocoding operation.
virtual QList< QgsGeocoderResult > geocodeString(const QString &string, const QgsGeocoderContext &context, QgsFeedback *feedback=nullptr) const
Geocodes a string.
virtual QgsFields appendedFields() const
Returns a set of newly created fields which will be appended to existing features during the geocode ...
A geometry is the spatial representation of a feature.
Qgis::GeometryOperationResult transform(const QgsCoordinateTransform &ct, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward, bool transformZ=false)
Transforms this geometry as described by the coordinate transform ct.
Base class for all map layer types.
bool addParameter(QgsProcessingParameterDefinition *parameterDefinition, bool createOutput=true)
Adds a parameter definition to the algorithm.
QString parameterAsString(const QVariantMap ¶meters, const QString &name, const QgsProcessingContext &context) const
Evaluates the parameter with matching name to a static string value.
Contains information about the context in which a processing algorithm is executed.
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context.
An abstract QgsProcessingAlgorithm base class for processing algorithms which operate "feature-by-fea...
Base class for providing feedback from a processing algorithm.
virtual void pushWarning(const QString &warning)
Pushes a warning informational message from the algorithm.
virtual void reportError(const QString &error, bool fatalError=false)
Reports that the algorithm encountered an error while executing.
A vector layer or feature source field parameter for processing algorithms.
static QgsFields combineFields(const QgsFields &fieldsA, const QgsFields &fieldsB, const QString &fieldsBPrefix=QString())
Combines two field lists, avoiding duplicate field names (in a case-insensitive manner).
Represents a vector layer which manages a vector based data sets.
QList< QgsFeature > QgsFeatureList