24 QString QgsLineSubstringAlgorithm::name()
const
26 return QStringLiteral(
"linesubstring" );
29 QString QgsLineSubstringAlgorithm::displayName()
const
31 return QObject::tr(
"Line substring" );
34 QStringList QgsLineSubstringAlgorithm::tags()
const
36 return QObject::tr(
"linestring,curve,split,shorten,shrink,portion,part,reference,referencing,distance,interpolate" ).split(
',' );
39 QString QgsLineSubstringAlgorithm::group()
const
41 return QObject::tr(
"Vector geometry" );
44 QString QgsLineSubstringAlgorithm::groupId()
const
46 return QStringLiteral(
"vectorgeometry" );
49 QString QgsLineSubstringAlgorithm::outputName()
const
51 return QObject::tr(
"Substring" );
54 QString QgsLineSubstringAlgorithm::shortHelpString()
const
56 return QObject::tr(
"This algorithm returns the portion of a line (or curve) which falls "
57 "between the specified start and end distances (measured from the "
58 "beginning of the line).\n\n"
59 "Z and M values are linearly interpolated from existing values.\n\n"
60 "If a multipart geometry is encountered, only the first part is considered when "
61 "calculating the substring." );
64 QString QgsLineSubstringAlgorithm::shortDescription()
const
66 return QObject::tr(
"Returns the substring of lines which fall between start and end distances." );
69 QList<int> QgsLineSubstringAlgorithm::inputLayerTypes()
const
79 QgsLineSubstringAlgorithm *QgsLineSubstringAlgorithm::createInstance()
const
81 return new QgsLineSubstringAlgorithm();
84 void QgsLineSubstringAlgorithm::initParameters(
const QVariantMap & )
86 std::unique_ptr< QgsProcessingParameterDistance> startDistance = qgis::make_unique< QgsProcessingParameterDistance >( QStringLiteral(
"START_DISTANCE" ),
87 QObject::tr(
"Start distance" ), 0.0, QStringLiteral(
"INPUT" ),
false, 0 );
88 startDistance->setIsDynamic(
true );
90 startDistance->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
91 addParameter( startDistance.release() );
93 std::unique_ptr< QgsProcessingParameterDistance> endDistance = qgis::make_unique< QgsProcessingParameterDistance >( QStringLiteral(
"END_DISTANCE" ),
94 QObject::tr(
"End distance" ), 1.0, QStringLiteral(
"INPUT" ),
false, 0 );
95 endDistance->setIsDynamic(
true );
97 endDistance->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
98 addParameter( endDistance.release() );
109 mStartDistance = parameterAsDouble( parameters, QStringLiteral(
"START_DISTANCE" ), context );
111 if ( mDynamicStartDistance )
112 mStartDistanceProperty = parameters.value( QStringLiteral(
"START_DISTANCE" ) ).value<
QgsProperty >();
114 mEndDistance = parameterAsDouble( parameters, QStringLiteral(
"END_DISTANCE" ), context );
116 if ( mDynamicEndDistance )
117 mEndDistanceProperty = parameters.value( QStringLiteral(
"END_DISTANCE" ) ).value<
QgsProperty >();
128 double startDistance = mStartDistance;
129 if ( mDynamicStartDistance )
130 startDistance = mStartDistanceProperty.valueAsDouble( context.
expressionContext(), startDistance );
132 double endDistance = mEndDistance;
133 if ( mDynamicEndDistance )
138 curve = qgsgeometry_cast< const QgsCurve * >( geometry.
constGet() );
143 if ( collection->numGeometries() > 0 )
145 curve = qgsgeometry_cast< const QgsCurve * >( collection->geometryN( 0 ) );
151 std::unique_ptr< QgsCurve > substring( curve->
curveSubstring( startDistance, endDistance ) );