@@ -757,6 +757,37 @@ static QVariant fcnYat( const QVariantList& values, QgsFeature* f, QgsExpression
757
757
else
758
758
return QVariant ();
759
759
}
760
+ static QVariant fcnGeometry ( const QVariantList& , QgsFeature* f, QgsExpression* )
761
+ {
762
+ QgsGeometry* geom = f->geometry ();
763
+ if ( geom )
764
+ return QVariant::fromValue ( geom );
765
+ else
766
+ return QVariant ();
767
+ }
768
+ static QVariant fcnGeomFromWKT ( const QVariantList& values, QgsFeature*, QgsExpression* parent )
769
+ {
770
+ QString wkt = getStringValue ( values.at ( 0 ), parent );
771
+ QgsGeometry* geom = QgsGeometry::fromWkt ( wkt );
772
+ if ( geom )
773
+ return QVariant::fromValue ( geom );
774
+ else
775
+ return QVariant ();
776
+ }
777
+ static QVariant fcnGeomFromGML2 ( const QVariantList& values, QgsFeature*, QgsExpression* parent )
778
+ {
779
+ QDomDocument doc;
780
+ QString errorMsg;
781
+ QString gml = getStringValue ( values.at ( 0 ), parent );
782
+ if ( !doc.setContent ( gml, true , &errorMsg ) )
783
+ return QVariant ();
784
+
785
+ QgsGeometry* geom = QgsGeometry::fromGML2 ( doc.documentElement () );
786
+ if ( geom )
787
+ return QVariant::fromValue ( geom );
788
+ else
789
+ return QVariant ();
790
+ }
760
791
761
792
static QVariant fcnGeomArea ( const QVariantList& , QgsFeature* f, QgsExpression* parent )
762
793
{
@@ -932,6 +963,9 @@ const QList<QgsExpression::Function*> &QgsExpression::Functions()
932
963
<< new StaticFunction ( " $perimeter" , 0 , fcnGeomPerimeter, QObject::tr ( " Geometry" ), " " , true )
933
964
<< new StaticFunction ( " $x" , 0 , fcnX, QObject::tr ( " Geometry" ), " " , true )
934
965
<< new StaticFunction ( " $y" , 0 , fcnY, QObject::tr ( " Geometry" ), " " , true )
966
+ << new StaticFunction ( " $geometry" , 0 , fcnGeometry, QObject::tr ( " Geometry" ), " " , true )
967
+ << new StaticFunction ( " GeomFromWKT" , 1 , fcnGeomFromWKT, QObject::tr ( " Geometry" ) )
968
+ << new StaticFunction ( " GeomFromGML2" , 1 , fcnGeomFromGML2, QObject::tr ( " Geometry" ) )
935
969
<< new StaticFunction ( " $rownum" , 0 , fcnRowNumber, QObject::tr ( " Record" ) )
936
970
<< new StaticFunction ( " $id" , 0 , fcnFeatureId, QObject::tr ( " Record" ) )
937
971
<< new StaticFunction ( " $scale" , 0 , fcnScale, QObject::tr ( " Record" ) )
0 commit comments