Tygron Query Language: Difference between revisions

From Tygron Preview Support Wiki
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
 
(246 intermediate revisions by 9 users not shown)
Line 1: Line 1:
{{stub}}
TQL is short for Tygron Query Language. It provides a means of obtaining and adjusting data of a [[session]]. It is comprised of a number of key phrases, that can be divided into 2 categories: statements and clauses. The statements indicate what data interaction should take place; retrieving using a [[Select (TQL)|<code>SELECT</code>]] statement, or adjusting using an [[Update (TQL)|<code>UPDATE</code>]] statement. The clauses provide a means to filter the data the interaction is applied to. A query always consists of exactly 1 statement and 0 or more clauses. Each clause always consists of a [[Clause (TQL)|Clause parameter]] and a value.


==Queries==
TQL can access both property data from individual items, as well as spatial information. Property data pertains to a specific component of a [[project]], such as individual [[building]]s, [[indicator]]s, or [[global]]s. Polygon data pertains to geographic data; surface areas in the [[project area]], such as the lot size of [[building]]s, the surface area of [[neighborhood]]s, or calculated [[grid overlay|grid]]s. Depending on what kind of statement is used, the query will interact with its clauses treating them as items or as polygons.


===Land polygons===
An example of a TQL query is:
{| class="wikitable"
: <code>SELECT_LOTSIZE_WHERE_CATEGORY_IS_SOCIAL_AND_STAKEHOLDERTYPE_IS_MUNICIPALITY</code>.  
|-
! Query
! Value returned
! Clauses for specific query
! Clauses for entire group
|-
| LANDSIZE
| Amount of surface area.
|
* {{inlink|Grids}}
|rowspan="2"|
* {{inlink|Specific polygons}}
* {{inlink|Attribute polygons}}
* {{inlink|Stakeholder}}
* {{inlink|Map types}}
|-
| DIKES
| The amount of surface area taken up by dikes.
|
* {{inlink|Dikes}}
* {{inlink|Timestate}}
|}


===Construction polygons===
{| class="wikitable"
|-
! Query
! Value returned
! Clauses for specific query
! Clauses for entire group
|-
| LOTSIZE
| Amount of surface area used by a [[construction]].
|
|rowspan="4"|
* {{inlink|Specific polygons}}
* {{inlink|Attribute polygons}}
* {{inlink|Grids}}
* {{inlink|Constructions}}
* {{inlink|Dikes}}
* {{inlink|Building categories}}
* {{inlink|Timestates}}
* {{inlink|Attributes}}
* {{inlink|Stakeholders}}
* {{inlink|Relations}}
* {{inlink|Layer Types}}
* {{inlink|Map types}}
* {{inlink|Multipliers}}
|-
| FLOORSIZE
| The amount of floorsize, based on constructions' lotsize and their amount of floors.
|
|-
| UNITS
| The amount of housing units, based on construction's lotsize and their unit size.
|
|-
| LOTPOLYGONS
| Whether something meats the criteria (1) or not (0). When used in a panel and the panel is opened, the polygon is highlighted.
|
|}


===Grid values===
In this example, <code>SELECT_LOTSIZE</code> is the statement. <code>CATEGORY_IS_SOCIAL</code> is the first clause, and <code>STAKEHOLDERTYPE_IS_MUNICIPALITY</code> is the second clause. It would return all the land area taken up with social housing, which is also owned by a municipal stakeholder.
{| class="wikitable"
|-
! Query
! Value returned
! Clauses for specific query
! Clauses for entire group
|-
| GRIDAVG
| The average value of a [[grid overlay|grid]].
|
|rowspan="3"|
* {{inlink|Specific polygons}}
* {{inlink|Attribute polygons}}
* {{inlink|Grids}} (Without the value clauses)
* {{inlink|Map types}}
|-
| GRIDSTDEV
| The standard deviation of a grid.
|
|-
| GRIDSVOLUME
| The surface area multiplied by the average grid value on that surface.
|
|}


==Clauses==
Note that all clauses in a TQL query are cumulative. All clauses are connected by the term <code>AND</code>. This means all clauses must be met before the data is "counted". Depending on how you use TQL in your project or applications, it is possible to simulate an "OR" functionality as well (e.g. <code>CATEGORY_IS_SOCIAL</code> ''or'' <code>CATEGORY_IS_NORMAL</code>). This can be done simply by executing multiple queries, one for each "OR" section.
The following groups of clauses exist:


