Relations
Follow an object to its building storey, its type object and the elements that bound a space, in GET and in WHERE.
An IFC model is a graph: a door sits in a wall, the wall on a storey, the storey in a building; a wall occurrence points at a wall type that carries the properties shared by all walls of that kind. BQL follows these relations with a path prefix in front of any feature you already know.
The storey of an object#
buildingStorey. in front of a feature reads that feature from the storey that contains the object:
GET qid, attribute.Name, buildingStorey.attribute.Name WHERE type = IFCDOORThe same prefix filters: buildingStorey.attribute.Name = "00 begane grond" keeps the objects on the ground floor. The storey also carries a calculated level number, buildingStorey.calculated.property.level, which is more robust than a name when models differ in naming; Building storeys explains how storeys are ordered and matched across models. building., site. and project. work the same way for the levels above the storey.
The type object#
In IFC an occurrence (this wall) is linked to a type object (this kind of wall). The type object is the place authoring tools put the properties that all occurrences share, so a query on occurrences often needs a value from the type:
GET qid, attribute.Name, typeObject.attribute.Name WHERE type = IFCWALLtypeObject.property.* reaches the type's property sets in the same way. Keep the direction in mind: query the occurrence (type = IFCWALL) and reach the type through typeObject.; a query with type = IFCWALLTYPE returns the type objects themselves, which have no geometry and are not what you count or colour. Type objects covers how type and occurrence properties merge.
Related sets#
Some relations lead to many objects: the materials of a wall, its classifications, the openings in it, the elements that bound a space. In GET such a relation returns a list per object:
GET qid, attribute.Name, material.name, classification.identity WHERE type = IFCWALLA wall of the demo model comes back with material: [{"name": "03 Metselwerk - kalkzandsteen C"}] and classification: [{"identity": "21.12"}] — one entry per material layer and per classification reference. Both work in WHERE as well: material.name CONTAINS "hout" keeps the wooden ones, classification.identity = "21.12" the 423 walls of that NL-SfB code.
The relations of the IFC structure work the same way: hasOpenings on a wall lists its openings and fillings the doors and windows that fill them, fillsVoid goes the other way from a door to its opening, and spaceBoundary.relatedBuildingElement steps from a space to the walls, slabs and windows that bound it. The naming follows the IFC relationships; Openings and fillings draws the picture, and Sub-features and relations has the quantifiers (.any, .all, .count) that ask about a related set instead of listing it.
A relation returns nothing when the model does not carry it. Schependomlaan has no IfcRelSpaceBoundary entities and no explicit filling relations, so spaceBoundary and fillsVoid come back empty on it — which is itself worth knowing about a model before you write a check that depends on them.
A related set can also be summed up in place, spaceBoundary(SUM(quantity.*.Area)) for the boundary area of each space; the next lesson introduces the aggregate functions this uses.
Your turn#
GET qid, attribute.Name WHERE type = IFCDOORHints
- Put buildingStorey. in front of attribute.Name.
- The prefixed feature is a second GET item.
Show solution
GET qid, attribute.Name, buildingStorey.attribute.Name WHERE type = IFCDOORGET qid, attribute.Name, buildingStorey(attribute.Name) WHERE type = IFCDOORGET qid, attribute.Name WHERE type = IFCWINDOWHints
- The storey name is a condition on buildingStorey.attribute.Name.
- Combine it with the type condition using AND.
- The calculated level of that storey is 0, which is another way to say the same thing.
Show solution
GET qid, attribute.Name WHERE type = IFCWINDOW AND buildingStorey.attribute.Name = "00 begane grond"GET qid, attribute.Name WHERE type = IFCWINDOW AND buildingStorey.calculated.property.level = 0This round shows its result in the 3D viewer: the objects your query selected are coloured, the rest of the model stays grey, and the view is framed around them. It is the fastest way to see whether a condition means what you thought — a query with the wrong storey is obvious in one glance.
GET qid, attribute.Name WHERE type = IFCWALLHints
- The type object is reached with typeObject.
- Its name is typeObject.attribute.Name.
Show solution
GET qid, attribute.Name, typeObject.attribute.Name WHERE type = IFCWALLGET qid, attribute.Name, typeObject(attribute.Name) WHERE type = IFCWALLGET qid, attribute.Name WHERE type = IFCWALLHints
- The relation is called material, and the field of a material is name.
- A wall with several layers gets a list, which is why this round shows JSON.
Show solution
GET qid, attribute.Name, material.name WHERE type = IFCWALLGET qid, attribute.Name, material(name) WHERE type = IFCWALLA relation that leads to many objects nests a list in the record, which the JSON shows better than a table. The order of the members is the model's, not something you can rely on — and the round accepts any order for that reason. Note that only 282 of the 934 walls carry a material at all: the record of the others simply has no material key.
You can now#
- Read a feature of the storey, building, site or project an object belongs to, and filter on it.
- Reach the type object of an occurrence and its properties.
- List the objects a relation leads to, and chain relations.
Next: Grouping and aggregates, where rows become counts and sums.