QGIS API Documentation
3.26.3-Buenos Aires (65e4edfdad)
|
Go to the documentation of this file.
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 ) );
@ String
Accepts string fields.
Base class for providing feedback from a processing algorithm.
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.
virtual void reportError(const QString &error, bool fatalError=false)
Reports that the algorithm encountered an error while executing.
bool addParameter(QgsProcessingParameterDefinition *parameterDefinition, bool createOutput=true)
Adds a parameter definition to the algorithm.
Container of fields for a vector layer.
QgsWkbTypes::Type outputWkbType(QgsWkbTypes::Type inputWkbType) const override
Maps the input WKB geometry type (inputWkbType) to the corresponding output WKB type generated by the...
Type
The WKB type describes the number of dimensions a geometry has.
QString parameterAsString(const QVariantMap ¶meters, const QString &name, const QgsProcessingContext &context) const
Evaluates the parameter with matching name to a static string value.
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).
An abstract QgsProcessingAlgorithm base class for processing algorithms which operate "feature-by-fea...
Custom exception class for Coordinate Reference System related exceptions.
@ TypeVector
Tables (i.e. vector layers with or without geometry). When used for a sink this indicates the sink ha...
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
Contains information about the context in which a processing algorithm is executed.
virtual QgsFields appendedFields() const
Returns a set of newly created fields which will be appended to existing features during the geocode ...
QgsBatchGeocodeAlgorithm(QgsGeocoderInterface *geocoder)
Constructor for QgsBatchGeocodeAlgorithm.
QString outputName() const override
Returns the translated, user visible name for any layers created by this algorithm.
QList< QgsFeature > QgsFeatureList
QVariant attribute(const QString &name) const
Lookup attribute value by attribute name.
virtual QList< QgsGeocoderResult > geocodeString(const QString &string, const QgsGeocoderContext &context, QgsFeedback *feedback=nullptr) const
Geocodes a string.
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context.
This class represents a coordinate reference system (CRS).
bool setAttribute(int field, const QVariant &attr)
Sets an attribute's value by field index.
Encapsulates the context of a geocoding operation.
QgsFeatureList processFeature(const QgsFeature &feature, QgsProcessingContext &, QgsProcessingFeedback *feedback) override
Processes an individual input feature from the source.
QString group() const override
Returns the name of the group this algorithm belongs to.
A geometry is the spatial representation of a feature.
Represents a vector layer which manages a vector based data sets.
Base class for all map layer types. This is the base class for all map layer types (vector,...
QList< int > inputLayerTypes() const override
Returns the valid input layer types for the source layer for this algorithm.
A vector of attributes. Mostly equal to QVector<QVariant>.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
bool supportInPlaceEdit(const QgsMapLayer *layer) const override
Checks whether this algorithm supports in-place editing on the given layer Default implementation for...
QgsFields outputFields(const QgsFields &inputFields) const override
Maps the input source fields (inputFields) to corresponding output fields generated by the algorithm.
void initParameters(const QVariantMap &configuration=QVariantMap()) override
Initializes any extra parameters added by the algorithm subclass.
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...
QgsCoordinateReferenceSystem outputCrs(const QgsCoordinateReferenceSystem &inputCrs) const override
Maps the input source coordinate reference system (inputCrs) to a corresponding output CRS generated ...
QString groupId() const override
Returns the unique ID of the group this algorithm belongs to.
A vector layer or feature source field parameter for processing algorithms.
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 prepareAlgorithm(const QVariantMap ¶meters, QgsProcessingContext &context, QgsProcessingFeedback *feedback) override
Prepares the algorithm to run using the specified parameters.
virtual void pushWarning(const QString &warning)
Pushes a warning informational message from the algorithm.
QStringList names() const
Returns a list with field names.
Encapsulate a field in an attribute table or data source.