===Main clause groups===
More examples can be found at [[TQL Examples]].


====Specific polygons====
==TQL components==
{| class="wikitable"
TQL queries are composed of 2 major elements: the [[#Statements|statement]], and the [[Clause (TQL)|clauses]]. Together they may make up a single query.
|-
! Clause
! As a polygon
! As an item
! Type
|-
| AREA
| It must intersect with this [[area]].
| It must be data of this area specifically.
| ID indicating a specific area.
|-
| NEIGHBORHOOD
| It must intersect with this [[neighborhood]].
| It must be data of this neighborhood specifically.
| ID indicating a specific neighborhood.
|-
| ZONE
| It must intersect with this [[zone]].
| It must be data of this zone specifically.
| ID indicating a specific zone.
|-
| TERRAIN
| It must intersect with this [[terrain]] type.
| It must be data of this type of terrain. There are no specific "instances" of terrain.
| ID indicating a type of terrain.
|}


====Attribute polygons====
===Statements===
{| class="wikitable"
Statements are the instruction which is to be performed with the [[Project]]. A query always has exactly one statement.  
|-
! Clause
! As a polygon
! As an item
! Type
|-
| AREA_WITH_ATTRIBUTE
| It must intersect with at least one [[area]] with this attribute.
| N/A
| Attribute name of one or more areas.
|-
| NEIGHBORHOOD_WITH_ATTRIBUTE
| It must intersect with at least one [[neighborhood]] with this attribute.
| N/A
| Attribute name of one or more neighborhoods.
|-
| ZONE_WITH_ATTRIBUTE
| It must intersect with at least one [[zone]] with this attribute.
| N/A
| Attribute name of one or more zones.
|-
| TERRAIN_WITH_ATTRIBUTE
| It must intersect with [[terrain]] with this attribute.
| N/A
| Attribute name of one or more terrains.
|}


====Grids====
There are 2 kinds of [[TQL]] Statements:
{| class="wikitable"
* [[Select (TQL)|Select statement]]s, for data retrieval from [[Item]]s in a [[Project]]
|-
* [[Update (TQL)|Update statement]]s, for writing data (back) into the [[Project]] and its [[Item]]s
! Clause
! As a polygon
! As an item
! Type
|-
| MAXGRIDVALUE
| It must intersect with at least this value on a [[grid overlay]].
| N/A
| Decimal number.
|-
| MINGRIDVALUE
| It must intersect with at most this value on a grid overlay.
| N/A
| Decimal number.
|-
| GRID
| It must fall within this grid.
| It must be data of this grid overlay specifically.
| ID indicating a specific zone.
|-
| GRIDTYPE
| It must fall within this type of grid.
| It must be data of this type of grid, not a specific "instance" of this grid.
| Technical name indicating a type of grid overlay.
|}


Note that each grid automatically covers the entire map, unless a minimum gridvalue or maximum gridvalue is defined. For queries such as GRIDAVG, this can be acceptable. However, for example, a query of SELECT_LANDSIZE_WHERE_GRID_IS_2 is functionally the same as SELECT_LANDSIZE.
===Clauses===
{{main|Clause (TQL)}}
Clauses indicate the conditions which must be met for any data to be taken into account for a statement. In a query, they are connected to the statement using the phrase <code>WHERE</code>. Multiple additional clauses can be added to a query using the phrase <code>AND</code>. Clauses added to a query are cumulative conditions which must all be met. When, for any data, at least one condition is not met, that data is not taken into account or affected by the query.


Also note that when a GRIDTYPE is selected but multiple [[overlays]] of that type exist in the [[project]], there are no guarantees on which overlay is used specifically.
For any given [[Select (TQL)]] or [[Update (TQL)]] statement, different clauses can be applied from across all these groups. The availability and function of clauses is also influenced by whether the statement dictates an interaction with polygon data or with item data. Some clauses may or may not be available at all, depending on this.


====Constructions====
The order in which the clauses appear in the query is not relevant.
{| class="wikitable"
|-
! Clause
! As a polygon
! As an item
! Type
|-
| BUILDING
| It must intersect with this [[construction]].
| It must be data of this construction specifically.
| ID indicating a specific construction.
|-
| NET_LOAD
| It must intersect with the building of this [[net load]].
| It must be data of this net load specifically.
| ID indicating a specific net load.
|-
| NET_CLUSTER
| It must intersect with buildings of [[net load]]s of this [[net cluster]].
| It must be data of this net cluster specifically.
| ID indicating a specific net cluster.
|-
| FUNCTION
| It must intersect with constructions of this [[function]].
| It must be data related to this function type.
| ID indicating a specific function.
|}


====Dikes====
For a full list of available clauses, see [[Clause (TQL)]].
{| class="wikitable"
|-
! Clause
! As a polygon
! As an item
! Type
|-
| DIKE
| It must intersect with this [[dike]].
| It must be data of this dike specifically.
| ID indicating a specific dike.
|}


====Building categories====
====Limiting Search Polygon====
{| class="wikitable"
Some clause parameters described on this wiki note that they ''Limit the Search Polygon''. The Search Polygon is the geometry created from the specified clauses that will limit the buildings that will be considered when executing the statement. For example <code>SELECT_LOTSIZE_WHERE_AREA_WITH_ATTRIBUTE_SPECIAL_CASE_AND_CATEGORY_IS_SOCIAL</code> will create a search polygon for buildings based on the areas that have the attribute <code>SPECIAL_CASE</code>. The [[Area with attribute (TQL Param)]] is a search polygon limiter.
|-
! Clause
! As a polygon
! As an item
! Type
|-
| CATEGORY
| It must intersect with [[constructions]] of this [[category]].
| It must be related to this specific category.
| Technical name indicating a category.
|}


====Timestates====
It will also have effect when executing the statement: <code>SELECT_LANDSIZE_WHERE_NEIGHBORHOOD_IS_2_AND_AREA_WITH_ATTRIBUTE_SPECIAL_CASE</code>, where together with the [[Neighborhood (TQL Param)]] they limit the search polygon to the intersection of the Neighborhood with Item ID 2 and areas with an attribute <code>SPECIAL_CASE</code>. Ultimately, the statement returns the landsize of the limiting search polygon.
{| class="wikitable"
|-
! Clause
! As a polygon
! As an item
! Type
|-
| STATE
| It must intersect with buildings or other spatial actions, which are currently in this [[timestate]].
| It must be related to this specific timestate
| Technical name indicating a timestate.
|}


====Attributes====
==Usage==
{| class="wikitable"
TQL can be used in a number of places. The most common place is in the [[excel]]s of custom [[indicator]]s, [[panel]] or [[global]]s. To indicate which cells should contain certain data from the [[session]], cells in an excel file can be given a name. In this case, the name would be a TQL query. When an indicator calculation takes place, the {{software}} will obtain all queries that exist in the excel file of the indicator. For the queries with <code>SELECT</code> statements, the results of those queries are obtained and placed in the corresponding cells. when the calculation of the excel is complete, the cells with an <code>UPDATE</code> statement are read out, and the items in the project indicated by those queries are updated with those values.
|-
! Clause
! As a polygon
! As an item
! Type
|-
| ATTRIBUTE_MAX
| It must intersect with at least this value of an [[attribute]].
| N/A
| Decimal number.
|-
| ATTRIBUTE_MIN
| It must intersect with at most this value of an [[attribute]].
| N/A
| Decimal number.
|-
| ATTRIBUTE
| The attribute of which to test the value.  
| N/A
| Attribute name of any polygonal item.
|}
When neither a maximum or minimum value is specified, or when no attribute is specified, everything is considered


====Networks====
TQL can also be used to quickly check data in a project. When in [[editor]] mode, it's possible to open the [[query tool]]. With this tool, queries can be made and directly executed. The result is then presented to the [[user]]. This can be especially handy when it's necessary to quickly check whether a certain type of data is present or correctly readable. The query tool also functions both in and out of [[Test Run|test runs]], allowing a user to also check data in a [[project]] during a session.
{| class="wikitable"
|-
! Clause
! As a polygon
! As an item
! Type
|-
| NET_LINE
| N/A
| It must be data of this [[net line]] specifically.
| ID indicating a specific net line.
|-
| NET_LINE_DEFINITION
| N/A
| It must be data of [[net line]]s of this [[net line definition|definition]].
| ID indicating a line definition.
|-
| NET_TYPE
| N/A
| It must be data of [[net line]]s of this type of [[net type|network]].
| ID indicating the type of network.
|}


====Stakeholders====
It's also possible to execute TQL queries directly via the [[API]]. The advantage of using TQL, rather than inspecting a project's data via the API directly, is that it can be used to perform calculations that require some intermediate processing. For example, calculating the intersection of buildings with an area or neighborhood. Other examples of this include the queries related to values of [[grid overlay|grid]]s, or the multiplication of floor size with a related [[function values | function value]].
{| class="wikitable"
|-
! Clause
! As a polygon
! As an item
! Type
|-
| STAKEHOLDER
| The land must be owned by this specific [[stakeholder]].
| It must be data of this stakeholder specifically.
| ID indicating a specific stakeholder.
|-
| STAKEHOLDERTYPE
| The land must be owned by this type of stakeholder.
| N/A
| Technical name indicating a type of stakeholder.
|}


====Interface====
{{article end
{| class="wikitable"
|seealso=
|-
* [[Excel indicator]]s, [[Panel]]s and [[Global]]s
! Clause
* [[Select (TQL)]], [[Update (TQL)]] and [[Clause (TQL)]]
! As a polygon
* [[Query tool]]
! As an item
|howtos=
! Type
* [[How to use buffers (TQL)]]
|-
* [[TQL Examples]]
| INDICATOR
|videos=
| N/A
{{video|link=https://youtu.be/6D29CclkWQ4|description=Information about Residents and Energylabels in the {{software}}.|language=dutch}}
| It must be data of this [[indicator]] specifically.
}}
| ID indicating a specific indicator.
|-
| OVERLAY
| N/A
| It must be data of this [[overlay]] specifically.
| ID indicating a specific overlay.
|-
| PANEL
| N/A
| It must be data of this [[panel]] specifically.
| ID indicating a specific panel.
|}


===Minor clause groups===


====Variables====
{{TQL nav}}
{| class="wikitable"
|-
! Clause
! As a polygon
! As an item
! Type
|-
| NAME
| N/A
| The data requested must have this name.
| The name which identifies the requested data.
|}
 
====Indicators====
{| class="wikitable"
|-
! Clause
! As a polygon
! As an item
! Type
|-
| INDICATORTYPE
| N/A
| It must be related to this type of [[indicator]].
| Technical name indicating a type of indicator.
|}
 
====Terms====
{| class="wikitable"
|-
! Clause
! As a polygon
! As an item
! Type
|-
| STATE
| N/A
| It must be related to this specific text (or "term") used by the Engine.
| Technical name indicating a term.
|}
 
 
===Modifying clause groups===
 
====Map types====
{| class="wikitable"
|-
! Clause
! As a polygon
! As an item
! Type
|-
| MAP
| It must be data from this [[maptype|moment of time]] in a [[session]].
| It must be data from this moment of time in a session.
| Technical name of the original/current state or the planned/maquette state.
|}
The precise terms vary based on the simulation type, but the terms which appear in the query are CURRENT and MAQUETTE.
 
====Layer types====
{| class="wikitable"
|-
! Clause
! As a polygon
! As an item
! Type
|-
| LAYERTYPE
| It must be data from this layer of the [[3D world]].
| N/A
| Technical name of the surface or underground layers of the 3D world.
|}
The precise terms are SURFACE and UNDERGROUND.
 
====Multipliers====
{| class="wikitable"
|-
! Clause
! As a polygon
! As an item
! Type
|-
| ATTRIBUTE_MULT
| Multiply the result by the (spatial) value of an attribute.
| N/A
| Attribute name of any polygonal item.
|-
| FUNCTIONMULT
| Multiply the result by the (spatial) value of an attribute.
| N/A
| The name of a [[function value]].
|-
| CATEGORYMULT
| Multiply the result by the (spatial) value of an attribute.
| N/A
| The name of a [[category value]].
|}
 
====Relations====
{| class="wikitable"
|-
! Clause
! As a polygon
! As an item
! Type
|-
| RELATION
| N/A
| Rather than data of the specified item, use the item which has this relation to it.
| Technical name indicating a type of relation.
|}

Latest revision as of 08:43, 5 September 2024

TQL is short for Tygron Query Language. It provides a means of obtaining and adjusting data of a session. It is comprised of a number of key phrases, that can be divided into 2 categories: statements and clauses. The statements indicate what data interaction should take place; retrieving using a SELECT statement, or adjusting using an UPDATE statement. The clauses provide a means to filter the data the interaction is applied to. A query always consists of exactly 1 statement and 0 or more clauses. Each clause always consists of a Clause parameter and a value.

TQL can access both property data from individual items, as well as spatial information. Property data pertains to a specific component of a project, such as individual buildings, indicators, or globals. Polygon data pertains to geographic data; surface areas in the project area, such as the lot size of buildings, the surface area of neighborhoods, or calculated grids. Depending on what kind of statement is used, the query will interact with its clauses treating them as items or as polygons.

An example of a TQL query is:

SELECT_LOTSIZE_WHERE_CATEGORY_IS_SOCIAL_AND_STAKEHOLDERTYPE_IS_MUNICIPALITY.


In this example, SELECT_LOTSIZE is the statement. CATEGORY_IS_SOCIAL is the first clause, and STAKEHOLDERTYPE_IS_MUNICIPALITY is the second clause. It would return all the land area taken up with social housing, which is also owned by a municipal stakeholder.

Note that all clauses in a TQL query are cumulative. All clauses are connected by the term AND. This means all clauses must be met before the data is "counted". Depending on how you use TQL in your project or applications, it is possible to simulate an "OR" functionality as well (e.g. CATEGORY_IS_SOCIAL or CATEGORY_IS_NORMAL). This can be done simply by executing multiple queries, one for each "OR" section.

More examples can be found at TQL Examples.

TQL components

TQL queries are composed of 2 major elements: the statement, and the clauses. Together they may make up a single query.

Statements

Statements are the instruction which is to be performed with the Project. A query always has exactly one statement.

There are 2 kinds of TQL Statements:

Clauses

Main article: Clause (TQL)

Clauses indicate the conditions which must be met for any data to be taken into account for a statement. In a query, they are connected to the statement using the phrase WHERE. Multiple additional clauses can be added to a query using the phrase AND. Clauses added to a query are cumulative conditions which must all be met. When, for any data, at least one condition is not met, that data is not taken into account or affected by the query.

For any given Select (TQL) or Update (TQL) statement, different clauses can be applied from across all these groups. The availability and function of clauses is also influenced by whether the statement dictates an interaction with polygon data or with item data. Some clauses may or may not be available at all, depending on this.

The order in which the clauses appear in the query is not relevant.

For a full list of available clauses, see Clause (TQL).

Limiting Search Polygon

Some clause parameters described on this wiki note that they Limit the Search Polygon. The Search Polygon is the geometry created from the specified clauses that will limit the buildings that will be considered when executing the statement. For example SELECT_LOTSIZE_WHERE_AREA_WITH_ATTRIBUTE_SPECIAL_CASE_AND_CATEGORY_IS_SOCIAL will create a search polygon for buildings based on the areas that have the attribute SPECIAL_CASE. The Area with attribute (TQL Param) is a search polygon limiter.

It will also have effect when executing the statement: SELECT_LANDSIZE_WHERE_NEIGHBORHOOD_IS_2_AND_AREA_WITH_ATTRIBUTE_SPECIAL_CASE, where together with the Neighborhood (TQL Param) they limit the search polygon to the intersection of the Neighborhood with Item ID 2 and areas with an attribute SPECIAL_CASE. Ultimately, the statement returns the landsize of the limiting search polygon.

Usage

TQL can be used in a number of places. The most common place is in the excels of custom indicators, panel or globals. To indicate which cells should contain certain data from the session, cells in an excel file can be given a name. In this case, the name would be a TQL query. When an indicator calculation takes place, the Tygron Platform will obtain all queries that exist in the excel file of the indicator. For the queries with SELECT statements, the results of those queries are obtained and placed in the corresponding cells. when the calculation of the excel is complete, the cells with an UPDATE statement are read out, and the items in the project indicated by those queries are updated with those values.

TQL can also be used to quickly check data in a project. When in editor mode, it's possible to open the query tool. With this tool, queries can be made and directly executed. The result is then presented to the user. This can be especially handy when it's necessary to quickly check whether a certain type of data is present or correctly readable. The query tool also functions both in and out of test runs, allowing a user to also check data in a project during a session.

It's also possible to execute TQL queries directly via the API. The advantage of using TQL, rather than inspecting a project's data via the API directly, is that it can be used to perform calculations that require some intermediate processing. For example, calculating the intersection of buildings with an area or neighborhood. Other examples of this include the queries related to values of grids, or the multiplication of floor size with a related function value.

How-to's

Videos

Information about Residents and Energylabels in the Tygron Platform. (In dutch)

See also