Spatial Query Language Overview
Many of the inputs into Envision can include a spatial query that determines the spatial extent of the
phemonemna of interest. ENVISION includes a simple query language and built in query compiler that can be used to:
- Specify site attribute for policies, to indicate where in the landscape the policy may be applied,
- To run queries on the map to locate IDU’s matching specific attribute criteria, and
- To specify inputs into certain evaluative models and autonomous processes.
The syntax for this language is very straightforward and consists most fundamentally of
Field | operator | value triplets. These may be logically ‘and’ed or ‘or’ed
together and arbitrarily nested to create complex queries. Additionally, the
Query language supports several spatial operators to incorporate neighborhood information into the query.
Query Operators
The [Field | operator| value] triplets are the fundamental query elements and are defined as follows:
Complex queries can be constructed using the AND and OR operator to connect the field|operator| value triplets,
with optional nesting with parentheses. These operators are not case sensitive. Examples include:
- LULC_A=10 AND DIST_STR<100
- (LULC_A=20 and DIST_STR < 100) OR (LULC_A=30 and DIST_HWY>10)
Math Operators
Mathematical expression can be included in queries using the usual math operators as follows:
Operator | Definition | Applicable Types |
+ | Addition | Any numeric |
- | Subtraction | Any numeric |
/ | Division | Any numeric |
* | Multiplication | Any numeric |
% | Modulus (remainder) function | Any numeric |
Spatial Operators
In addition to basic field|operator|value triplets, several spatial operators can be incorporated into a query. These operators are:
Operator | Definition | Arguments | Example |
NextTo( query ) | Returns True if the IDU is adjacent to an IDU that satisfies the query argument | query: Any valid query | NextTo( LULC_A = 3 ) |
NextToArea( query ) | Returns the area of the region adjacent to an IDU that satisfies the query argument. The area returned is an extended area, meaning it finds all IDUs that define a continuous region around the target IDU, even if some of those IDU’s are not directly adjacent to the target IDU. | query: Any valid query | NextToArea( LULC_A=40 ) > 500 |
Within(query, distance) | Returns True is the IDU is within the specified distance of any IDU that satisfies the query argument | query: Any valid query distance: a numeric distance, in map units | Within( SLOPE < 10, 100 ) |
WithinArea (query,radius,percent) | Returns True if the percent area of IDU’s satisfying the query argument within the circle around the center of the IDU is greater than the specified percentage. | query: Any valid query radius: a numeric distance percent: the decimal percent threshold | WithinArea( DENS<100, 1000, 0.20)
This is true if within a radius of 1000 of the centroid of the IDU, the DENS value of the IDU areas falling within that radius is less than 100 for at least 20 percent of the area. |
These spatial operators can be combined into complex queries in a manner similar to the field|operator|value triplets, e.g.:
- LULC_A=10 and NextTo( LULC_A=30 )
Temporal Operators
The following temporal operators can be incorporated into a query:
Operator | Definition | Arguments | Example |
Time() | Returns the current value of teh simulated time. | None | Time() < LASTTIME |
Constants
One two constants are defined by the query language, TRUE (which evaluates to 1), and FALSE (which evaluates to 0).
These are not case sensitive, so TRUE, true, and TRue all evaluate the same way. These are generally useful for
comparing values returned from Boolean database fields.
Embedding Comments in Spatial Queries
Comments can be embedded in spatial queries to greatly improve readability and interpretability of the query string. Anything enclosed in
matched braces ( { } ) is considered a comment and ignored by the Query compiler. For example:
- LULC_A=10 {Agricultural Lands} is treated identically as LULC_A=10.