Skip to content

Commit

Permalink
Correctly assign output type from input type
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Jan 20, 2019
1 parent f4a25eb commit 6c110c8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 20 deletions.
43 changes: 24 additions & 19 deletions src/analysis/processing/qgsalgorithmpolygonstolines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" );
Expand All @@ -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 * )
Expand All @@ -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;

Expand All @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/analysis/processing/qgsalgorithmpolygonstolines.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down

0 comments on commit 6c110c8

Please sign in to comment.