mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-15 00:04:00 -04:00
[processing] Port transform alg to c++
This commit is contained in:
parent
501081f863
commit
f5f0a299c2
@ -62,6 +62,7 @@ void QgsNativeAlgorithms::loadAlgorithms()
|
||||
addAlgorithm( new QgsBufferAlgorithm() );
|
||||
addAlgorithm( new QgsDissolveAlgorithm() );
|
||||
addAlgorithm( new QgsClipAlgorithm() );
|
||||
addAlgorithm( new QgsTransformAlgorithm() );
|
||||
}
|
||||
|
||||
|
||||
@ -534,5 +535,64 @@ QVariantMap QgsClipAlgorithm::processAlgorithm( const QVariantMap ¶meters, Q
|
||||
}
|
||||
|
||||
|
||||
QgsTransformAlgorithm::QgsTransformAlgorithm()
|
||||
{
|
||||
addParameter( new QgsProcessingParameterFeatureSource( QStringLiteral( "INPUT" ), QObject::tr( "Input layer" ) ) );
|
||||
addParameter( new QgsProcessingParameterCrs( QStringLiteral( "TARGET_CRS" ), QObject::tr( "Target CRS" ), QStringLiteral( "EPSG:4326" ) ) );
|
||||
addParameter( new QgsProcessingParameterFeatureSink( QStringLiteral( "OUTPUT" ), QObject::tr( "Reprojected" ) ) );
|
||||
addOutput( new QgsProcessingOutputVectorLayer( QStringLiteral( "OUTPUT" ), QObject::tr( "Reprojected" ) ) );
|
||||
}
|
||||
|
||||
QString QgsTransformAlgorithm::shortHelpString() const
|
||||
{
|
||||
return QObject::tr( "This algorithm reprojects a vector layer. It creates a new layer with the same features "
|
||||
"as the input one, but with geometries reprojected to a new CRS.\n\n"
|
||||
"Attributes are not modified by this algorithm." );
|
||||
}
|
||||
|
||||
QVariantMap QgsTransformAlgorithm::processAlgorithm( const QVariantMap ¶meters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) const
|
||||
{
|
||||
std::unique_ptr< QgsFeatureSource > source( parameterAsSource( parameters, QStringLiteral( "INPUT" ), context ) );
|
||||
if ( !source )
|
||||
return QVariantMap();
|
||||
|
||||
QgsCoordinateReferenceSystem targetCrs = parameterAsCrs( parameters, QStringLiteral( "TARGET_CRS" ), context );
|
||||
|
||||
QString dest;
|
||||
std::unique_ptr< QgsFeatureSink > sink( parameterAsSink( parameters, QStringLiteral( "OUTPUT" ), context, source->fields(), source->wkbType(), targetCrs, dest ) );
|
||||
if ( !sink )
|
||||
return QVariantMap();
|
||||
|
||||
long count = source->featureCount();
|
||||
if ( count <= 0 )
|
||||
return QVariantMap();
|
||||
|
||||
QgsFeature f;
|
||||
QgsFeatureRequest req;
|
||||
// perform reprojection in the iterators...
|
||||
req.setDestinationCrs( targetCrs );
|
||||
|
||||
QgsFeatureIterator it = source->getFeatures( req );
|
||||
|
||||
double step = 100.0 / count;
|
||||
int current = 0;
|
||||
while ( it.nextFeature( f ) )
|
||||
{
|
||||
if ( feedback->isCanceled() )
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
sink->addFeature( f );
|
||||
feedback->setProgress( current * step );
|
||||
current++;
|
||||
}
|
||||
|
||||
QVariantMap outputs;
|
||||
outputs.insert( QStringLiteral( "OUTPUT" ), dest );
|
||||
return outputs;
|
||||
}
|
||||
|
||||
|
||||
///@endcond
|
||||
|
||||
|
@ -66,6 +66,29 @@ class QgsCentroidAlgorithm : public QgsProcessingAlgorithm
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Native transform algorithm.
|
||||
*/
|
||||
class QgsTransformAlgorithm : public QgsProcessingAlgorithm
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
QgsTransformAlgorithm();
|
||||
|
||||
QString name() const override { return QStringLiteral( "reprojectlayer" ); }
|
||||
QString displayName() const override { return QObject::tr( "Reproject layer" ); }
|
||||
virtual QStringList tags() const override { return QObject::tr( "transform,reproject,crs,srs,warp" ).split( ',' ); }
|
||||
QString group() const override { return QObject::tr( "Vector general tools" ); }
|
||||
QString shortHelpString() const override;
|
||||
|
||||
protected:
|
||||
|
||||
virtual QVariantMap processAlgorithm( const QVariantMap ¶meters,
|
||||
QgsProcessingContext &context, QgsProcessingFeedback *feedback ) const override;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Native buffer algorithm.
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user