Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35875 from olivierdalang/tracing_curves_prototype
[feature] Curved geometries support for trace tool
- Loading branch information
Showing
25 changed files
with
860 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
157 changes: 157 additions & 0 deletions
157
src/analysis/processing/qgsalgorithmconverttocurves.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
/*************************************************************************** | ||
qgsalgorithmconverttocurves.cpp | ||
--------------------- | ||
begin : March 2018 | ||
copyright : (C) 2018 by Nyall Dawson | ||
email : nyall dot dawson at gmail dot com | ||
***************************************************************************/ | ||
|
||
/*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "qgsalgorithmconverttocurves.h" | ||
|
||
///@cond PRIVATE | ||
|
||
QString QgsConvertToCurvesAlgorithm::name() const | ||
{ | ||
return QStringLiteral( "converttocurves" ); | ||
} | ||
|
||
QString QgsConvertToCurvesAlgorithm::displayName() const | ||
{ | ||
return QObject::tr( "Convert to curved geometries" ); | ||
} | ||
|
||
QStringList QgsConvertToCurvesAlgorithm::tags() const | ||
{ | ||
return QObject::tr( "straight,segmentize,curves,curved,circular" ).split( ',' ); | ||
} | ||
|
||
QString QgsConvertToCurvesAlgorithm::group() const | ||
{ | ||
return QObject::tr( "Vector geometry" ); | ||
} | ||
|
||
QString QgsConvertToCurvesAlgorithm::groupId() const | ||
{ | ||
return QStringLiteral( "vectorgeometry" ); | ||
} | ||
|
||
QString QgsConvertToCurvesAlgorithm::outputName() const | ||
{ | ||
return QObject::tr( "Curves" ); | ||
} | ||
|
||
QString QgsConvertToCurvesAlgorithm::shortHelpString() const | ||
{ | ||
return QObject::tr( "This algorithm converts a geometry into its curved geometry equivalent.\n\n" | ||
"Already curved geometries will be retained without change." ); | ||
} | ||
|
||
QgsConvertToCurvesAlgorithm *QgsConvertToCurvesAlgorithm::createInstance() const | ||
{ | ||
return new QgsConvertToCurvesAlgorithm(); | ||
} | ||
|
||
QList<int> QgsConvertToCurvesAlgorithm::inputLayerTypes() const | ||
{ | ||
return QList<int>() << QgsProcessing::TypeVectorLine << QgsProcessing::TypeVectorPolygon; | ||
} | ||
|
||
void QgsConvertToCurvesAlgorithm::initParameters( const QVariantMap & ) | ||
{ | ||
std::unique_ptr< QgsProcessingParameterNumber > tolerance = qgis::make_unique< QgsProcessingParameterNumber >( QStringLiteral( "DISTANCE" ), | ||
QObject::tr( "Maximum distance tolerance" ), QgsProcessingParameterNumber::Double, | ||
0.000001, false, 0, 10000000.0 ); | ||
tolerance->setIsDynamic( true ); | ||
tolerance->setDynamicPropertyDefinition( QgsPropertyDefinition( QStringLiteral( "DISTANCE" ), QObject::tr( "Maximum distance tolerance" ), QgsPropertyDefinition::DoublePositive ) ); | ||
tolerance->setDynamicLayerParameterName( QStringLiteral( "INPUT" ) ); | ||
addParameter( tolerance.release() ); | ||
|
||
std::unique_ptr< QgsProcessingParameterNumber > angleTolerance = qgis::make_unique< QgsProcessingParameterNumber >( QStringLiteral( "ANGLE" ), | ||
QObject::tr( "Maximum angle tolerance" ), QgsProcessingParameterNumber::Double, | ||
0.000001, false, 0, 45.0 ); | ||
angleTolerance->setIsDynamic( true ); | ||
angleTolerance->setDynamicPropertyDefinition( QgsPropertyDefinition( QStringLiteral( "ANGLE" ), QObject::tr( "Maximum angle tolerance" ), QgsPropertyDefinition::DoublePositive ) ); | ||
angleTolerance->setDynamicLayerParameterName( QStringLiteral( "INPUT" ) ); | ||
addParameter( angleTolerance.release() ); | ||
} | ||
|
||
bool QgsConvertToCurvesAlgorithm::prepareAlgorithm( const QVariantMap ¶meters, QgsProcessingContext &context, QgsProcessingFeedback * ) | ||
{ | ||
mTolerance = parameterAsDouble( parameters, QStringLiteral( "DISTANCE" ), context ); | ||
mDynamicTolerance = QgsProcessingParameters::isDynamic( parameters, QStringLiteral( "DISTANCE" ) ); | ||
if ( mDynamicTolerance ) | ||
mToleranceProperty = parameters.value( QStringLiteral( "DISTANCE" ) ).value< QgsProperty >(); | ||
|
||
mAngleTolerance = parameterAsDouble( parameters, QStringLiteral( "ANGLE" ), context ); | ||
mDynamicAngleTolerance = QgsProcessingParameters::isDynamic( parameters, QStringLiteral( "ANGLE" ) ); | ||
if ( mDynamicAngleTolerance ) | ||
mAngleToleranceProperty = parameters.value( QStringLiteral( "ANGLE" ) ).value< QgsProperty >(); | ||
|
||
return true; | ||
} | ||
|
||
QgsFeatureList QgsConvertToCurvesAlgorithm::processFeature( const QgsFeature &feature, QgsProcessingContext &context, QgsProcessingFeedback * ) | ||
{ | ||
QgsFeature f = feature; | ||
if ( f.hasGeometry() ) | ||
{ | ||
QgsGeometry geometry = f.geometry(); | ||
double tolerance = mTolerance; | ||
if ( mDynamicTolerance ) | ||
tolerance = mToleranceProperty.valueAsDouble( context.expressionContext(), tolerance ); | ||
double angleTolerance = mAngleTolerance; | ||
if ( mDynamicAngleTolerance ) | ||
angleTolerance = mAngleToleranceProperty.valueAsDouble( context.expressionContext(), angleTolerance ); | ||
|
||
f.setGeometry( geometry.convertToCurves( tolerance, angleTolerance * M_PI / 180.0 ) ); | ||
} | ||
return QgsFeatureList() << f; | ||
} | ||
|
||
QgsWkbTypes::Type QgsConvertToCurvesAlgorithm::outputWkbType( QgsWkbTypes::Type inputWkbType ) const | ||
{ | ||
if ( QgsWkbTypes::isCurvedType( inputWkbType ) ) | ||
return inputWkbType; | ||
|
||
QgsWkbTypes::Type outType = QgsWkbTypes::Unknown; | ||
switch ( QgsWkbTypes::geometryType( inputWkbType ) ) | ||
{ | ||
case QgsWkbTypes::PointGeometry: | ||
case QgsWkbTypes::NullGeometry: | ||
case QgsWkbTypes::UnknownGeometry: | ||
return inputWkbType; | ||
|
||
case QgsWkbTypes::LineGeometry: | ||
outType = QgsWkbTypes::CompoundCurve; | ||
break; | ||
|
||
case QgsWkbTypes::PolygonGeometry: | ||
outType = QgsWkbTypes::CurvePolygon; | ||
break; | ||
} | ||
|
||
if ( QgsWkbTypes::isMultiType( inputWkbType ) ) | ||
outType = QgsWkbTypes::multiType( outType ); | ||
|
||
if ( QgsWkbTypes::hasZ( inputWkbType ) ) | ||
outType = QgsWkbTypes::addZ( outType ); | ||
|
||
if ( QgsWkbTypes::hasM( inputWkbType ) ) | ||
outType = QgsWkbTypes::addM( outType ); | ||
|
||
return outType; | ||
} | ||
|
||
|
||
///@endcond | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/*************************************************************************** | ||
qgsalgorithmconverttocurves.h | ||
--------------------- | ||
begin : March 2018 | ||
copyright : (C) 2018 by Nyall Dawson | ||
email : nyall dot dawson at gmail dot com | ||
***************************************************************************/ | ||
|
||
/*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#ifndef QGSALGORITHMCONVERTTOCURVES_H | ||
#define QGSALGORITHMCONVERTTOCURVES_H | ||
|
||
#define SIP_NO_FILE | ||
|
||
#include "qgis.h" | ||
#include "qgsprocessingalgorithm.h" | ||
#include "qgsmaptopixelgeometrysimplifier.h" | ||
|
||
///@cond PRIVATE | ||
|
||
/** | ||
* Native segmentize by maximum distance algorithm. | ||
*/ | ||
class QgsConvertToCurvesAlgorithm : public QgsProcessingFeatureBasedAlgorithm | ||
{ | ||
|
||
public: | ||
|
||
QgsConvertToCurvesAlgorithm() = default; | ||
QString name() const override; | ||
QString displayName() const override; | ||
QStringList tags() const override; | ||
QString group() const override; | ||
QString groupId() const override; | ||
QString shortHelpString() const override; | ||
QgsConvertToCurvesAlgorithm *createInstance() const override SIP_FACTORY; | ||
QList<int> inputLayerTypes() const override; | ||
void initParameters( const QVariantMap &configuration = QVariantMap() ) override; | ||
|
||
protected: | ||
QString outputName() const override; | ||
bool prepareAlgorithm( const QVariantMap ¶meters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override; | ||
QgsFeatureList processFeature( const QgsFeature &feature, QgsProcessingContext &, QgsProcessingFeedback *feedback ) override; | ||
QgsWkbTypes::Type outputWkbType( QgsWkbTypes::Type inputWkbType ) const override; | ||
|
||
private: | ||
|
||
double mTolerance = 0.000001; | ||
bool mDynamicTolerance = false; | ||
QgsProperty mToleranceProperty; | ||
|
||
double mAngleTolerance = 0.000001; | ||
bool mDynamicAngleTolerance = false; | ||
QgsProperty mAngleToleranceProperty; | ||
|
||
}; | ||
|
||
///@endcond PRIVATE | ||
|
||
#endif // QGSALGORITHMCONVERTTOCURVES_H | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.