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( QObject::tr(
"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 ellipsoidal heights) and are expressed in its vertical units (generally meters). If unchecked, then z coordinates will not be changed by the transform." ) );
39 addParameter( transformZParam.release() );
42 auto crsOpParam = std::make_unique<QgsProcessingParameterCoordinateOperation>( u
"OPERATION"_s, QObject::tr(
"Coordinate operation" ), QVariant(), u
"INPUT"_s, u
"TARGET_CRS"_s, QVariant(), QVariant(),
true );
44 addParameter( crsOpParam.release() );
52QString QgsTransformAlgorithm::outputName()
const
54 return QObject::tr(
"Reprojected" );
62QString QgsTransformAlgorithm::name()
const
64 return u
"reprojectlayer"_s;
67QString QgsTransformAlgorithm::displayName()
const
69 return QObject::tr(
"Reproject layer" );
72QStringList QgsTransformAlgorithm::tags()
const
74 return QObject::tr(
"transform,reprojection,crs,srs,warp" ).split(
',' );
77QString QgsTransformAlgorithm::group()
const
79 return QObject::tr(
"Vector general" );
82QString QgsTransformAlgorithm::groupId()
const
84 return u
"vectorgeneral"_s;
87QString QgsTransformAlgorithm::shortHelpString()
const
89 return QObject::tr(
"This algorithm reprojects a vector layer. It creates a new layer with the same features "
90 "as the input one, but with geometries reprojected to a new CRS.\n\n"
91 "Attributes are not modified by this algorithm." );
94QString QgsTransformAlgorithm::shortDescription()
const
96 return QObject::tr(
"Creates a vector layer with geometries transformed to a new CRS." );
99QgsTransformAlgorithm *QgsTransformAlgorithm::createInstance()
const
101 return new QgsTransformAlgorithm();
106 prepareSource( parameters, context );
107 mDestCrs = parameterAsCrs( parameters, u
"TARGET_CRS"_s, context );
109 mConvertCurveToSegments = parameterAsBoolean( parameters, u
"CONVERT_CURVED_GEOMETRIES"_s, context );
110 mTransformZ = parameterAsBoolean( parameters, u
"TRANSFORM_Z"_s, context );
111 mCoordOp = parameterAsString( parameters, u
"OPERATION"_s, context );
118 if ( !mCreatedTransform )
120 mCreatedTransform =
true;
121 if ( !mCoordOp.isEmpty() )
122 mTransformContext.addCoordinateOperation( sourceCrs(), mDestCrs, mCoordOp,
false );
125 mTransform.disableFallbackOperationHandler(
true );
132 if ( !mTransform.isShortCircuited() && mConvertCurveToSegments )
148 if ( !mWarnedAboutFallbackTransform && mTransform.fallbackOperationOccurred() )
150 feedback->
reportError( QObject::tr(
"An alternative, ballpark-only transform was used when transforming coordinates for one or more features. "
151 "(Possibly an incorrect choice of operation was made for transformations between these reference systems - check "
152 "that the selected operation is valid for the full extent of the input layer.)" ) );
153 mWarnedAboutFallbackTransform =
true;
159 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