Skip to content

Commit

Permalink
Add alias support for expression functions
Browse files Browse the repository at this point in the history
Standardise naming of all internal functions to lowercase with
underscore convention. Add aliases for old names to avoid
breakage.
  • Loading branch information
nyalldawson committed May 3, 2015
1 parent bb64830 commit bd9e02b
Show file tree
Hide file tree
Showing 29 changed files with 198 additions and 128 deletions.
9 changes: 8 additions & 1 deletion python/core/qgsexpression.sip
Expand Up @@ -202,6 +202,13 @@ class QgsExpression
/** Does this function use a geometry object. */
bool usesgeometry();

/** Returns a list of possible aliases for the function. These include
* other permissible names for the function, eg deprecated names.
* @return list of known aliases
* @note added in QGIS 2.9
*/
virtual QStringList aliases() const;

/** True if this function should use lazy evaluation. Lazy evaluation functions take QgsExpression::Node objects
* rather than the node results when called. You can use node->eval(parent, feature) to evaluate the node and return the result
* Functions are non lazy default and will be given the node return value when called **/
Expand Down Expand Up @@ -231,7 +238,7 @@ class QgsExpression
static bool isFunctionName( QString name );

// return index of the function in Functions array
static int functionIndex( QString name );
static int functionIndex( const QString& name );

