Skip to content

Commit 2b31660

Browse files
committed
First test with Qvariant QgsGeometry*
1 parent 4ca2160 commit 2b31660

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

src/core/qgsexpression.cpp

+34
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,37 @@ static QVariant fcnYat( const QVariantList& values, QgsFeature* f, QgsExpression
757757
else
758758
return QVariant();
759759
}
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+
}
760791

761792
static QVariant fcnGeomArea( const QVariantList& , QgsFeature* f, QgsExpression* parent )
762793
{
@@ -932,6 +963,9 @@ const QList<QgsExpression::Function*> &QgsExpression::Functions()
932963
<< new StaticFunction( "$perimeter", 0, fcnGeomPerimeter, QObject::tr( "Geometry" ), "", true )
933964
<< new StaticFunction( "$x", 0, fcnX, QObject::tr( "Geometry" ), "", true )
934965
<< 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" ) )
935969
<< new StaticFunction( "$rownum", 0, fcnRowNumber, QObject::tr( "Record" ) )
936970
<< new StaticFunction( "$id", 0, fcnFeatureId, QObject::tr( "Record" ) )
937971
<< new StaticFunction( "$scale", 0, fcnScale, QObject::tr( "Record" ) )

src/core/qgsexpression.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ class CORE_EXPORT QgsExpression
434434
{
435435
public:
436436
NodeSpatialOperator( SpatialOperator op, QgsGeometry* opGeom ) : mOp( op ), mOpGeometry( 0 ) { if ( opGeom ) mOpGeometry = opGeom; }
437-
~NodeSpatialOperator() { delete mOpGeometry; }
437+
~NodeSpatialOperator() { }
438438

439439
virtual bool prepare( QgsExpression* parent, const QgsFieldMap& fields );
440440
virtual QVariant eval( QgsExpression* parent, QgsFeature* f );
@@ -630,6 +630,7 @@ class CORE_EXPORT QgsExpression
630630
QgsDistanceArea* mCalc;
631631
};
632632

633-
Q_DECLARE_METATYPE( QgsExpression::Interval )
633+
Q_DECLARE_METATYPE( QgsExpression::Interval );
634+
Q_DECLARE_METATYPE( QgsGeometry * );
634635

635636
#endif // QGSEXPRESSION_H

0 commit comments

Comments
 (0)