TQL Examples
A number of use-cases come up frequently across various projects. Queries of the following forms often provide a firm basis for using TQL to obtain required data.
Select Active
- Main article: Select active (TQL)
To query whether a Neighborhood with id 5 is active, returning 1 if active, 0 otherwise:
SELECT_ACTIVE_WHERE_NEIGHBORHOOD_IS_5To query whether each Neighborhood is active, returning an array of 0 and 1's:
SELECT_ACTIVE_WHERE_NEIGHBORHOOD_IS_XTo query whether an Indicator with id 8 is active, returning 1 if active, 0 otherwise:
SELECT_ACTIVE_WHERE_INDICATOR_IS_8To query whether an Scenario with id 0 is active, returning 1 if active, 0 otherwise:
SELECT_ACTIVE_WHERE_SCENARIO_IS_0To query whether a test-run or single/multi stakeholder session is active, returning 1 if active, 0 otherwise:
SELECT_ACTIVE_WHERE_SCENARIO_IS_ACTIVETo query whether a Heat Network is active, returning 1 if active, 0 otherwise:
SELECT_ACTIVE_WHERE_NET_TYPE_IS_HEATTo query whether an Overlay with ID 25 is active, returning 1 if active, 0 otherwise:
SELECT_ACTIVE_WHERE_OVERLAY_IS_25To query whether an Area with ID 4 is active, returning 1 if active, 0 otherwise:
SELECT_ACTIVE_WHERE_AREA_IS_4To query whether Areas with the Attribute DESTINATION are active, returning an array of 0 and 1's:
SELECT_ACTIVE_WHERE_AREA_IS_XA_DESTINATIONSelect Attribute
- Main article: Select attribute (TQL)
To query the value of the attribute INHABITANTS for the Neighborhood with ID 0, returning a decimal number:
SELECT_ATTRIBUTE_WHERE_NEIGHBORHOOD_IS_0_AND_NAME_IS_INHABITANTSTo query the value of the attribute FLOOR_SPACE_M2 for an Address with ID 415, returning a decimal number:
SELECT_ATTRIBUTE_WHERE_ADDRESS_IS_415_AND_NAME_IS_FLOOR_SPACE_M2To query the value of the attribute POWER for each Net Load of the HEAT Net Type, returning an array of decimal numbers:
SELECT_ATTRIBUTE_WHERE_NET_LOAD_IS_X_AND_NET_TYPE_IS_HEAT_AND_NAME_IS_POWERIn case an overlay with a particular Grid Type is not unique in your project, a Grid Overlay can alternatively be identified using the GRID_WITH_ATTRIBUTE clause. To query the value of the attribute TIMEFRAMES for a Grid Overlay that has the unique Attribute named SPECIAL_OVERLAY
SELECT_ATTRIBUTE_WHERE_GRID_WITH_ATTRIBUTE_IS_SPECIAL_OVERLAY_AND_NAME_IS_TIMEFRAMESTo query an attribute named PARAMETER_1 of the first Building of a Measure:
SELECT_ATTRIBUTE_WHERE_MEASURE_IS_5_AND_RELATION_IS_BUILDING_AND_NAME_IS_PARAMETER_1To query the Dates model attribute of a Heat Stress Overlay for each timeframe, return an array of decimal numbers:
SELECT_ATTRIBUTE_WHERE_GRIDTYPE_IS_HEAT_STRESS_AND_NAME_IS_DATES_AND_TIMEFRAME_IS_XAdvanced
Culverts are buildings that are identified using the key CULVERT_DIAMETER, configured for a Water Overlay, such as a Rainfall Overlay. To query each Culvert (Water Overlay) for the value of the attribute configured for the Rainfall Overlay Key OBJECT_FLOW_OUTPUT, returning an array of decimal numbers:
SELECT_ATTRIBUTE_WHERE_BUILDING_IS_XK_CULVERT_DIAMETER_AND_GRIDTYPE_IS_RAINFALL_AND_KEY_IS_OBJECT_FLOW_OUTPUTTo query the values of the Rain m attribute of the Weather configured for a Rainfall Overlay, returning an array of 100 decimal numbers:
SELECT_ATTRIBUTE_WHERE_NAME_IS_RAIN_M_AND_GRIDTYPE_IS_RAINFALL_AND_RELATION_IS_WEATHER_AND_INDEX_IS_XWeirs are buildings that are identified using the key WEIR_HEIGHT, configured for a Water Overlay, such as a Groundwater Overlay. To query the weight height of each Weirs covered by a Water Level Area, related to a Groundwater Overlay: (This query can only be applied by a Template Panel set up for Areas, hence the AREA_IS_ID clause)
SELECT_ATTRIBUTE_WHERE_KEY_IS_WEIR_HEIGHT_AND_GRIDTYPE_IS_GROUNDWATER_AND_BUILDING_IS_XCK_WEIR_HEIGHT_AND_AREA_IS_IDColor
- Main article: Select color (TQL)
To query the COLOR attribute of an Area with Item ID 5, returning the color in HEX Format:
SELECT_COLOR_WHERE_AREA_IS_5To query the color of a Stakeholder with Item ID 3, returning the color in HEX Format:
SELECT_COLOR_WHERE_STAKEHOLDER_IS_3To query the default color of a Stakeholder Type MUNICIPALITY, returning the color in HEX Format:
SELECT_COLOR_WHERE_STAKEHOLDERTYPE_IS_MUNICIPALITYExpenses
- Main article: Select expenses (TQL)
To query the total expenses made by a Stakeholder with Item ID 3, returning a decimal number:
SELECT_EXPENSES_WHERE_STAKEHOLDER_IS_3Revenue
- Main article: Select revenue (TQL)
To query the total revenue received by a Stakeholder with Item ID 4, returning a decimal number:
SELECT_EXPENSES_WHERE_STAKEHOLDER_IS_4Other
Function values (selecting)
Parking requirements of social housing
The parking demand is based on a function value of each function, and is defined as "parking places per m2". Parking demand is not based on the footprint of a building, but the size of a building. i.e. a building 4 floors high needs more parking than a building with the same footprint 2 floors high.
SELECT_FLOORSIZE_WHERE_CATEGORY_IS_SOCIAL_AND_CATEGORYMULT_IS_PARKING_LOTS_DEMAND_PER_M2
SELECT_FLOORSIZE: What we are basically looking for is the floorsize of the building.CATEGORY_IS_SOCIAL: We only want to look at buildings which are of the category social housing. For that, a category clause is added.CATEGORYMULT_IS_PARKING_LOTS_DEMAND_PER_M2: Lastly, we are not looking directly for the floorsize, but for the parking demand as a result of that floorsize.
Function values (updating)
Traffic intensity on roads
The traffic intensity is a function value which affects calculations related to traffic. Some use-cases require these values to be updated dynamically. This can be done per neighborhood. (In this example, the neighborhood in question has the ID 1.)
UPDATE_BUILDING_TRAFFIC_FLOW_WHERE_CATEGORY_IS_ROAD_AND_NEIGHBORHOOD_IS_1
UPDATE_BUILDING: We're changing an attribute of a building.TRAFFIC_FLOW: The attribute we are changing is the TRAFFIC_FLOW, which is the technical name of a function value.CATEGORY_IS_ROAD: We only want to update this value on roads.NEIGHBORHOOD_IS_1: We are updating only in this specific neighborhood. Nothing outside the neighborhood is updated by this statement.
Grid average
Quality of livability in a neighborhood
The livability overlay calculates, for each grid cell, the average livability. The best indication of how well a certain region performs in terms of livability would be to average these values out. That way, its possible to compare places which are not the same size. (In this example, the neighborhood in question has the ID 1, and the grid of livability has the ID 4.)
SELECT_GRIDAVG_WHERE_NEIGHBORHOOD_IS_1_AND_GRID_IS_4
For any given neighborhood, different points of a grid may score differently.
SELECT_GRIDAVG: We're looking for the average score across the entire neighborhood.NEIGHBORHOOD_IS_1: We don't need the average of the entire map, but only of a specific neighborhood.GRID_IS_4: We need to specify the grid we wish to use the values of.
Grid values
The area of open water which is flooded by more than 20 cm of water
The rainfall overlay calculates what amounts of water ends up where. The overlay's results are in meters. If we wish to provide some minimum value, it must be in meters as well. 20 cm is 0,2 meters. The project can also contain multiple types of water. All types of have one thing in common, namely that they all have the WATER attribute, which can be tested against. (In this example, the grid of inundation has the ID 4, and has its result type set to water stress.)
SELECT_LANDSIZE_WHERE_MINGRIDVALUE_IS_0.2_AND_GRID_IS_4_AND_TERRAIN_WITH_ATTRIBUTE_IS_WATER
SELECT_LANDSIZE: The end result must be some area; some amount of square meters.MINGRIDVALUE_IS_0.2: We only want to count the area where the value calculated is at least 0.2 (meters).GRID_IS_4: We need to specify the grid we wish to use the values of.TERRAIN_WITH_ATTRIBUTE_IS_WATER: We are only looking for the water which ends up on water, identified by the "WATER" attribute.
Buffers
The amount of green in or near a neighborhood
Green buildings can be found by their green function value. The value is the amount of green in square meters, per square meter of building. Green can be in a neighborhood, but can also be within a certain range near a neighborhood (say, 20 meters) and still have an effective presence.
SELECT_LOTSIZE_WHERE_NEIGHBORHOOD_IS_1_AND_BUFFER_IS_20.0_AND_FUNCTIONMULT_IS_VEGETATION_FRACTION
SELECT_LOTSIZE: The end result must be area taken up by buildings; some amount in square meters.NEIGHBORHOOD_IS_1: We want the greenery in a particular neighborhood.BUFFER_IS_20.0: We don't just want to look at buildings in the neighborhood itself, but also buildings within 20 meters of the neighborhoodFUNCTIONMULT_IS_VEGETATION_FRACTION:The end result must be multiplied by the green value of the respective buildings found.
See also