/** Returns the number of functions defined in the parser
* @return The number of function defined in the parser.
Expand Down
13 changes: 0 additions & 13 deletions resources/function_help/bbox

This file was deleted.

@@ -1,12 +1,12 @@
<h3>convexHull function</h3>
<h3>convex_hull function</h3>
Returns the convex hull of a geometry. It represents the minimum convex geometry that encloses all geometries within the set.

<h4>Syntax</h4>
<pre>convexHull( a, b )</pre>
<pre>convex_hull( a, b )</pre>

<h4>Arguments</h4>
a &rarr; geometry
a &rarr; geometry

<h4>Example</h4>
<pre> geomToWKT( convexHull( geomFromWKT( 'LINESTRING(3 3 , 4 4 , 4 10)' )) ) &rarr; returns POLYGON((3 3,4 10,4 4,3 3)) </pre>
<pre> geom_to_wkt( convex_hull( geom_from_wkt( 'LINESTRING(3 3 , 4 4 , 4 10)' )) ) &rarr; returns POLYGON((3 3,4 10,4 4,3 3)) </pre>
12 changes: 0 additions & 12 deletions resources/function_help/geomFromGML

This file was deleted.

12 changes: 12 additions & 0 deletions resources/function_help/geom_from_gml
@@ -0,0 +1,12 @@
<h3>geom_from_gml function</h3>
Returns a geometry from a GML representation of geometry

<h4>Syntax</h4>
<pre>geom_from_gml(text)</pre>

<h4>Arguments</h4>
text &rarr; GML representation of a geometry

<h4>Example</h4>
<pre> geom_from_gml( '<gml:LineString srsName="EPSG:4326"><gml:coordinates>4,4 5,5 6,6</gml:coordinates></gml:LineString>') &rarr; returns a geometry</pre>

@@ -1,12 +1,12 @@
<h3>geomFromWKT function</h3>
<h3>geom_from_wkt function</h3>
Returns a geometry created from a Well-Known Text (WKT) representation.

<h4>Syntax</h4>
<pre>geomFromWKT(text)</pre>
<pre>geom_from_wkt(text)</pre>

<h4>Arguments</h4>
text &rarr; Well-Known Text (WKT) representation of a geometry

<h4>Example</h4>
<pre> geomFromWKT( 'POINT(4 5)' ) &rarr; returns a geometry</pre>
<pre> geom_from_wkt( 'POINT(4 5)' ) &rarr; returns a geometry</pre>

@@ -1,11 +1,11 @@
<h3>geomToWKT function</h3>
<h3>geom_to_wkt function</h3>
Returns the Well-Known Text (WKT) representation of the geometry without SRID metadata.

<h4>Syntax</h4>
<pre>geomToWKT(a)</pre>
<pre>geom_to_wkt(a)</pre>

<h4>Arguments</h4>
a &rarr; geometry

<h4>Example</h4>
<pre> geomToWKT( $geometry ) &rarr; POINT(6 50)</pre>
<pre> geom_to_wkt( $geometry ) &rarr; POINT(6 50)</pre>
@@ -1,6 +1,6 @@
<h3>getFeature function</h3>
<h3>get_feature function</h3>
Returns the first feature of a layer matching a given attribute value

<h4>Syntax</h4>
<pre>getFeature( layer, attributeField, value )</pre>
<pre>get_feature( layer, attributeField, value )</pre>

13 changes: 13 additions & 0 deletions resources/function_help/intersects_bbox
@@ -0,0 +1,13 @@
<h3>intersects_bbox function</h3>
Returns 1 if the geometries spatially intersect the bounding box defined and 0 if they don't.

<h4>Syntax</h4>
<pre>intersects_bbox( a, b )</pre>

<h4>Arguments</h4>
a &rarr; geometry
b &rarr; geometry

<h4>Example</h4>
<pre>intersects_bbox( geomFromWKT( 'POINT(4 5)' ) , geom_from_wkt( 'LINESTRING(3 3 , 4 4 , 5 5)' )) &rarr; returns 1</pre>
<pre>intersects_bbox( geomFromWKT( 'POINT(6 5)' ) , geom_from_wkt( 'POLYGON((3 3 , 4 4 , 5 5, 3 3))' )) &rarr; returns 0</pre>
12 changes: 0 additions & 12 deletions resources/function_help/symDifference

This file was deleted.

12 changes: 12 additions & 0 deletions resources/function_help/sym_difference
@@ -0,0 +1,12 @@
<h3>sym_difference function</h3>
Returns a geometry that represents the portions of a and b that do not intersect.

<h4>Syntax</h4>
<pre>sym_difference( geometry a, geometry b)</pre>

<h4>Arguments</h4>
geometry &rarr; geometry
geometry &rarr; geometry

<h4>Example</h4>
<pre> geom_to_wkt( sym_difference( geom_from_wkt( 'LINESTRING(3 3 , 4 4 , 5 5)' ) , geom_from_wkt( 'LINESTRING(3 3 , 8 8)' )) ) &rarr; returns LINESTRING(5 5, 8 8)</pre>
@@ -1,13 +1,13 @@
<h3>todate() function</h3>
<h3>to_date() function</h3>
Convert a string into Qt data type.

<h4>Syntax</h4>
<code>todate('string')</code><br>
<code>to_date('string')</code><br>

<h4>Arguments</h4>
<code>string</code> - is string in Qt date format.
<br>

<h4>Example</h4>
<!-- Show example of function.-->
<code>todate('2012-05-04') &rarr; 2012-05-04</code><br>
<code>to_date('2012-05-04') &rarr; 2012-05-04</code><br>
@@ -1,13 +1,13 @@
<h3>todatetime() function</h3>
<h3>to_datetime() function</h3>
Convert a string into Qt data time type.

<h4>Syntax</h4>
<code>todatetime('string')</code><br>
<code>to_datetime('string')</code><br>

<h4>Arguments</h4>
<code>string</code> - is string in Qt date time format.
<br>

<h4>Example</h4>
<!-- Show example of function.-->
<code>todatetime('2012-05-04 12:50:00') &rarr; 2012-05-04T12:50:00</code><br>
<code>to_datetime('2012-05-04 12:50:00') &rarr; 2012-05-04T12:50:00</code><br>
@@ -1,13 +1,13 @@
<h3>toint() function</h3>
<h3>to_int() function</h3>
Converts a string to integer number. Nothing changed if a value cannot be converted to integer (e.g '123asd' is invalid).

<p><h4>Syntax</h4>
toint(<i>string</i>)</p>
to_int(<i>string</i>)</p>

<p><h4>Arguments</h4>
<!-- List args for functions here-->
<i> string</i> &rarr; is string. The String to convert to integer number.</p>

<p><h4>Example</h4>
<!-- Show example of function.-->
toint('123') &rarr; 123</p>
to_int('123') &rarr; 123</p>
@@ -1,13 +1,13 @@
<h3>tointerval() function</h3>
<h3>to_interval() function</h3>
Converts a string to a interval type. Can be used to take days, hours, month, etc off a date.

<h4>Syntax</h4>
<code>tointerval('string')</code><br>
<code>to_interval('string')</code><br>

<h4>Arguments</h4>
<code>string</code> - is string. Format {n} days {n} hours {n} months
<br>

<h4>Example</h4>
<!-- Show example of function.-->
<code>todatetime('2012-05-05 12:00:00') - tointerval('1 day 2 hours') &rarr; 2012-05-04T10:00:00</code><br>
<code>todatetime('2012-05-05 12:00:00') - to_interval('1 day 2 hours') &rarr; 2012-05-04T10:00:00</code><br>
@@ -1,13 +1,13 @@
<h3>toreal() function</h3>
<h3>to_real() function</h3>
Converts a string to real number. Nothing changed if a value cannot be converted to real (e.g '123.56asd' is invalid). Numbers are rounded after saving changes if the precision is smaller than the result of the conversion.

<p><h4>Syntax</h4>
toreal(<i>string</i>)</p>
to_real(<i>string</i>)</p>

<p><h4>Arguments</h4>
<!-- List args for functions here-->
<i> string</i> &rarr; is string. The String to convert to real number.</p>

<p><h4>Example</h4>
<!-- Show example of function.-->
toreal('123.45') &rarr; 123.45</p>
to_real('123.45') &rarr; 123.45</p>
@@ -1,13 +1,13 @@
<h3>tostring() function</h3>
<h3>to_string() function</h3>
Converts a number to string.

<p><h4>Syntax</h4>
tostring(<i>number</i>)</p>
to_string(<i>number</i>)</p>

<p><h4>Arguments</h4>
<!-- List args for functions here-->
<i>number</i> &rarr; is integer or real. The number to convert to string.</p>

<p><h4>Example</h4>
<!-- Show example of function.-->
tostring(123) &rarr; '123'</p>
to_string(123) &rarr; '123'</p>
@@ -1,13 +1,13 @@
<h3>totime() function</h3>
<h3>to_time() function</h3>
Convert a string into Qt time type.

<h4>Syntax</h4>
<code>totime('string')</code><br>
<code>to_time('string')</code><br>

<h4>Arguments</h4>
<code>string</code> - is string in Qt time format.
<br>

<h4>Example</h4>
<!-- Show example of function.-->
<code>totime('12:30:01') &rarr; 12:30:01</code><br>
<code>to_time('12:30:01') &rarr; 12:30:01</code><br>
6 changes: 3 additions & 3 deletions resources/function_help/xat → resources/function_help/x_at
@@ -1,11 +1,11 @@
<h3>xat() function</h3>
<h3>x_at() function</h3>
Retrieves a x coordinate of the current feature

<h4>Syntax</h4>
<code>xat(i)</code>
<code>x_at(i)</code>

<h4>Arguments</h4>
<code>i<code> - is int. index of point of a line (indices start at 0; negative values apply to the last index).

<h4>Example</h4>
<pre>xat(1) &rarr; 5</pre>
<pre>x_at(1) &rarr; 5</pre>
@@ -1,12 +1,12 @@
<h3>xmax function</h3>
<h3>x_max function</h3>
Returns the maximum x coordinate of a geometry. Calculations are in the Spatial Reference System of this Geometry.

<h4>Syntax</h4>
<pre>xmax(geom)</pre>
<pre>x_max(geom)</pre>

<h4>Arguments</h4>
geom &rarr; a geometry

<h4>Example</h4>
<pre> xmax($geometry) &rarr; returns maximum x coordinate of $geometry</pre>
<pre> x_max($geometry) &rarr; returns maximum x coordinate of $geometry</pre>

@@ -1,12 +1,12 @@
<h3>xmin function</h3>
<h3>x_min function</h3>
Returns the minimum x coordinate of a geometry. Calculations are in the Spatial Reference System of this Geometry.

<h4>Syntax</h4>
<pre>xmin(geom)</pre>
<pre>x_min(geom)</pre>

<h4>Arguments</h4>
geom &rarr; a geometry

<h4>Example</h4>
<pre> xmin($geometry) &rarr; returns minimum x coordinate of $geometry</pre>
<pre> x_min($geometry) &rarr; returns minimum x coordinate of $geometry</pre>

6 changes: 3 additions & 3 deletions resources/function_help/yat → resources/function_help/y_at
@@ -1,11 +1,11 @@
<h3>yat() function</h3>
<h3>y_at() function</h3>
Retrieves a y coordinate of the current feature

<h4>Syntax</h4>
<code>yat(i)</code>
<code>y_at(i)</code>

<h4>Arguments</h4>
<code>i<code> - is int. index of point of a line (indices start at 0; negative values apply to the last index).

<h4>Example</h4>
<pre>yat(1) &rarr; 5</pre>
<pre>y_at(1) &rarr; 5</pre>
@@ -1,12 +1,12 @@
<h3>ymax function</h3>
<h3>y_max function</h3>
Returns the maximum y coordinate of a geometry. Calculations are in the Spatial Reference System of this Geometry.

<h4>Syntax</h4>
<pre>ymax(geom)</pre>
<pre>y_max(geom)</pre>

<h4>Arguments</h4>
geom &rarr; a geometry

<h4>Example</h4>
<pre> ymax($geometry) &rarr; returns maximum y coordinate of $geometry</pre>
<pre> y_max($geometry) &rarr; returns maximum y coordinate of $geometry</pre>

@@ -1,12 +1,12 @@
<h3>ymin function</h3>
<h3>y_min function</h3>
Returns the minimum y coordinate of a geometry. Calculations are in the Spatial Reference System of this Geometry.

<h4>Syntax</h4>
<pre>ymin(geom)</pre>
<pre>y_min(geom)</pre>

<h4>Arguments</h4>
geom &rarr; a geometry

<h4>Example</h4>
<pre> ymin($geometry) &rarr; returns minimum y coordinate of $geometry</pre>
<pre> y_min($geometry) &rarr; returns minimum y coordinate of $geometry</pre>

0 comments on commit bd9e02b

Please sign in to comment.