23void QgsTransformAlgorithm::initParameters(
const QVariantMap & )
25 addParameter(
new QgsProcessingParameterCrs( QStringLiteral(
"TARGET_CRS" ), QObject::tr(
"Target CRS" ), QStringLiteral(
"EPSG:4326" ) ) );
28 auto convertCurvesParam = std::make_unique<QgsProcessingParameterBoolean>( QStringLiteral(
"CONVERT_CURVED_GEOMETRIES" ), QObject::tr(
"Convert curved geometries to straight segments" ),
false );
29 convertCurvesParam->setHelp( QObject::tr(
"If checked, curved geometries will be converted to straight segments. Otherwise, they will be kept as curves. This can fix distortion issues." ) );
30 addParameter( convertCurvesParam.release() );
33 auto crsOpParam = std::make_unique<QgsProcessingParameterCoordinateOperation>( QStringLiteral(
"OPERATION" ), QObject::tr(
"Coordinate operation" ), QVariant(), QStringLiteral(
"INPUT" ), QStringLiteral(
"TARGET_CRS" ), QVariant(), QVariant(),
true );
35 addParameter( crsOpParam.release() );
43QString QgsTransformAlgorithm::outputName()
const
45 return QObject::tr(
"Reprojected" );
53QString QgsTransformAlgorithm::name()
const
55 return QStringLiteral(
"reprojectlayer" );
58QString QgsTransformAlgorithm::displayName()
const
60 return QObject::tr(
"Reproject layer" );
63QStringList QgsTransformAlgorithm::tags()
const
65 return QObject::tr(
"transform,reprojection,crs,srs,warp" ).split(
',' );
68QString QgsTransformAlgorithm::group()
const
70 return QObject::tr(
"Vector general" );
73QString QgsTransformAlgorithm::groupId()
const
75 return QStringLiteral(
"vectorgeneral" );
78QString QgsTransformAlgorithm::shortHelpString()
const
80 return QObject::tr(
"This algorithm reprojects a vector layer. It creates a new layer with the same features "
81 "as the input one, but with geometries reprojected to a new CRS.\n\n"
82 "Attributes are not modified by this algorithm." );
85QString QgsTransformAlgorithm::shortDescription()
const
87 return QObject::tr(
"Creates a vector layer with geometries transformed to a new CRS." );
90QgsTransformAlgorithm *QgsTransformAlgorithm::createInstance()
const
92 return new QgsTransformAlgorithm();
97 prepareSource( parameters, context );
98 mDestCrs = parameterAsCrs( parameters, QStringLiteral(
"TARGET_CRS" ), context );
100 mConvertCurveToSegments = parameterAsBoolean( parameters, QStringLiteral(
"CONVERT_CURVED_GEOMETRIES" ), context );
101 mCoordOp = parameterAsString( parameters, QStringLiteral(
"OPERATION" ), context );
108 if ( !mCreatedTransform )
110 mCreatedTransform =
true;
111 if ( !mCoordOp.isEmpty() )
112 mTransformContext.addCoordinateOperation( sourceCrs(), mDestCrs, mCoordOp,
false );
115 mTransform.disableFallbackOperationHandler(
true );
122 if ( !mTransform.isShortCircuited() && mConvertCurveToSegments )
138 if ( !mWarnedAboutFallbackTransform && mTransform.fallbackOperationOccurred() )
140 feedback->
reportError( QObject::tr(
"An alternative, ballpark-only transform was used when transforming coordinates for one or more features. "
141 "(Possibly an incorrect choice of operation was made for transformations between these reference systems - check "
142 "that the selected operation is valid for the full extent of the input layer.)" ) );
143 mWarnedAboutFallbackTransform =
true;
149 feedback->
reportError( QObject::tr(
"Encountered a transform error when reprojecting feature with id %1." ).arg( f.
id() ) );
@ Success
Operation succeeded.
@ SkipGeometryValidityChecks
Invalid geometry checks should always be skipped. This flag can be useful for algorithms which always...
@ Advanced
Parameter is an advanced parameter which should be hidden from users by default.
QFlags< ProcessingFeatureSourceFlag > ProcessingFeatureSourceFlags
Flags which control how QgsProcessingFeatureSource fetches features.
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)
Transforms this geometry as described by the coordinate transform ct.
void convertToStraightSegment(double tolerance=M_PI/180., QgsAbstractGeometry::SegmentationToleranceType toleranceType=QgsAbstractGeometry::MaximumAngle)
Converts the geometry to straight line segments, if it is a curved geometry type.
Contains information about the context in which a processing algorithm is executed.
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context.
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.
QList< QgsFeature > QgsFeatureList