27using namespace Qt::StringLiterals;
31 , mGeocoder( geocoder )
36 return QObject::tr(
"geocode" ).split(
',' );
41 return QObject::tr(
"Vector general" );
46 return u
"vectorgeneral"_s;
51 mIsInPlace = configuration.value( u
"IN_PLACE"_s ).toBool();
57 const QgsFields newFields = mGeocoder->appendedFields();
58 for (
const QgsField &newField : newFields )
72 if (
const QgsVectorLayer *vl = qobject_cast<const QgsVectorLayer *>( layer ) )
81 return QObject::tr(
"Geocoded" );
90 const QgsFields newFields = mGeocoder->appendedFields();
91 for (
const QgsField &newField : newFields )
92 mInPlaceFieldMap.insert( newField.name(),
parameterAsString( parameters, newField.name(), context ) );
105 mOutputCrs = inputCrs;
114 const QgsFields newFields = mGeocoder->appendedFields();
115 mAdditionalFields = newFields.
names();
127 QGS_MARK_ALGORITHM_SOURCE
131 const QString address = f.
attribute( mAddressField ).toString();
132 if ( address.isEmpty() )
134 f.padAttributes( mAdditionalFields.count() );
135 feedback->
pushWarning( QObject::tr(
"Empty address field for feature %1" ).arg( feature.
id() ) );
140 const QList<QgsGeocoderResult> results = mGeocoder->geocodeString( address, geocodeContext, feedback );
141 if ( results.empty() )
143 f.padAttributes( mAdditionalFields.count() );
144 feedback->
pushWarning( QObject::tr(
"No result for %1" ).arg( address ) );
148 if ( !results.at( 0 ).isValid() )
150 f.padAttributes( mAdditionalFields.count() );
151 feedback->
reportError( QObject::tr(
"Error geocoding %1: %2" ).arg( address, results.at( 0 ).error() ) );
156 const QVariantMap additionalAttributes = results.at( 0 ).additionalAttributes();
159 for (
const QString &additionalField : mAdditionalFields )
161 attr.append( additionalAttributes.value( additionalField ) );
163 f.setAttributes( attr );
167 for (
auto it = mInPlaceFieldMap.constBegin(); it != mInPlaceFieldMap.constEnd(); ++it )
169 if ( !it.value().isEmpty() )
171 f.setAttribute( it.value(), additionalAttributes.value( it.key() ) );
184 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.
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 QVariant attribute(const QString &name) const
Lookup attribute value by attribute name.
Encapsulate a field in an attribute table or data source.
Container of fields for a vector layer.
Encapsulates the context of a geocoding operation.
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.
QgsProcessingFeatureBasedAlgorithm()=default
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 dataset.
QList< QgsFeature > QgsFeatureList