Skip to content
Permalink
Browse files
[api] Add function to apply a dash pattern vector to a geometry
This returns a new multilinestring geometry which represents the
input geometry with the dash pattern applied to the lines or rings
of the input geometry.

Options are available to set rules for the start/end of the pattern,
e.g. ending on a full dash or gap, or half dash or gap.

Sponsored by North Road, thanks to SLYR
  • Loading branch information
nyalldawson committed Oct 30, 2021
1 parent 5c3915b commit 0795f726cf1afb53662b7ec269cc05ddb7e5c86e
@@ -1105,3 +1105,19 @@
Qgis.LineClipMode.__doc__ = 'Line clipping modes.\n\n.. versionadded:: 3.24\n\n' + '* ``ClipPainterOnly``: ' + Qgis.LineClipMode.ClipPainterOnly.__doc__ + '\n' + '* ``ClipToIntersection``: ' + Qgis.LineClipMode.ClipToIntersection.__doc__ + '\n' + '* ``NoClipping``: ' + Qgis.LineClipMode.NoClipping.__doc__
# --
Qgis.LineClipMode.baseClass = Qgis
# monkey patching scoped based enum
Qgis.DashPatternLineEndingRule.NoRule.__doc__ = "No special rule"
Qgis.DashPatternLineEndingRule.FullDash.__doc__ = "Start or finish the pattern with a full dash"
Qgis.DashPatternLineEndingRule.HalfDash.__doc__ = "Start or finish the pattern with a half length dash"
Qgis.DashPatternLineEndingRule.FullGap.__doc__ = "Start or finish the pattern with a full gap"
Qgis.DashPatternLineEndingRule.HalfGap.__doc__ = "Start or finish the pattern with a half length gap"
Qgis.DashPatternLineEndingRule.__doc__ = 'Dash pattern line ending rules.\n\n.. versionadded:: 3.24\n\n' + '* ``NoRule``: ' + Qgis.DashPatternLineEndingRule.NoRule.__doc__ + '\n' + '* ``FullDash``: ' + Qgis.DashPatternLineEndingRule.FullDash.__doc__ + '\n' + '* ``HalfDash``: ' + Qgis.DashPatternLineEndingRule.HalfDash.__doc__ + '\n' + '* ``FullGap``: ' + Qgis.DashPatternLineEndingRule.FullGap.__doc__ + '\n' + '* ``HalfGap``: ' + Qgis.DashPatternLineEndingRule.HalfGap.__doc__
# --
Qgis.DashPatternLineEndingRule.baseClass = Qgis
# monkey patching scoped based enum
Qgis.DashPatternSizeAdjustment.ScaleBothDashAndGap.__doc__ = "Both the dash and gap lengths are adjusted equally"
Qgis.DashPatternSizeAdjustment.ScaleDashOnly.__doc__ = "Only dash lengths are adjusted"
Qgis.DashPatternSizeAdjustment.ScaleGapOnly.__doc__ = "Only gap lengths are adjusted"
Qgis.DashPatternSizeAdjustment.__doc__ = 'Dash pattern size adjustment options.\n\n.. versionadded:: 3.24\n\n' + '* ``ScaleBothDashAndGap``: ' + Qgis.DashPatternSizeAdjustment.ScaleBothDashAndGap.__doc__ + '\n' + '* ``ScaleDashOnly``: ' + Qgis.DashPatternSizeAdjustment.ScaleDashOnly.__doc__ + '\n' + '* ``ScaleGapOnly``: ' + Qgis.DashPatternSizeAdjustment.ScaleGapOnly.__doc__
# --
Qgis.DashPatternSizeAdjustment.baseClass = Qgis
@@ -1133,6 +1133,25 @@ is 0, then a completely random sequence of points will be generated.

.. seealso:: :py:func:`squareWaves`

.. versionadded:: 3.24
%End

