@@ -1087,6 +1087,56 @@ static QVariant fcnGeomPerimeter( const QVariantList& , const QgsFeature* f, Qgs
10871087 return QVariant ( calc->measurePerimeter ( f->geometry () ) );
10881088}
10891089
1090+ static QVariant fcnBounds ( const QVariantList& values, const QgsFeature* , QgsExpression* parent )
1091+ {
1092+ QgsGeometry geom = getGeometry ( values.at ( 0 ), parent );
1093+ QgsGeometry* geomBounds = QgsGeometry::fromRect ( geom.boundingBox () );
1094+ if ( geomBounds )
1095+ {
1096+ return QVariant::fromValue ( *geomBounds );
1097+ }
1098+ else
1099+ {
1100+ return QVariant ();
1101+ }
1102+ }
1103+
1104+ static QVariant fcnBoundsWidth ( const QVariantList& values, const QgsFeature* , QgsExpression* parent )
1105+ {
1106+ QgsGeometry geom = getGeometry ( values.at ( 0 ), parent );
1107+ return QVariant::fromValue ( geom.boundingBox ().width () );
1108+ }
1109+
1110+ static QVariant fcnBoundsHeight ( const QVariantList& values, const QgsFeature* , QgsExpression* parent )
1111+ {
1112+ QgsGeometry geom = getGeometry ( values.at ( 0 ), parent );
1113+ return QVariant::fromValue ( geom.boundingBox ().height () );
1114+ }
1115+
1116+ static QVariant fcnXMin ( const QVariantList& values, const QgsFeature* , QgsExpression* parent )
1117+ {
1118+ QgsGeometry geom = getGeometry ( values.at ( 0 ), parent );
1119+ return QVariant::fromValue ( geom.boundingBox ().xMinimum () );
1120+ }
1121+
1122+ static QVariant fcnXMax ( const QVariantList& values, const QgsFeature* , QgsExpression* parent )
1123+ {
1124+ QgsGeometry geom = getGeometry ( values.at ( 0 ), parent );
1125+ return QVariant::fromValue ( geom.boundingBox ().xMaximum () );
1126+ }
1127+
1128+ static QVariant fcnYMin ( const QVariantList& values, const QgsFeature* , QgsExpression* parent )
1129+ {
1130+ QgsGeometry geom = getGeometry ( values.at ( 0 ), parent );
1131+ return QVariant::fromValue ( geom.boundingBox ().yMinimum () );
1132+ }
1133+
1134+ static QVariant fcnYMax ( const QVariantList& values, const QgsFeature* , QgsExpression* parent )
1135+ {
1136+ QgsGeometry geom = getGeometry ( values.at ( 0 ), parent );
1137+ return QVariant::fromValue ( geom.boundingBox ().yMaximum () );
1138+ }
1139+
10901140static QVariant fcnBbox ( const QVariantList& values, const QgsFeature* , QgsExpression* parent )
10911141{
10921142 QgsGeometry fGeom = getGeometry ( values.at ( 0 ), parent );
@@ -1574,14 +1624,18 @@ const QList<QgsExpression::Function*> &QgsExpression::Functions()
15741624 << new StaticFunction ( " color_hsva" , 4 , fncColorHsva, " Color" )
15751625 << new StaticFunction ( " color_cmyk" , 4 , fcnColorCmyk, " Color" )
15761626 << new StaticFunction ( " color_cmyka" , 5 , fncColorCmyka, " Color" )
1577- << new StaticFunction ( " xat" , 1 , fcnXat, " Geometry" , " " , true )
1578- << new StaticFunction ( " yat" , 1 , fcnYat, " Geometry" , " " , true )
1627+ << new StaticFunction ( " $geometry" , 0 , fcnGeometry, " Geometry" , " " , true )
15791628 << new StaticFunction ( " $area" , 0 , fcnGeomArea, " Geometry" , " " , true )
15801629 << new StaticFunction ( " $length" , 0 , fcnGeomLength, " Geometry" , " " , true )
15811630 << new StaticFunction ( " $perimeter" , 0 , fcnGeomPerimeter, " Geometry" , " " , true )
15821631 << new StaticFunction ( " $x" , 0 , fcnX, " Geometry" , " " , true )
15831632 << new StaticFunction ( " $y" , 0 , fcnY, " Geometry" , " " , true )
1584- << new StaticFunction ( " $geometry" , 0 , fcnGeometry, " Geometry" , " " , true )
1633+ << new StaticFunction ( " xat" , 1 , fcnXat, " Geometry" , " " , true )
1634+ << new StaticFunction ( " yat" , 1 , fcnYat, " Geometry" , " " , true )
1635+ << new StaticFunction ( " xmin" , 1 , fcnXMin, " Geometry" , " " , true )
1636+ << new StaticFunction ( " xmax" , 1 , fcnXMax, " Geometry" , " " , true )
1637+ << new StaticFunction ( " ymin" , 1 , fcnYMin, " Geometry" , " " , true )
1638+ << new StaticFunction ( " ymax" , 1 , fcnYMax, " Geometry" , " " , true )
15851639 << new StaticFunction ( " geomFromWKT" , 1 , fcnGeomFromWKT, " Geometry" )
15861640 << new StaticFunction ( " geomFromGML" , 1 , fcnGeomFromGML, " Geometry" )
15871641 << new StaticFunction ( " bbox" , 2 , fcnBbox, " Geometry" )
@@ -1594,6 +1648,9 @@ const QList<QgsExpression::Function*> &QgsExpression::Functions()
15941648 << new StaticFunction ( " within" , 2 , fcnWithin, " Geometry" )
15951649 << new StaticFunction ( " buffer" , -1 , fcnBuffer, " Geometry" )
15961650 << new StaticFunction ( " centroid" , 1 , fcnCentroid, " Geometry" )
1651+ << new StaticFunction ( " bounds" , 1 , fcnBounds, " Geometry" , " " , true )
1652+ << new StaticFunction ( " bounds_width" , 1 , fcnBoundsWidth, " Geometry" , " " , true )
1653+ << new StaticFunction ( " bounds_height" , 1 , fcnBoundsHeight, " Geometry" , " " , true )
15971654 << new StaticFunction ( " convexHull" , 1 , fcnConvexHull, " Geometry" )
15981655 << new StaticFunction ( " difference" , 2 , fcnDifference, " Geometry" )
15991656 << new StaticFunction ( " distance" , 2 , fcnDistance, " Geometry" )
0 commit comments