23void QgsTransformAlgorithm::initParameters(
const QVariantMap & )
25 addParameter(
new QgsProcessingParameterCrs( QStringLiteral(
"TARGET_CRS" ), QObject::tr(
"Target CRS" ), QStringLiteral(
"EPSG:4326" ) ) );
27 std::unique_ptr< QgsProcessingParameterCoordinateOperation > crsOpParam = std::make_unique< QgsProcessingParameterCoordinateOperation >( QStringLiteral(
"OPERATION" ), QObject::tr(
"Coordinate operation" ),
28 QVariant(), QStringLiteral(
"INPUT" ), QStringLiteral(
"TARGET_CRS" ), QVariant(), QVariant(),
true );
30 addParameter( crsOpParam.release() );
38QString QgsTransformAlgorithm::outputName()
const
40 return QObject::tr(
"Reprojected" );
48QString QgsTransformAlgorithm::name()
const
50 return QStringLiteral(
"reprojectlayer" );
53QString QgsTransformAlgorithm::displayName()
const
55 return QObject::tr(
"Reproject layer" );
58QStringList QgsTransformAlgorithm::tags()
const
60 return QObject::tr(
"transform,reprojection,crs,srs,warp" ).split(
',' );
63QString QgsTransformAlgorithm::group()
const
65 return QObject::tr(
"Vector general" );
68QString QgsTransformAlgorithm::groupId()
const
70 return QStringLiteral(
"vectorgeneral" );
73QString QgsTransformAlgorithm::shortHelpString()
const
75 return QObject::tr(
"This algorithm reprojects a vector layer. It creates a new layer with the same features "
76 "as the input one, but with geometries reprojected to a new CRS.\n\n"
77 "Attributes are not modified by this algorithm." );
80QgsTransformAlgorithm *QgsTransformAlgorithm::createInstance()
const
82 return new QgsTransformAlgorithm();
87 prepareSource( parameters, context );
88 mDestCrs = parameterAsCrs( parameters, QStringLiteral(
"TARGET_CRS" ), context );
90 mCoordOp = parameterAsString( parameters, QStringLiteral(
"OPERATION" ), context );
97 if ( !mCreatedTransform )
99 mCreatedTransform =
true;
100 if ( !mCoordOp.isEmpty() )
101 mTransformContext.addCoordinateOperation( sourceCrs(), mDestCrs, mCoordOp,
false );
104 mTransform.disableFallbackOperationHandler(
true );
121 if ( !mWarnedAboutFallbackTransform && mTransform.fallbackOperationOccurred() )
123 feedback->
reportError( QObject::tr(
"An alternative, ballpark-only transform was used when transforming coordinates for one or more features. "
124 "(Possibly an incorrect choice of operation was made for transformations between these reference systems - check "
125 "that the selected operation is valid for the full extent of the input layer.)" ) );
126 mWarnedAboutFallbackTransform =
true;
132 feedback->
reportError( QObject::tr(
"Encountered a transform error when reprojecting feature with id %1." ).arg( f.
id() ) );
@ Success
Operation succeeded.
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 clearGeometry()
Removes any geometry associated with the feature.
bool hasGeometry() const
Returns true if the feature has an associated geometry.
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
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.
Contains information about the context in which a processing algorithm is executed.
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context.
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.
@ FlagAdvanced
Parameter is an advanced parameter which should be hidden from users by default.
QList< QgsFeature > QgsFeatureList
const QgsCoordinateReferenceSystem & outputCrs