QgsGeometry applyDashPattern( const QVector< double > &pattern,
Qgis::DashPatternLineEndingRule startRule = Qgis::DashPatternLineEndingRule::NoRule,
Qgis::DashPatternLineEndingRule endRule = Qgis::DashPatternLineEndingRule::NoRule,
Qgis::DashPatternSizeAdjustment adjustment = Qgis::DashPatternSizeAdjustment::ScaleBothDashAndGap,
double patternOffset = 0 ) const;
%Docstring
Applies a dash pattern to a geometry, returning a MultiLineString geometry which is the
input geometry stroked along each line/ring with the specified ``pattern``.

The ``startRule`` and ``endRule`` options can be set to control how the dash pattern is adjusted
at line endings. If a ``startRule`` or ``endRule`` is set, the ``adjustment`` option defines whether
both dash and gaps, or only dash or gap sizes are adjusted to apply the rules.

The ``patternOffset`` option specifies how far along the pattern the result should start at.
The offset is applied AFTER any start/end rules are applied.

.. versionadded:: 3.24
%End

@@ -707,6 +707,22 @@ The development version
NoClipping,
};

enum class DashPatternLineEndingRule
{
NoRule,
FullDash,
HalfDash,
FullGap,
HalfGap,
};

enum class DashPatternSizeAdjustment
{
ScaleBothDashAndGap,
ScaleDashOnly,
ScaleGapOnly,
};

static const double DEFAULT_SEARCH_RADIUS_MM;

static const float DEFAULT_MAPTOPIXEL_THRESHOLD;
@@ -1233,6 +1233,12 @@ QgsGeometry QgsGeometry::roundWavesRandomized( double minimumWavelength, double
return engine.roundWavesRandomized( minimumWavelength, maximumWavelength, minimumAmplitude, maximumAmplitude, seed );
}

QgsGeometry QgsGeometry::applyDashPattern( const QVector<double> &pattern, Qgis::DashPatternLineEndingRule startRule, Qgis::DashPatternLineEndingRule endRule, Qgis::DashPatternSizeAdjustment adjustment, double patternOffset ) const
{
QgsInternalGeometryEngine engine( *this );
return engine.applyDashPattern( pattern, startRule, endRule, adjustment, patternOffset );
}

QgsGeometry QgsGeometry::snappedToGrid( double hSpacing, double vSpacing, double dSpacing, double mSpacing ) const
{
if ( !d->geometry )
@@ -1169,6 +1169,25 @@ class CORE_EXPORT QgsGeometry
*/
QgsGeometry roundWavesRandomized( double minimumWavelength, double maximumWavelength, double minimumAmplitude, double maximumAmplitude, unsigned long seed = 0 ) const;

/**
* Applies a dash pattern to a geometry, returning a MultiLineString geometry which is the
* input geometry stroked along each line/ring with the specified \a pattern.
*
* The \a startRule and \a endRule options can be set to control how the dash pattern is adjusted
* at line endings. If a \a startRule or \a endRule is set, the \a adjustment option defines whether
* both dash and gaps, or only dash or gap sizes are adjusted to apply the rules.
*
* The \a patternOffset option specifies how far along the pattern the result should start at.
* The offset is applied AFTER any start/end rules are applied.
*
* \since QGIS 3.24
*/
QgsGeometry applyDashPattern( const QVector< double > &pattern,
Qgis::DashPatternLineEndingRule startRule = Qgis::DashPatternLineEndingRule::NoRule,
Qgis::DashPatternLineEndingRule endRule = Qgis::DashPatternLineEndingRule::NoRule,
Qgis::DashPatternSizeAdjustment adjustment = Qgis::DashPatternSizeAdjustment::ScaleBothDashAndGap,
double patternOffset = 0 ) const;

/**
* Returns a new geometry with all points or vertices snapped to the closest point of the grid.
*
Loading

0 comments on commit 0795f72

Please sign in to comment.