[Users Guide : Constraint Query Language (refractions.net)](http://udig.refractions.net/confluence/display/EN/Constraint Query Language.html)
Constraint Query Language
The Constraint Query Language is used to define expressions and filters in several parts of the uDig application.
The CQL syntax is defined as part of the OGC Catalog specification (in much the same way the well-known-text representation of geometry is defined as part of the Simple Feature for SQL specification).
Filters
A Filters is used to test content, similar in spirit to a WHERE statement in SQL. Filters are used to define the selected Features in a uDig layer.
Comparisons
1 2 3 4CITY = 'Nelson' ATTR1 < (1 + ((2 / 3) * 4)) ATTR1 < abs(ATTR2) ATTR1 < 10 AND ATTR2 < 2 OR ATTR3 > 10Text
1 2ATTR1 LIKE 'abc%' ATTR1 NOT LIKE 'abc%'Null
1 2ATTR1 IS NULL ATTR1 IS NOT NULLExists
1 2ATTR1 EXISTS ATTR1 DOES-NOT-EXISTBetween
1ATTR1 BETWEEN 10 AND 20Spatial Relationships
1 2 3 4 5 6CONTAINS(ATTR1, POINT(1 2)) CROSS(ATTR1, LINESTRING(1 2, 10 15)) INTERSECT(ATTR1, GEOMETRYCOLLECTION (POINT (10 10),POINT (30 30),LINESTRING (15 15, 20 20)) ) BBOX(ATTR1, 10,20,30,40) DWITHIN(ATTR1, POINT(1 2), 10, kilometers) BBOX(ATTR1, 10,20,30,40)Time
Before a date.
1ATTR1 BEFORE 2006-11-30T01:30:00ZBefore a period
1ATTR1 BEFORE 2006-11-30T01:30:00Z/2006-12-31T01:30:00ZAfter a date.
1ATTR1 AFTER 2006-11-30T01:30:00ZAfter a period
1ATTR1 AFTER 2006-11-30T01:30:00Z/2006-12-31T01:30:00ZTemporal predicate with dutation (ten day after 2006-11-30T01:30:00Z )
1 2ATTR1 AFTER 2006-11-30T01:30:00Z/P10D ATTR1 AFTER 2006-11-30T01:30:00Z/T10HDuring predicate
1ATTR1 DURING 2006-11-30T01:30:00Z/2006-12-31T01:30:00ZCompound Attributes
1gmd:MD_Metadata.gmd:identificationInfo.gmd:MD_DataIdentification.gmd:abstract LIKE 'abc%'Expressions
Expressions are used to extract a value similar in spirit to a SELECT statement in SQL. Unlike SQL expressions are strictly untyped; the following produces the same result:
- sin( 0 )
- sin( 0.0 )
- sin( ‘0’ )
In many cases you will see several functions defined with similar names; differing only in how they interpret the provided argument expressions. The functions functions that produce a boolean value are very similar to a filter.
Literals
1 2 3 41 3.14159 'abc' 2006-11-30T01:30:00ZGeometry
Geometry literals are provided in Well Known Text format:
1 2POINT(1 2) LINESTRING (15 15, 20 20)This is the same format used by PostGIS and other applications.
Attribute
1 2NAME prefix:nameMath
1 2 31 + 1 1 + 2 * 3 (1 + 2) * 3Functions
1 2 3 4 5sin( pi() / 4 ) sin( toRadians( ANGLE ) ) getX( pointN( THE_GEOM, 0 ) ) area( THE_GEOM ) ID()Function List:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118double Area(Geometry) // alternate implementation double area(Geometry) long abs( number ) // number treated as long double abs_2( number ) // number treated as double float abs_3( number ) // number treated as float int abs_4( number ) // number treated as int double acos( cos ) double asin( sin ) double atan( tan ) double atan2( x, y ) // convert x, y to theta boolean between( value, min, max ) boundary(Geometry) boundaryDimension(Geometry) buffer(Geometry, double) bufferWithSegments(Geometry, double, int) double ceil( number ) centroid(Geometry) contains(Geometry, Geometry) convexHull(Geometry) double cos( radians ) crosses(Geometry, Geometry) difference(Geometry, Geometry) dimension(Geometry) disjoint(Geometry, Geometry) distance(Geometry, Geometry) double2bool(double) endPoint(Geometry) envelope(Geometry) equalsExact(Geometry, Geometry) equalsExactTolerance(Geometry, Geometry, double) equalTo(Object, Object) double exp( number ) exteriorRing(Geometry) double floor( number ) String geometryType(Geometry) Geometry geomFromWKT(String) double geomLength(Geometry) Geometry getGeometryN(Geometry, int) double getX( Point ) double getY( Point ) boolean greaterEqualThan(Object, Object) boolean greaterThan(Object, Object) double IEEEremainder( dividend, divisor ) value if_then_else(boolean, value, value ) in2(value, Object, Object) // tests to is if value is equal to one of the listed objects in3(value, Object, Object, Object) in4(value, Object, Object, Object, Object) in5(value, Object, Object, Object, Object, Object) in6(value, Object, Object, Object, Object, Object, Object) in7(value, Object, Object, Object, Object, Object, Object, Object) in8(value, Object, Object, Object, Object, Object, Object, Object, Object) in9(value, Object, Object, Object, Object, Object, Object, Object, Object, Object) in10(value, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object) boolean int2bbool(int) double int2ddouble(int) Point interiorPoint(Geometry) LinearRing interiorRingN(Geometry, int) Geometry intersection(Geometry, Geometry) boolean intersects(Geometry, Geometry) boolean isClosed(Geometry) boolean isEmpty(Geometry) isLike(String, String) isNull(Object) isRing(Geometry) isSimple(Geometry) isValid(Geometry) isWithinDistance(Geometry, Geometry, double) lessEqualThan(Object, Object) lessThan(Object, Object) double log( number ) double max( number, number ) float max_2( number, number ) int max_3( number, number ) long max_4( number, number ) double min( number, number ) float min_2( number, number ) int min_3( number, number ) long min_4( number, number ) not(boolean) notEqualTo(Object, Object) numGeometries(Geometry) numInteriorRing(Geometry) numPoints(Geometry) overlaps(Geometry, Geometry) parseBoolean(String) parseDouble(String) parseInt(String) pointN(Geometry, int) double pow( base, exponent ) double random() String relate(Geometry, Geometry) boolean relatePattern(Geometry, Geometry, String) double rint( number ) // closest integer int round( number ) long round_2( number ) int roundDouble( number ) // number is treated as a double double sin( radians ) double sqrt( number ) startPoint(Geometry) strConcat(String, String) strEndsWith(String, String) strEqualsIgnoreCase(String, String) strIndexOf(String, String) strLastIndexOf(String, String) strLength(String) strMatches(String, String) strStartsWith(String, String) strSubstring(String, int, int) strSubstringStart(String, int) strTrim(String) symDifference(Geometry, Geometry) double tan( radians ) touches(Geometry, Geometry) double toDegrees( radians ) double toRadians( degrees ) String toWKT(Geometry) union(Geometry, Geometry) within(Geometry, Geometry)Extended CQL
The common query language cannot quite do everything we would like it to. The following extensions are not strictly common query language (so please do not expect them to work with other applications).
Feature ID
You can select against a feature identifier using:
1IN ('river.1', 'river.2')Or if you have an integer type as feature id:
1IN (300, 301)
[Selection using CQL](http://udig.refractions.net/confluence/display/EN/Selection using CQL.html)
[Table view](http://udig.refractions.net/confluence/display/EN/Table view.html)
Reshape Operation