26 , mGeocoder( geocoder )
33 return QObject::tr(
"geocode" ).split(
',' );
38 return QObject::tr(
"Vector general" );
43 return QStringLiteral(
"vectorgeneral" );
48 mIsInPlace = configuration.value( QStringLiteral(
"IN_PLACE" ) ).toBool();
55 for (
const QgsField &newField : newFields )
67 if (
const QgsVectorLayer *vl = qobject_cast< const QgsVectorLayer * >( layer ) )
76 return QObject::tr(
"Geocoded" );
81 mAddressField =
parameterAsString( parameters, QStringLiteral(
"FIELD" ), context );
86 for (
const QgsField &newField : newFields )
87 mInPlaceFieldMap.insert( newField.name(),
parameterAsString( parameters, newField.name(), context ) );
100 mOutputCrs = inputCrs;
110 mAdditionalFields = newFields.
names();
124 const QString address = f.
attribute( mAddressField ).toString();
125 if ( address.isEmpty() )
128 feedback->
pushWarning( QObject::tr(
"Empty address field for feature %1" ).arg( feature.
id() ) );
133 const QList< QgsGeocoderResult > results = mGeocoder->
geocodeString( address, geocodeContext, feedback );
134 if ( results.empty() )
137 feedback->
pushWarning( QObject::tr(
"No result for %1" ).arg( address ) );
141 if ( !results.at( 0 ).isValid() )
144 feedback->
reportError( QObject::tr(
"Error geocoding %1: %2" ).arg( address, results.at( 0 ).error() ) );
149 const QVariantMap additionalAttributes = results.at( 0 ).additionalAttributes();
152 for (
const QString &additionalField : mAdditionalFields )
154 attr.append( additionalAttributes.value( additionalField ) );
160 for (
auto it = mInPlaceFieldMap.constBegin(); it != mInPlaceFieldMap.constEnd(); ++it )
162 if ( !it.value().isEmpty() )
164 f.
setAttribute( it.value(), additionalAttributes.value( it.key() ) );
177 feedback->
reportError( QObject::tr(
"Error transforming %1 to layer CRS" ).arg( address ) );
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.
QgsWkbTypes::Type outputWkbType(QgsWkbTypes::Type inputWkbType) const override
Maps the input WKB geometry type (inputWkbType) to the corresponding output WKB type generated by the...
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 for...
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...
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...
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.
QStringList names() const
Returns a list with field names.
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) SIP_THROW(QgsCsException)
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.
@ String
Accepts string fields.
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).
@ TypeVector
Tables (i.e. vector layers with or without geometry). When used for a sink this indicates the sink ha...
Represents a vector layer which manages a vector based data sets.
Type
The WKB type describes the number of dimensions a geometry has.
QList< QgsFeature > QgsFeatureList