qgis/Quantum-GIS — pull request #317 by NathanW2 (2012-11-05 11:21:35+00:00)
Title: [FEATURE] Add ability to create user defined Python (and C++) expression functions

Adds the ability add user defined functions to QgsExpression.

Example function:

```python
from qgis.utils import qgsfunction
from qgis.core import QGis

@qgsfunction(0, "Python")
def vertices(values, feature, parent):
"""
Returns the number of vertices for a features geometry
"""
vertices = None
geom = feature.geometry()
if geom is None: return None
if geom.type() == QGis.Polygon:
vertices = 0
if geom.isMultipart():
polygons = geom.asMultiPolygon()
else:
polygons = [ geom.asPolygon() ]
for polygon in polygons:
for ring in polygon:
vertices += len(ring)
return vertices
```

will give you the ability to do:

```
QgsExpression('$vertices')
```