|
51 | 51 | #include "qgscurvepolygon.h"
|
52 | 52 | #include "qgsexpressionprivate.h"
|
53 | 53 | #include "qgsexpressionsorter.h"
|
| 54 | +#include "qgsmaptopixelgeometrysimplifier.h" |
54 | 55 |
|
55 | 56 | #if QT_VERSION < 0x050000
|
56 | 57 | #include <qtextdocument.h>
|
@@ -1767,6 +1768,59 @@ static QVariant fcnLineMerge( const QVariantList& values, const QgsExpressionCon
|
1767 | 1768 | return QVariant::fromValue( merged );
|
1768 | 1769 | }
|
1769 | 1770 |
|
| 1771 | +static QVariant fcnSimplify( const QVariantList& values, const QgsExpressionContext*, QgsExpression* parent ) |
| 1772 | +{ |
| 1773 | + QgsGeometry geom = getGeometry( values.at( 0 ), parent ); |
| 1774 | + |
| 1775 | + if ( geom.isEmpty() ) |
| 1776 | + return QVariant(); |
| 1777 | + |
| 1778 | + double tolerance = getDoubleValue( values.at( 1 ), parent ); |
| 1779 | + |
| 1780 | + QgsGeometry simplified = geom.simplify( tolerance ); |
| 1781 | + if ( simplified.isEmpty() ) |
| 1782 | + return QVariant(); |
| 1783 | + |
| 1784 | + return simplified; |
| 1785 | +} |
| 1786 | + |
| 1787 | +static QVariant fcnSimplifyVW( const QVariantList& values, const QgsExpressionContext*, QgsExpression* parent ) |
| 1788 | +{ |
| 1789 | + QgsGeometry geom = getGeometry( values.at( 0 ), parent ); |
| 1790 | + |
| 1791 | + if ( geom.isEmpty() ) |
| 1792 | + return QVariant(); |
| 1793 | + |
| 1794 | + double tolerance = getDoubleValue( values.at( 1 ), parent ); |
| 1795 | + |
| 1796 | + QgsMapToPixelSimplifier simplifier( QgsMapToPixelSimplifier::SimplifyGeometry, tolerance, QgsMapToPixelSimplifier::Visvalingam ); |
| 1797 | + |
| 1798 | + QgsGeometry simplified = simplifier.simplify( geom ); |
| 1799 | + if ( simplified.isEmpty() ) |
| 1800 | + return QVariant(); |
| 1801 | + |
| 1802 | + return simplified; |
| 1803 | +} |
| 1804 | + |
| 1805 | +static QVariant fcnSmooth( const QVariantList& values, const QgsExpressionContext*, QgsExpression* parent ) |
| 1806 | +{ |
| 1807 | + QgsGeometry geom = getGeometry( values.at( 0 ), parent ); |
| 1808 | + |
| 1809 | + if ( geom.isEmpty() ) |
| 1810 | + return QVariant(); |
| 1811 | + |
| 1812 | + int iterations = qMin( getIntValue( values.at( 1 ), parent ), 10 ); |
| 1813 | + double offset = qBound( 0.0, getDoubleValue( values.at( 2 ), parent ), 0.5 ); |
| 1814 | + double minLength = getDoubleValue( values.at( 3 ), parent ); |
| 1815 | + double maxAngle = qBound( 0.0, getDoubleValue( values.at( 4 ), parent ), 180.0 ); |
| 1816 | + |
| 1817 | + QgsGeometry smoothed = geom.smooth( iterations, offset, minLength, maxAngle ); |
| 1818 | + if ( smoothed.isEmpty() ) |
| 1819 | + return QVariant(); |
| 1820 | + |
| 1821 | + return smoothed; |
| 1822 | +} |
| 1823 | + |
1770 | 1824 | static QVariant fcnMakePoint( const QVariantList& values, const QgsExpressionContext*, QgsExpression* parent )
|
1771 | 1825 | {
|
1772 | 1826 | if ( values.count() < 2 || values.count() > 4 )
|
@@ -3166,6 +3220,7 @@ const QStringList& QgsExpression::BuiltinFunctions()
|
3166 | 3220 | << "disjoint" << "intersects" << "touches" << "crosses" << "contains"
|
3167 | 3221 | << "relate"
|
3168 | 3222 | << "overlaps" << "within" << "buffer" << "offset_curve" << "single_sided_buffer"
|
| 3223 | + << "simplify" << "simplify_vw" << "smooth" |
3169 | 3224 | << "centroid" << "bounds" << "reverse" << "exterior_ring"
|
3170 | 3225 | << "boundary" << "line_merge"
|
3171 | 3226 | << "bounds_width" << "bounds_height" << "is_closed" << "convex_hull" << "difference"
|
@@ -3377,6 +3432,12 @@ const QList<QgsExpression::Function*>& QgsExpression::Functions()
|
3377 | 3432 | << new StaticFunction( "boundary", ParameterList() << Parameter( "geometry" ), fcnBoundary, "GeometryGroup" )
|
3378 | 3433 | << new StaticFunction( "line_merge", ParameterList() << Parameter( "geometry" ), fcnLineMerge, "GeometryGroup" )
|
3379 | 3434 | << new StaticFunction( "bounds", 1, fcnBounds, "GeometryGroup" )
|
| 3435 | + << new StaticFunction( "simplify", ParameterList() << Parameter( "geometry" ) << Parameter( "tolerance" ), fcnSimplify, "GeometryGroup" ) |
| 3436 | + << new StaticFunction( "simplify_vw", ParameterList() << Parameter( "geometry" ) << Parameter( "tolerance" ), fcnSimplifyVW, "GeometryGroup" ) |
| 3437 | + << new StaticFunction( "smooth", ParameterList() << Parameter( "geometry" ) << Parameter( "iterations", true, 1 ) |
| 3438 | + << Parameter( "offset", true, 0.25 ) |
| 3439 | + << Parameter( "min_length", true, -1 ) |
| 3440 | + << Parameter( "max_angle", true, 180 ), fcnSmooth, "GeometryGroup" ) |
3380 | 3441 | << new StaticFunction( "num_points", 1, fcnGeomNumPoints, "GeometryGroup" )
|
3381 | 3442 | << new StaticFunction( "num_interior_rings", 1, fcnGeomNumInteriorRings, "GeometryGroup" )
|
3382 | 3443 | << new StaticFunction( "num_rings", 1, fcnGeomNumRings, "GeometryGroup" )
|
|
0 commit comments