23 void QgsTransformAlgorithm::initParameters(
const QVariantMap & )
25 addParameter(
new QgsProcessingParameterCrs( QStringLiteral(
"TARGET_CRS" ), QObject::tr(
"Target CRS" ), QStringLiteral(
"EPSG:4326" ) ) );
27 #if PROJ_VERSION_MAJOR>=6 28 std::unique_ptr< QgsProcessingParameterCoordinateOperation > crsOpParam = qgis::make_unique< QgsProcessingParameterCoordinateOperation >( QStringLiteral(
"OPERATION" ), QObject::tr(
"Coordinate operation" ),
29 QVariant(), QStringLiteral(
"INPUT" ), QStringLiteral(
"TARGET_CRS" ), QVariant(), QVariant(), true );
31 addParameter( crsOpParam.release() );
40 QString QgsTransformAlgorithm::outputName()
const 42 return QObject::tr(
"Reprojected" );
50 QString QgsTransformAlgorithm::name()
const 52 return QStringLiteral(
"reprojectlayer" );
55 QString QgsTransformAlgorithm::displayName()
const 57 return QObject::tr(
"Reproject layer" );
60 QStringList QgsTransformAlgorithm::tags()
const 62 return QObject::tr(
"transform,reprojection,crs,srs,warp" ).split(
',' );
65 QString QgsTransformAlgorithm::group()
const 67 return QObject::tr(
"Vector general" );
70 QString QgsTransformAlgorithm::groupId()
const 72 return QStringLiteral(
"vectorgeneral" );
75 QString QgsTransformAlgorithm::shortHelpString()
const 77 return QObject::tr(
"This algorithm reprojects a vector layer. It creates a new layer with the same features " 78 "as the input one, but with geometries reprojected to a new CRS.\n\n" 79 "Attributes are not modified by this algorithm." );
82 QgsTransformAlgorithm *QgsTransformAlgorithm::createInstance()
const 84 return new QgsTransformAlgorithm();
89 prepareSource( parameters, context );
90 mDestCrs = parameterAsCrs( parameters, QStringLiteral(
"TARGET_CRS" ), context );
92 mCoordOp = parameterAsString( parameters, QStringLiteral(
"OPERATION" ), context );
99 if ( !mCreatedTransform )
101 mCreatedTransform =
true;
102 if ( !mCoordOp.isEmpty() )
103 mTransformContext.addCoordinateOperation( sourceCrs(), mDestCrs, mCoordOp,
false );
106 mTransform.disableFallbackOperationHandler(
true );
123 if ( !mWarnedAboutFallbackTransform && mTransform.fallbackOperationOccurred() )
125 feedback->
reportError( QObject::tr(
"An alternative, ballpark-only transform was used when transforming coordinates for one or more features. " 126 "(Possibly an incorrect choice of operation was made for transformations between these reference systems - check " 127 "that the selected operation is valid for the full extent of the input layer.)" ) );
128 mWarnedAboutFallbackTransform =
true;
134 feedback->
reportError( QObject::tr(
"Encountered a transform error when reprojecting feature with id %1." ).arg( f.
id() ) );
Base class for providing feedback from a processing algorithm.
Parameter is an advanced parameter which should be hidden from users by default.
Invalid geometry checks should always be skipped. This flag can be useful for algorithms which always...
OperationResult transform(const QgsCoordinateTransform &ct, QgsCoordinateTransform::TransformDirection direction=QgsCoordinateTransform::ForwardTransform, bool transformZ=false) SIP_THROW(QgsCsException)
Transforms this geometry as described by the coordinate transform ct.
QList< QgsFeature > QgsFeatureList
A geometry is the spatial representation of a feature.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
bool hasGeometry() const
Returns true if the feature has an associated geometry.
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context.
A coordinate reference system parameter for processing algorithms.
Flag
Flags controlling how QgsProcessingFeatureSource fetches features.
void clearGeometry()
Removes any geometry associated with the feature.
This class represents a coordinate reference system (CRS).
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
const QgsCoordinateReferenceSystem & outputCrs
virtual void reportError(const QString &error, bool fatalError=false)
Reports that the algorithm encountered an error while executing.
Custom exception class for Coordinate Reference System related exceptions.
Contains information about the context in which a processing algorithm is executed.