22using namespace Qt::StringLiterals;
27void QgsTransformAlgorithm::initParameters(
const QVariantMap & )
32 auto convertCurvesParam = std::make_unique<QgsProcessingParameterBoolean>( u
"CONVERT_CURVED_GEOMETRIES"_s, QObject::tr(
"Convert curved geometries to straight segments" ),
false );
33 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." ) );
34 addParameter( convertCurvesParam.release() );
37 auto transformZParam = std::make_unique<QgsProcessingParameterBoolean>( u
"TRANSFORM_Z"_s, QObject::tr(
"Also transform Z coordinates" ),
false );
38 transformZParam->setHelp(
40 "If checked, the z coordinates will also be transformed. This requires that the z coordinates in the geometries represent height relative to the vertical datum of the source CRS (generally "
41 "ellipsoidal heights) and are expressed in its vertical units (generally meters). If unchecked, then z coordinates will not be changed by the transform."
44 addParameter( transformZParam.release() );
48 = std::make_unique<QgsProcessingParameterCoordinateOperation>( u
"OPERATION"_s, QObject::tr(
"Coordinate operation" ), QVariant(), u
"INPUT"_s, u
"TARGET_CRS"_s, QVariant(), QVariant(),
true );
50 addParameter( crsOpParam.release() );
58QString QgsTransformAlgorithm::outputName()
const
60 return QObject::tr(
"Reprojected" );
68QString QgsTransformAlgorithm::name()
const
70 return u
"reprojectlayer"_s;
73QString QgsTransformAlgorithm::displayName()
const
75 return QObject::tr(
"Reproject layer" );
78QStringList QgsTransformAlgorithm::tags()
const
80 return QObject::tr(
"transform,reprojection,crs,srs,warp" ).split(
',' );
83QString QgsTransformAlgorithm::group()
const
85 return QObject::tr(
"Vector general" );
88QString QgsTransformAlgorithm::groupId()
const
90 return u
"vectorgeneral"_s;
93QString QgsTransformAlgorithm::shortHelpString()
const
96 "This algorithm reprojects a vector layer. It creates a new layer with the same features "
97 "as the input one, but with geometries reprojected to a new CRS.\n\n"
98 "Attributes are not modified by this algorithm."
102QString QgsTransformAlgorithm::shortDescription()
const
104 return QObject::tr(
"Creates a vector layer with geometries transformed to a new CRS." );
107QgsTransformAlgorithm *QgsTransformAlgorithm::createInstance()
const
109 return new QgsTransformAlgorithm();
114 prepareSource( parameters, context );
115 mDestCrs = parameterAsCrs( parameters, u
"TARGET_CRS"_s, context );
117 mConvertCurveToSegments = parameterAsBoolean( parameters, u
"CONVERT_CURVED_GEOMETRIES"_s, context );
118 mTransformZ = parameterAsBoolean( parameters, u
"TRANSFORM_Z"_s, context );
119 mCoordOp = parameterAsString( parameters, u
"OPERATION"_s, context );
126 if ( !mCreatedTransform )
128 mCreatedTransform =
true;
129 if ( !mCoordOp.isEmpty() )
130 mTransformContext.addCoordinateOperation( sourceCrs(), mDestCrs, mCoordOp,
false );
133 mTransform.disableFallbackOperationHandler(
true );
140 if ( !mTransform.isShortCircuited() && mConvertCurveToSegments )
156 if ( !mWarnedAboutFallbackTransform && mTransform.fallbackOperationOccurred() )
160 "An alternative, ballpark-only transform was used when transforming coordinates for one or more features. "
161 "(Possibly an incorrect choice of operation was made for transformations between these reference systems - check "
162 "that the selected operation is valid for the full extent of the input layer.)"
165 mWarnedAboutFallbackTransform =
true;
171 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.
@ Forward
Forward transform (from source to destination).
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