@@ -1258,6 +1258,40 @@ static QVariant fcnGeomY( const QVariantList& values, const QgsExpressionContext
1258
1258
return result;
1259
1259
}
1260
1260
1261
+ static QVariant fcnGeomZ ( const QVariantList& values, const QgsExpressionContext*, QgsExpression* parent )
1262
+ {
1263
+ QgsGeometry geom = getGeometry ( values.at ( 0 ), parent );
1264
+ if ( geom.isEmpty () )
1265
+ return QVariant (); // or 0?
1266
+
1267
+ // if single point, return the point's z coordinate
1268
+ if ( geom.type () == QGis::Point && !geom.isMultipart () )
1269
+ {
1270
+ QgsPointV2* point = dynamic_cast < QgsPointV2* >( geom.geometry () );
1271
+ if ( point )
1272
+ return point->z ();
1273
+ }
1274
+
1275
+ return QVariant ();
1276
+ }
1277
+
1278
+ static QVariant fcnGeomM ( const QVariantList& values, const QgsExpressionContext*, QgsExpression* parent )
1279
+ {
1280
+ QgsGeometry geom = getGeometry ( values.at ( 0 ), parent );
1281
+ if ( geom.isEmpty () )
1282
+ return QVariant (); // or 0?
1283
+
1284
+ // if single point, return the point's m value
1285
+ if ( geom.type () == QGis::Point && !geom.isMultipart () )
1286
+ {
1287
+ QgsPointV2* point = dynamic_cast < QgsPointV2* >( geom.geometry () );
1288
+ if ( point )
1289
+ return point->m ();
1290
+ }
1291
+
1292
+ return QVariant ();
1293
+ }
1294
+
1261
1295
static QVariant fcnPointN ( const QVariantList& values, const QgsExpressionContext*, QgsExpression* parent )
1262
1296
{
1263
1297
QgsGeometry geom = getGeometry ( values.at ( 0 ), parent );
@@ -1314,10 +1348,35 @@ static QVariant fcnEndPoint( const QVariantList& values, const QgsExpressionCont
1314
1348
}
1315
1349
1316
1350
static QVariant fcnMakePoint ( const QVariantList& values, const QgsExpressionContext*, QgsExpression* parent )
1351
+ {
1352
+ if ( values.count () < 2 || values.count () > 4 )
1353
+ {
1354
+ parent->setEvalErrorString ( QObject::tr ( " Function make_point requires 2-4 arguments" ) );
1355
+ return QVariant ();
1356
+ }
1357
+
1358
+ double x = getDoubleValue ( values.at ( 0 ), parent );
1359
+ double y = getDoubleValue ( values.at ( 1 ), parent );
1360
+ double z = values.count () >= 3 ? getDoubleValue ( values.at ( 2 ), parent ) : 0.0 ;
1361
+ double m = values.count () >= 4 ? getDoubleValue ( values.at ( 3 ), parent ) : 0.0 ;
1362
+ switch ( values.count () )
1363
+ {
1364
+ case 2 :
1365
+ return QVariant::fromValue ( QgsGeometry ( new QgsPointV2 ( x, y ) ) );
1366
+ case 3 :
1367
+ return QVariant::fromValue ( QgsGeometry ( new QgsPointV2 ( QgsWKBTypes::PointZ, x, y, z ) ) );
1368
+ case 4 :
1369
+ return QVariant::fromValue ( QgsGeometry ( new QgsPointV2 ( QgsWKBTypes::PointZM, x, y, z, m ) ) );
1370
+ }
1371
+ return QVariant (); // avoid warning
1372
+ }
1373
+
1374
+ static QVariant fcnMakePointM ( const QVariantList& values, const QgsExpressionContext*, QgsExpression* parent )
1317
1375
{
1318
1376
double x = getDoubleValue ( values.at ( 0 ), parent );
1319
1377
double y = getDoubleValue ( values.at ( 1 ), parent );
1320
- return QVariant::fromValue ( QgsGeometry ( new QgsPointV2 ( x, y ) ) );
1378
+ double m = getDoubleValue ( values.at ( 2 ), parent );
1379
+ return QVariant::fromValue ( QgsGeometry ( new QgsPointV2 ( QgsWKBTypes::PointM, x, y, 0.0 , m ) ) );
1321
1380
}
1322
1381
1323
1382
static QVariant pointAt ( const QVariantList& values, const QgsExpressionContext* context, QgsExpression* parent ) // helper function
@@ -2034,7 +2093,7 @@ static QVariant fcnGetFeature( const QVariantList& values, const QgsExpressionCo
2034
2093
const QVariant& attVal = values.at ( 2 );
2035
2094
QgsFeatureRequest req;
2036
2095
req.setFilterExpression ( QString ( " %1=%2" ).arg ( QgsExpression::quotedColumnRef ( attribute ),
2037
- QgsExpression::quotedString ( attVal.toString () ) ) );
2096
+ QgsExpression::quotedString ( attVal.toString () ) ) );
2038
2097
if ( !parent->needsGeometry () )
2039
2098
{
2040
2099
req.setFlags ( QgsFeatureRequest::NoGeometry );
@@ -2192,8 +2251,8 @@ const QStringList& QgsExpression::BuiltinFunctions()
2192
2251
<< " color_hsl" << " color_hsla" << " color_hsv" << " color_hsva"
2193
2252
<< " color_cmyk" << " color_cmyka" << " color_part" << " set_color_part"
2194
2253
<< " xat" << " yat" << " $area" << " area" << " perimeter"
2195
- << " $length" << " $perimeter" << " x" << " y" << " $x" << " $y" << " num_points"
2196
- << " point_n" << " start_point" << " end_point" << " make_point"
2254
+ << " $length" << " $perimeter" << " x" << " y" << " $x" << " $y" << " z " << " m " << " num_points"
2255
+ << " point_n" << " start_point" << " end_point" << " make_point" << " make_point_m "
2197
2256
<< " $x_at" << " x_at" << " xat" << " $y_at" << " y_at" << " yat" << " x_min" << " xmin" << " x_max" << " xmax"
2198
2257
<< " y_min" << " ymin" << " y_max" << " ymax" << " geom_from_wkt" << " geomFromWKT"
2199
2258
<< " geom_from_gml" << " geomFromGML" << " intersects_bbox" << " bbox"
@@ -2308,10 +2367,13 @@ const QList<QgsExpression::Function*>& QgsExpression::Functions()
2308
2367
<< new StaticFunction ( " $y" , 0 , fcnY, " GeometryGroup" , QString (), true )
2309
2368
<< new StaticFunction ( " x" , 1 , fcnGeomX, " GeometryGroup" )
2310
2369
<< new StaticFunction ( " y" , 1 , fcnGeomY, " GeometryGroup" )
2370
+ << new StaticFunction ( " z" , 1 , fcnGeomZ, " GeometryGroup" )
2371
+ << new StaticFunction ( " m" , 1 , fcnGeomM, " GeometryGroup" )
2311
2372
<< new StaticFunction ( " point_n" , 2 , fcnPointN, " GeometryGroup" )
2312
2373
<< new StaticFunction ( " start_point" , 1 , fcnStartPoint, " GeometryGroup" )
2313
2374
<< new StaticFunction ( " end_point" , 1 , fcnEndPoint, " GeometryGroup" )
2314
- << new StaticFunction ( " make_point" , 2 , fcnMakePoint, " GeometryGroup" )
2375
+ << new StaticFunction ( " make_point" , -1 , fcnMakePoint, " GeometryGroup" )
2376
+ << new StaticFunction ( " make_point_m" , 3 , fcnMakePointM, " GeometryGroup" )
2315
2377
<< new StaticFunction ( " $x_at" , 1 , fcnXat, " GeometryGroup" , QString (), true , QStringList (), false , QStringList () << " xat" << " x_at" )
2316
2378
<< new StaticFunction ( " $y_at" , 1 , fcnYat, " GeometryGroup" , QString (), true , QStringList (), false , QStringList () << " yat" << " y_at" )
2317
2379
<< new StaticFunction ( " x_min" , 1 , fcnXMin, " GeometryGroup" , QString (), false , QStringList (), false , QStringList () << " xmin" )
0 commit comments