Skip to content
Permalink
Browse files

Correctly assign output type from input type

  • Loading branch information
m-kuhn committed Jan 20, 2019
1 parent f4a25eb commit 6c110c824e36158c011134e8fe3497a8f674ab1c
@@ -53,6 +53,28 @@ QString QgsPolygonsToLinesAlgorithm::outputName() const
return QObject::tr( "Lines" );
}

QgsProcessing::SourceType QgsPolygonsToLinesAlgorithm::outputLayerType() const
{
return QgsProcessing::TypeVectorLine;
}

QgsWkbTypes::Type QgsPolygonsToLinesAlgorithm::outputWkbType( QgsWkbTypes::Type inputWkbType ) const
{
QgsWkbTypes::Type wkbType = QgsWkbTypes::Unknown;

if ( QgsWkbTypes::singleType( QgsWkbTypes::flatType( inputWkbType ) ) == QgsWkbTypes::Polygon )
wkbType = QgsWkbTypes::MultiLineString;
else if ( QgsWkbTypes::singleType( QgsWkbTypes::flatType( inputWkbType ) ) == QgsWkbTypes::CurvePolygon )
wkbType = QgsWkbTypes::MultiCurve;

if ( QgsWkbTypes::hasM( inputWkbType ) )
wkbType = QgsWkbTypes::addM( wkbType );
if ( QgsWkbTypes::hasZ( inputWkbType ) )
wkbType = QgsWkbTypes::addZ( wkbType );

return wkbType;
}

QString QgsPolygonsToLinesAlgorithm::shortHelpString() const
{
return QObject::tr( "Converts polygons to lines" );
@@ -70,7 +92,7 @@ QgsPolygonsToLinesAlgorithm *QgsPolygonsToLinesAlgorithm::createInstance() const

QList<int> QgsPolygonsToLinesAlgorithm::inputLayerTypes() const
{
return QList< int >() << QgsProcessing::TypeVectorPolygon;
return QList<int>() << QgsProcessing::TypeVectorPolygon;
}

QgsFeatureList QgsPolygonsToLinesAlgorithm::processFeature( const QgsFeature &feature, QgsProcessingContext &context, QgsProcessingFeedback * )
@@ -90,7 +112,7 @@ QgsGeometry QgsPolygonsToLinesAlgorithm::convertToLines( const QgsGeometry &geom
{
auto rings = extractRings( geometry.constGet() );

QgsWkbTypes::Type resultType = outWkbType( geometry.wkbType() );
QgsWkbTypes::Type resultType = outputWkbType( geometry.wkbType() );

std::unique_ptr<QgsMultiCurve> lineGeometry;

@@ -105,23 +127,6 @@ QgsGeometry QgsPolygonsToLinesAlgorithm::convertToLines( const QgsGeometry &geom
return QgsGeometry( lineGeometry.release() );
}

QgsWkbTypes::Type QgsPolygonsToLinesAlgorithm::outWkbType( QgsWkbTypes::Type polygonWkbType ) const
{
QgsWkbTypes::Type wkbType = QgsWkbTypes::NoGeometry;

if ( QgsWkbTypes::singleType( QgsWkbTypes::flatType( polygonWkbType ) ) == QgsWkbTypes::Polygon )
wkbType = QgsWkbTypes::MultiLineString;
else if ( QgsWkbTypes::singleType( QgsWkbTypes::flatType( polygonWkbType ) ) == QgsWkbTypes::CurvePolygon )
wkbType = QgsWkbTypes::MultiCurve;

if ( QgsWkbTypes::hasM( polygonWkbType ) )
wkbType = QgsWkbTypes::addM( wkbType );
if ( QgsWkbTypes::hasZ( polygonWkbType ) )
wkbType = QgsWkbTypes::addZ( wkbType );

return wkbType;
}

QList<QgsCurve *> QgsPolygonsToLinesAlgorithm::extractRings( const QgsAbstractGeometry *geom ) const
{
QList<QgsCurve *> rings;
@@ -46,12 +46,13 @@ class QgsPolygonsToLinesAlgorithm : public QgsProcessingFeatureBasedAlgorithm

protected:
QString outputName() const override;
QgsProcessing::SourceType outputLayerType() const override;
QgsWkbTypes::Type outputWkbType( QgsWkbTypes::Type inputWkbType ) const override;
QgsFeatureList processFeature( const QgsFeature &feature, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;

private:
QgsGeometry convertToLines( const QgsGeometry &geometry ) const;
QList<QgsCurve *> extractRings( const QgsAbstractGeometry *geom ) const;
QgsWkbTypes::Type outWkbType( QgsWkbTypes::Type polygonWkbType ) const;

friend class TestQgsProcessingAlgs;
};

0 comments on commit 6c110c8

Please sign in to comment.
You can’t perform that action at this time.