@@ -1655,6 +1655,17 @@ static QVariant fcnGeomZ( const QVariantList &values, const QgsExpressionContext
1655
1655
if ( point )
1656
1656
return point->z ();
1657
1657
}
1658
+ else if ( geom.type () == QgsWkbTypes::PointGeometry && geom.isMultipart () )
1659
+ {
1660
+ if ( const QgsGeometryCollection *collection = qgsgeometry_cast< const QgsGeometryCollection * >( geom.constGet () ) )
1661
+ {
1662
+ if ( collection->numGeometries () == 1 )
1663
+ {
1664
+ if ( const QgsPoint *point = qgsgeometry_cast< const QgsPoint * >( collection->geometryN ( 0 ) ) )
1665
+ return point->z ();
1666
+ }
1667
+ }
1668
+ }
1658
1669
1659
1670
return QVariant ();
1660
1671
}
@@ -1672,6 +1683,17 @@ static QVariant fcnGeomM( const QVariantList &values, const QgsExpressionContext
1672
1683
if ( point )
1673
1684
return point->m ();
1674
1685
}
1686
+ else if ( geom.type () == QgsWkbTypes::PointGeometry && geom.isMultipart () )
1687
+ {
1688
+ if ( const QgsGeometryCollection *collection = qgsgeometry_cast< const QgsGeometryCollection * >( geom.constGet () ) )
1689
+ {
1690
+ if ( collection->numGeometries () == 1 )
1691
+ {
1692
+ if ( const QgsPoint *point = qgsgeometry_cast< const QgsPoint * >( collection->geometryN ( 0 ) ) )
1693
+ return point->m ();
1694
+ }
1695
+ }
1696
+ }
1675
1697
1676
1698
return QVariant ();
1677
1699
}
@@ -1802,6 +1824,17 @@ static QVariant fcnInteriorRingN( const QVariantList &values, const QgsExpressio
1802
1824
return QVariant ();
1803
1825
1804
1826
const QgsCurvePolygon *curvePolygon = qgsgeometry_cast< const QgsCurvePolygon * >( geom.constGet () );
1827
+ if ( !curvePolygon && geom.isMultipart () )
1828
+ {
1829
+ if ( const QgsGeometryCollection *collection = qgsgeometry_cast< const QgsGeometryCollection * >( geom.constGet () ) )
1830
+ {
1831
+ if ( collection->numGeometries () == 1 )
1832
+ {
1833
+ curvePolygon = qgsgeometry_cast< const QgsCurvePolygon * >( collection->geometryN ( 0 ) );
1834
+ }
1835
+ }
1836
+ }
1837
+
1805
1838
if ( !curvePolygon )
1806
1839
return QVariant ();
1807
1840
@@ -1811,7 +1844,7 @@ static QVariant fcnInteriorRingN( const QVariantList &values, const QgsExpressio
1811
1844
if ( idx >= curvePolygon->numInteriorRings () || idx < 0 )
1812
1845
return QVariant ();
1813
1846
1814
- QgsCurve *curve = static_cast < QgsCurve * >( curvePolygon->interiorRing ( idx )->clone () );
1847
+ QgsCurve *curve = static_cast < QgsCurve * >( curvePolygon->interiorRing ( static_cast < int >( idx ) )->clone () );
1815
1848
QVariant result = curve ? QVariant::fromValue ( QgsGeometry ( curve ) ) : QVariant ();
1816
1849
return result;
1817
1850
}
@@ -1833,7 +1866,7 @@ static QVariant fcnGeometryN( const QVariantList &values, const QgsExpressionCon
1833
1866
if ( idx < 0 || idx >= collection->numGeometries () )
1834
1867
return QVariant ();
1835
1868
1836
- QgsAbstractGeometry *part = collection->geometryN ( idx )->clone ();
1869
+ QgsAbstractGeometry *part = collection->geometryN ( static_cast < int >( idx ) )->clone ();
1837
1870
QVariant result = part ? QVariant::fromValue ( QgsGeometry ( part ) ) : QVariant ();
1838
1871
return result;
1839
1872
}
@@ -1989,25 +2022,57 @@ static QVariant fcnMakePolygon( const QVariantList &values, const QgsExpressionC
1989
2022
}
1990
2023
1991
2024
QgsGeometry outerRing = QgsExpressionUtils::getGeometry ( values.at ( 0 ), parent );
1992
- if ( outerRing.type () != QgsWkbTypes::LineGeometry || outerRing.isMultipart () || outerRing. isNull () )
2025
+ if ( outerRing.type () != QgsWkbTypes::LineGeometry || outerRing.isNull () )
1993
2026
return QVariant ();
1994
2027
1995
- QgsPolygon *polygon = new QgsPolygon ();
1996
- polygon->setExteriorRing ( qgsgeometry_cast< QgsCurve * >( outerRing.constGet ()->clone () ) );
2028
+ std::unique_ptr< QgsPolygon > polygon = qgis::make_unique< QgsPolygon >();
2029
+
2030
+ const QgsCurve *exteriorRing = qgsgeometry_cast< QgsCurve * >( outerRing.constGet () );
2031
+ if ( !exteriorRing && outerRing.isMultipart () )
2032
+ {
2033
+ if ( const QgsGeometryCollection *collection = qgsgeometry_cast< const QgsGeometryCollection * >( outerRing.constGet () ) )
2034
+ {
2035
+ if ( collection->numGeometries () == 1 )
2036
+ {
2037
+ exteriorRing = qgsgeometry_cast< QgsCurve * >( collection->geometryN ( 0 ) );
2038
+ }
2039
+ }
2040
+ }
2041
+
2042
+ if ( !exteriorRing )
2043
+ return QVariant ();
2044
+
2045
+ polygon->setExteriorRing ( exteriorRing->segmentize () );
2046
+
1997
2047
1998
2048
for ( int i = 1 ; i < values.count (); ++i )
1999
2049
{
2000
2050
QgsGeometry ringGeom = QgsExpressionUtils::getGeometry ( values.at ( i ), parent );
2001
2051
if ( ringGeom.isNull () )
2002
2052
continue ;
2003
2053
2004
- if ( ringGeom.type () != QgsWkbTypes::LineGeometry || ringGeom.isMultipart () || ringGeom.isNull () )
2054
+ if ( ringGeom.type () != QgsWkbTypes::LineGeometry || ringGeom.isNull () )
2055
+ continue ;
2056
+
2057
+ const QgsCurve *ring = qgsgeometry_cast< QgsCurve * >( ringGeom.constGet () );
2058
+ if ( !ring && ringGeom.isMultipart () )
2059
+ {
2060
+ if ( const QgsGeometryCollection *collection = qgsgeometry_cast< const QgsGeometryCollection * >( ringGeom.constGet () ) )
2061
+ {
2062
+ if ( collection->numGeometries () == 1 )
2063
+ {
2064
+ ring = qgsgeometry_cast< QgsCurve * >( collection->geometryN ( 0 ) );
2065
+ }
2066
+ }
2067
+ }
2068
+
2069
+ if ( !ring )
2005
2070
continue ;
2006
2071
2007
- polygon->addInteriorRing ( qgsgeometry_cast< QgsCurve * >( ringGeom. constGet ()-> clone () ) );
2072
+ polygon->addInteriorRing ( ring-> segmentize ( ) );
2008
2073
}
2009
2074
2010
- return QVariant::fromValue ( QgsGeometry ( polygon ) );
2075
+ return QVariant::fromValue ( QgsGeometry ( std::move ( polygon ) ) );
2011
2076
}
2012
2077
2013
2078
static QVariant fcnMakeTriangle ( const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent, const QgsExpressionNodeFunction * )
@@ -2026,6 +2091,17 @@ static QVariant fcnMakeTriangle( const QVariantList &values, const QgsExpression
2026
2091
return QVariant ();
2027
2092
2028
2093
const QgsPoint *point = qgsgeometry_cast< const QgsPoint * >( geom.constGet () );
2094
+ if ( !point && geom.isMultipart () )
2095
+ {
2096
+ if ( const QgsGeometryCollection *collection = qgsgeometry_cast< const QgsGeometryCollection * >( geom.constGet () ) )
2097
+ {
2098
+ if ( collection->numGeometries () == 1 )
2099
+ {
2100
+ point = qgsgeometry_cast< const QgsPoint * >( collection->geometryN ( 0 ) );
2101
+ }
2102
+ }
2103
+ }
2104
+
2029
2105
if ( !point )
2030
2106
return QVariant ();
2031
2107
@@ -2055,6 +2131,19 @@ static QVariant fcnMakeCircle( const QVariantList &values, const QgsExpressionCo
2055
2131
return QVariant ();
2056
2132
}
2057
2133
const QgsPoint *point = qgsgeometry_cast< const QgsPoint * >( geom.constGet () );
2134
+ if ( !point && geom.isMultipart () )
2135
+ {
2136
+ if ( const QgsGeometryCollection *collection = qgsgeometry_cast< const QgsGeometryCollection * >( geom.constGet () ) )
2137
+ {
2138
+ if ( collection->numGeometries () == 1 )
2139
+ {
2140
+ point = qgsgeometry_cast< const QgsPoint * >( collection->geometryN ( 0 ) );
2141
+ }
2142
+ }
2143
+ }
2144
+ if ( !point )
2145
+ return QVariant ();
2146
+
2058
2147
QgsCircle circ ( *point, radius );
2059
2148
return QVariant::fromValue ( QgsGeometry ( circ.toPolygon ( segment ) ) );
2060
2149
}
@@ -2078,6 +2167,19 @@ static QVariant fcnMakeEllipse( const QVariantList &values, const QgsExpressionC
2078
2167
return QVariant ();
2079
2168
}
2080
2169
const QgsPoint *point = qgsgeometry_cast< const QgsPoint * >( geom.constGet () );
2170
+ if ( !point && geom.isMultipart () )
2171
+ {
2172
+ if ( const QgsGeometryCollection *collection = qgsgeometry_cast< const QgsGeometryCollection * >( geom.constGet () ) )
2173
+ {
2174
+ if ( collection->numGeometries () == 1 )
2175
+ {
2176
+ point = qgsgeometry_cast< const QgsPoint * >( collection->geometryN ( 0 ) );
2177
+ }
2178
+ }
2179
+ }
2180
+ if ( !point )
2181
+ return QVariant ();
2182
+
2081
2183
QgsEllipse elp ( *point, majorAxis, minorAxis, azimuth );
2082
2184
return QVariant::fromValue ( QgsGeometry ( elp.toPolygon ( segment ) ) );
2083
2185
}
@@ -2112,8 +2214,34 @@ static QVariant fcnMakeRegularPolygon( const QVariantList &values, const QgsExpr
2112
2214
parent->setEvalErrorString ( QObject::tr ( " Option can be 0 (inscribed) or 1 (circumscribed)" ) );
2113
2215
return QVariant ();
2114
2216
}
2217
+
2115
2218
const QgsPoint *center = qgsgeometry_cast< const QgsPoint * >( pt1.constGet () );
2219
+ if ( !center && pt1.isMultipart () )
2220
+ {
2221
+ if ( const QgsGeometryCollection *collection = qgsgeometry_cast< const QgsGeometryCollection * >( pt1.constGet () ) )
2222
+ {
2223
+ if ( collection->numGeometries () == 1 )
2224
+ {
2225
+ center = qgsgeometry_cast< const QgsPoint * >( collection->geometryN ( 0 ) );
2226
+ }
2227
+ }
2228
+ }
2229
+ if ( !center )
2230
+ return QVariant ();
2231
+
2116
2232
const QgsPoint *corner = qgsgeometry_cast< const QgsPoint * >( pt2.constGet () );
2233
+ if ( !corner && pt2.isMultipart () )
2234
+ {
2235
+ if ( const QgsGeometryCollection *collection = qgsgeometry_cast< const QgsGeometryCollection * >( pt2.constGet () ) )
2236
+ {
2237
+ if ( collection->numGeometries () == 1 )
2238
+ {
2239
+ corner = qgsgeometry_cast< const QgsPoint * >( collection->geometryN ( 0 ) );
2240
+ }
2241
+ }
2242
+ }
2243
+ if ( !corner )
2244
+ return QVariant ();
2117
2245
2118
2246
QgsRegularPolygon rp = QgsRegularPolygon ( *center, *corner, nbEdges, option );
2119
2247
@@ -2394,6 +2522,17 @@ static QVariant fcnIsClosed( const QVariantList &values, const QgsExpressionCont
2394
2522
return QVariant ();
2395
2523
2396
2524
const QgsCurve *curve = qgsgeometry_cast< const QgsCurve * >( fGeom .constGet () );
2525
+ if ( !curve && fGeom .isMultipart () )
2526
+ {
2527
+ if ( const QgsGeometryCollection *collection = qgsgeometry_cast< const QgsGeometryCollection * >( fGeom .constGet () ) )
2528
+ {
2529
+ if ( collection->numGeometries () == 1 )
2530
+ {
2531
+ curve = qgsgeometry_cast< const QgsCurve * >( collection->geometryN ( 0 ) );
2532
+ }
2533
+ }
2534
+ }
2535
+
2397
2536
if ( !curve )
2398
2537
return QVariant ();
2399
2538
@@ -2496,6 +2635,17 @@ static QVariant fcnWedgeBuffer( const QVariantList &values, const QgsExpressionC
2496
2635
{
2497
2636
QgsGeometry fGeom = QgsExpressionUtils::getGeometry ( values.at ( 0 ), parent );
2498
2637
const QgsPoint *pt = qgsgeometry_cast<const QgsPoint *>( fGeom .constGet () );
2638
+ if ( !pt && fGeom .isMultipart () )
2639
+ {
2640
+ if ( const QgsGeometryCollection *collection = qgsgeometry_cast< const QgsGeometryCollection * >( fGeom .constGet () ) )
2641
+ {
2642
+ if ( collection->numGeometries () == 1 )
2643
+ {
2644
+ pt = qgsgeometry_cast< const QgsPoint * >( collection->geometryN ( 0 ) );
2645
+ }
2646
+ }
2647
+ }
2648
+
2499
2649
if ( !pt )
2500
2650
{
2501
2651
parent->setEvalErrorString ( QObject::tr ( " Function `wedge_buffer` requires a point value for the center." ) );
@@ -2699,6 +2849,17 @@ static QVariant fcnExteriorRing( const QVariantList &values, const QgsExpression
2699
2849
return QVariant ();
2700
2850
2701
2851
const QgsCurvePolygon *curvePolygon = qgsgeometry_cast< const QgsCurvePolygon * >( fGeom .constGet () );
2852
+ if ( !curvePolygon && fGeom .isMultipart () )
2853
+ {
2854
+ if ( const QgsGeometryCollection *collection = qgsgeometry_cast< const QgsGeometryCollection * >( fGeom .constGet () ) )
2855
+ {
2856
+ if ( collection->numGeometries () == 1 )
2857
+ {
2858
+ curvePolygon = qgsgeometry_cast< const QgsCurvePolygon * >( collection->geometryN ( 0 ) );
2859
+ }
2860
+ }
2861
+ }
2862
+
2702
2863
if ( !curvePolygon || !curvePolygon->exteriorRing () )
2703
2864
return QVariant ();
2704
2865
@@ -2783,7 +2944,28 @@ static QVariant fcnAzimuth( const QVariantList &values, const QgsExpressionConte
2783
2944
QgsGeometry fGeom2 = QgsExpressionUtils::getGeometry ( values.at ( 1 ), parent );
2784
2945
2785
2946
const QgsPoint *pt1 = qgsgeometry_cast<const QgsPoint *>( fGeom1 .constGet () );
2947
+ if ( !pt1 && fGeom1 .isMultipart () )
2948
+ {
2949
+ if ( const QgsGeometryCollection *collection = qgsgeometry_cast< const QgsGeometryCollection * >( fGeom1 .constGet () ) )
2950
+ {
2951
+ if ( collection->numGeometries () == 1 )
2952
+ {
2953
+ pt1 = qgsgeometry_cast< const QgsPoint * >( collection->geometryN ( 0 ) );
2954
+ }
2955
+ }
2956
+ }
2957
+
2786
2958
const QgsPoint *pt2 = qgsgeometry_cast<const QgsPoint *>( fGeom2 .constGet () );
2959
+ if ( !pt2 && fGeom2 .isMultipart () )
2960
+ {
2961
+ if ( const QgsGeometryCollection *collection = qgsgeometry_cast< const QgsGeometryCollection * >( fGeom2 .constGet () ) )
2962
+ {
2963
+ if ( collection->numGeometries () == 1 )
2964
+ {
2965
+ pt2 = qgsgeometry_cast< const QgsPoint * >( collection->geometryN ( 0 ) );
2966
+ }
2967
+ }
2968
+ }
2787
2969
2788
2970
if ( !pt1 || !pt2 )
2789
2971
{
@@ -2866,7 +3048,27 @@ static QVariant fcnInclination( const QVariantList &values, const QgsExpressionC
2866
3048
QgsGeometry fGeom2 = QgsExpressionUtils::getGeometry ( values.at ( 1 ), parent );
2867
3049
2868
3050
const QgsPoint *pt1 = qgsgeometry_cast<const QgsPoint *>( fGeom1 .constGet () );
3051
+ if ( !pt1 && fGeom1 .isMultipart () )
3052
+ {
3053
+ if ( const QgsGeometryCollection *collection = qgsgeometry_cast< const QgsGeometryCollection * >( fGeom1 .constGet () ) )
3054
+ {
3055
+ if ( collection->numGeometries () == 1 )
3056
+ {
3057
+ pt1 = qgsgeometry_cast< const QgsPoint * >( collection->geometryN ( 0 ) );
3058
+ }
3059
+ }
3060
+ }
2869
3061
const QgsPoint *pt2 = qgsgeometry_cast<const QgsPoint *>( fGeom2 .constGet () );
3062
+ if ( !pt2 && fGeom2 .isMultipart () )
3063
+ {
3064
+ if ( const QgsGeometryCollection *collection = qgsgeometry_cast< const QgsGeometryCollection * >( fGeom2 .constGet () ) )
3065
+ {
3066
+ if ( collection->numGeometries () == 1 )
3067
+ {
3068
+ pt2 = qgsgeometry_cast< const QgsPoint * >( collection->geometryN ( 0 ) );
3069
+ }
3070
+ }
3071
+ }
2870
3072
2871
3073
if ( ( fGeom1 .type () != QgsWkbTypes::PointGeometry ) || ( fGeom2 .type () != QgsWkbTypes::PointGeometry ) ||
2872
3074
!pt1 || !pt2 )
0 commit comments