/IFC-LBD

IFC.js based IFC to Linked Building Data parsers

Primary LanguageTypeScript

IFC to LBD

IFC to Linked Building Data (LBD) is built on IFC.js. It uses the web-ifc model loader and parses out triples in JSON-LD format.

demo

Install

npm i ifc-lbd

Why

Working with IFC in the express file format, and therefore the IFC.js project is like sent from the sky. It provides tools that make it a whole lot easier to retrieve properties and traverse the relationships of the IFC file, but even so, it is still a cumbersome job to work with IFC.

The minimal Building Topology Ontology (BOT), however, is quite straightforward to understand, and having a BOT dataset in RDF is cool because it allows you to do sophisticated queries it with SPARQL. The resulting JSON-LD-object can furthermore be re-structured using the cool concepts of compaction, expansion and framing. For example, it might be useful to use framing to build a simple tree structure of the graph as demonstrated below:

const frame = {
  "@context": {
    "bot": "https://w3id.org/bot#",
    "ex": "https://example.com/"
  },
  "@type": "bot:Building",
  "bot:hasStorey": {
    "@type": "bot:Storey",
    "bot:hasSpace": {
      "@type": "bot:Space"
    }
  }
}

const framed = await jsonld.frame(botTriples, frame);

Use

The IFC-LBD parser can be used in a JavaScript project or can be used as a CLI tool.

CLI Tool

Install globally on your machine npm i -g ifc-lbd

Run a subset (BOT, products) ifc-lbd [subset] -i ./myFile.ifc

NB! If used in Node 18, you currently need to set the --no-experimental-fetch flag when executing the command. But how to do this with a globally installed command?

See settings ifc-lbd -h

Run in dev node --no-experimental-fetch ./dist/cli-index.cjs bot -i ./tests/artifacts/Duplex.ifc

Building Topology Ontology (BOT)

Exports triples in compliance with the Building Topology Ontology.

// Init API and load model
const ifcApi = new WebIFC.IfcAPI();
await ifcApi.Init();
const modelID = ifcApi.OpenModel(ifcModelData);

// Init LBD Parser and parse BOT
const lbdParser = new LBDParser();
const botTriples = await lbdParser.parseBOTTriples(ifcApi, modelID);

// Close the model, all memory is freed
ifcApi.CloseModel(modelID);

Flow Systems Ontology (FSO)

Exports triples in compliance with the Flow Systems Ontology. In addition, ports are also exported and the center points of these are exported as OMG geometries. Pipe lengths are calculated from the distance between its two ports.

Coordinates and lengths are normalized to meters.

// Init LBD Parser and parse FSO
const lbdParser = new LBDParser();
const fsoTriples = await lbdParser.parseFSOTriples(ifcApi, modelID);

Flow Systems Ontology (FSO)

Exports triples in compliance with the TUBES System Ontology. This is a Work in Progress and currently only supports few concepts.

// Init LBD Parser and parse FSO
const lbdParser = new LBDParser();
const fsoTriples = await lbdParser.parseFSOTriples(ifcApi, modelID);

IFC Products

// Init LBD Parser and parse products
const lbdParser = new LBDParser();
const products = await lbdParser.parseProductTriples(ifcApi, modelID);

IFC Properties

All measurements (lengths, areas, volumes) are normalized to SI-units (m, m2, m3).

// Init LBD Parser and parse properties
const lbdParser = new LBDParser();
const properties = await lbdParser.parsePropertyTriples(ifcApi, modelID);

Contribute

This library is intended to be expanded, so please go and add your parser or extend one of the existing ones!

Remember to write tests! That's also the preferred approach to developing new functionalities. Run specific test: npm run test -i <path> (eg jest -i tests/fso.spec.ts)

NB! Due to a bug in web-ifc I had to do a hardcoded fix by changing doing a find/replace in node_modules/web-ifc/web-ifc-api-node.js and node_modules/web-ifc/web-ifc-api-browser.js:

Find:

].map((p) => p.value)

Replace:

]?.map((p) => p.value)

Stats

Execute like node ./lib/cli-tool/index.js bot -i ./tests/artifacts/Duplex.ifc

For triple count, copy resulting JSON-LD to JSON-LD Playground and convert to N-Quads + get line count.

Model Duplex (2,4MB) MEP(962KB) Schependomlaan(49,3MB) Office MEP(209,1MB)
BOT[ms] 34 13 128 349
BOT[triples] 1,718 175 12,251 33,087
FSO[ms] - 55 - 165
FSO[triples] - 2,386 - 32,024
Products[ms] 9 8 46 174
Products[triples] 218 85 3,635 16,012
Properties[ms] 161 48 3,066
Properties[triples] 15,506 1,401 266,391

Units

In the current setup, all units are as defined in the input model. Will be neutralized to the following in a future release:

Measure Unit
Distance mm
Area m2
Volume m3