How-to guide·Geo referencingJavaScript · Java

Get the footprint

Get the outline of a model on the ground with BQL — the projection, its smallest rectangle or a slice at a height — as GeoJSON or WKT in WGS84, placed by the version's geo reference, and draw it on a map.

The footprint is the outline of a model seen from above, placed on the earth: a polygon in WGS84 that a map, a GIS or a permit check can use as it is. You ask for it with a BQL query: PROJECTION() projects the building onto the ground and merges everything into one shape, holes included, and .geojson("EPSG:4326") or .wkt("EPSG:4326") places it with the model's Geo reference, in longitude latitude order.

Live demo#

A model's footprint on a mapLive demo
Uses the two georeferenced demo models in your Demo folder; Model switches between them. Open BIM.works and sign in once in this browser.

The outline is drawn where the model's geo reference puts it, with the centre of the model's bounds as the red dot; the model set draws one outline per model. Outline switches between the projection, its smallest rectangle and a slice whose height you set. The panel shows the query and the answer.

Before you start#

  • A client whose credential has the query:run Scope, and read rights on the version (Run a BQL query).
  • The Vid of a processed IFC version with a geo reference: Get the geo reference tells you whether it has one, and Set the geo reference stores one. Without one, ask for .geojson or .wkt without a coordinate system: the outline in metres in the model's own coordinates.

1. Get it#

const records = await client.bim.query(["<version uuid of the first demo model>"],
	'GET PROJECTION().geojson("EPSG:4326") AS footprint, PROJECTION().area AS outlineArea');
// By alias: records.columns says where each value is in a record
const {footprint, outlineArea} = QueryColumns.byLabel(records)[0];
console.log(footprint.type, outlineArea.value);    // "Polygon" 142.7
import java.util.UUID;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;

// Without AS: a shape's value is keyed by its text
ArrayNode records = client.bim.query("GET PROJECTION().wkt(\"EPSG:4326\"), PROJECTION().area",
		UUID.fromString("<version uuid of the first demo model>"));
String wkt = records.get(0).get("PROJECTION().wkt(\"EPSG:4326\")").asText();    // "POLYGON ((2.2946846 48.8582237, ...))"
double area = records.get(0).get("PROJECTION().area").get("value").asDouble();

The answer is one record per version, with a field per shape you asked for, keyed by the shape's text. An AS names the shape's column in the answer's columns (a keyword such as area cannot be a name), which is how QueryColumns finds it by that name:

Member What
.geojson("EPSG:4326") A GeoJSON geometry (RFC 7946): a Polygon or a MultiPolygon, [longitude, latitude]. Another EPSG code gives that system's coordinates; no code, metres in the model's own coordinates.
.wkt("EPSG:4326") The same as WKT, longitude first.
.area, .perimeter In m² and m, holes subtracted and counted.
.parts, .holes How many separate polygons and holes the outline has.
.length, .width The long and the short side of the smallest rectangle around it.

A query without a WHERE outlines the building envelope: walls, columns, slabs, roofs, footings and the other envelope and structure elements, with external spaces such as terraces left out. With a WHERE it outlines the objects you name, WHERE type IN (IFCWALL, IFCSLAB) for example. A version without a geo reference answers null for a member with a coordinate system.

2. Choose the outline#

Shape What you get
PROJECTION() Everything projected on the ground and merged: roofs and balconies that overhang the walls count.
PROJECTION(ABOVE 0 mm) The same without what lies below the site level, such as wide footings.
PROJECTION(MINIMUM_RECTANGLE) The smallest rotated rectangle around the projection.
SLICE(1200 mm) A horizontal cut 1.2 m above the site level.
JavaScript#
const records = await client.bim.query([versionUuid],
	'GET PROJECTION(MINIMUM_RECTANGLE).geojson("EPSG:4326") AS rectangle, SLICE(1200 mm).wkt("EPSG:4326") AS slice, SLICE(1200 mm).area AS sliceArea');

Heights are measured from the IfcSite placement; FROM ABSOLUTE measures from the model's z = 0 and FROM LOWEST from the lowest point of the objects: SLICE(1000 mm, FROM LOWEST). FILL_HOLES keeps only the exterior rings, the outline of the building rather than its plan, and FILL_HOLES 2 m2 fills only the holes smaller than 2 m². BQL has the rest of the language.

const factory = new BimWorksClientFactory("https://bim.works");
const client = await factory.createClientWithApiToken("<your API token>");
const versionUuid = "<version uuid of the first demo model>";

// Everything in the building projected on the ground, as a GeoJSON geometry in WGS84 ([longitude, latitude]),
// its smallest rectangle, and a cut through the walls, columns and slabs 1.2 m above the site
const records = await client.bim.query([versionUuid], `GET
	PROJECTION().geojson("EPSG:4326") AS footprint,
	PROJECTION().area AS outlineArea,
	PROJECTION(MINIMUM_RECTANGLE).geojson("EPSG:4326") AS rectangle,
	SLICE(1200 mm).wkt("EPSG:4326") AS slice,
	SLICE(1200 mm).area AS sliceArea`);
// The values by their aliases: records.columns says where each one is in a record
const [record] = QueryColumns.byLabel(records);
console.log(record.footprint.type, record.outlineArea.value);    // Polygon 142.7 (m²)
console.log(record.slice);                                 // POLYGON ((2.29468 48.85822, ...))

// The same over a set of objects of your own: only the walls
const walls = await client.bim.query([versionUuid], 'GET PROJECTION().wkt("EPSG:4326") AS outline WHERE type = IFCWALL');
console.log(QueryColumns.get(walls[0], "outline", walls.columns));    // MULTIPOLYGON (...)

// Where the centre of the model's bounds and its origin land on the earth, to mark next to the outline
const placed = await client.gis.getGeoReference(versionUuid, null, {placedPoints: true});
console.log(placed.bounds_centre, placed.zero_point);    // {latitude, longitude, elevation}

The projection, its rectangle and a slice in one query, and the points to mark on a map.

3. Mark the model on the map#

getGeoReference answers two points to mark next to the outline when you pass placedPoints: bounds_centre, the centre of the model's bounds, and zero_point, the model's origin, both {latitude, longitude, elevation} placed as the outline is. Neither is the version's anchor point: that one lies exactly on the geo reference's latitude and longitude.

JavaScript#
const placed = await client.gis.getGeoReference(versionUuid, null, {placedPoints: true});
console.log(placed.bounds_centre, placed.zero_point);

4. Draw it on a map#

The GeoJSON goes onto a map as it is. This example draws the outline with MapLibre GL, the map library the BIM.works map view uses; Leaflet (L.geoJSON) and OpenLayers read the same geometry.

import * as maplibregl from "maplibre-gl";
import "maplibre-gl/dist/maplibre-gl.css";

const factory = new BimWorksClientFactory("https://bim.works");
const client = await factory.createClientWithApiToken("<your API token>");

// The projection of the building as a GeoJSON geometry in WGS84: a Polygon or a MultiPolygon
const records = await client.bim.query(["<version uuid of the first demo model>"], 'GET PROJECTION().geojson("EPSG:4326") AS footprint');
// Read by its alias through the answer's columns (QueryColumns from @bimworks/jssdk)
const geometry = QueryColumns.get(records[0], "footprint", records.columns);
const placed = await client.gis.getGeoReference("<version uuid of the first demo model>", null, {placedPoints: true});
const centre = placed.bounds_centre;

// <div id="map" style="height: 480px"></div> in the page; any MapLibre style will do
const map = new maplibregl.Map({
	container: "map",
	style: "https://tiles.openfreemap.org/styles/bright",
	center: [centre.longitude, centre.latitude],
	zoom: 17
});

map.on("load", () => {
	map.addSource("footprint", {type: "geojson", data: {type: "Feature", geometry: geometry, properties: {}}});
	map.addLayer({id: "footprint-fill", type: "fill", source: "footprint", paint: {"fill-color": "#1F6FEB", "fill-opacity": 0.35}});
	map.addLayer({id: "footprint-line", type: "line", source: "footprint", paint: {"line-color": "#1F6FEB", "line-width": 2}});

	// Zoom to the outline
	const bounds = new maplibregl.LngLatBounds();
	const polygons = geometry.type == "Polygon" ? [geometry.coordinates] : geometry.coordinates;
	for (const polygon of polygons) {
		for (const point of polygon[0]) {
			bounds.extend(point);
		}
	}
	map.fitBounds(bounds, {padding: 40, maxZoom: 20});
});

Needs maplibre-gl from npm and a <div id="map"> with a height. The OpenFreeMap style needs no key; any MapLibre style will do.

Moving from GetFootprint#

getFootprint BQL
getFootprint([vid]), wkt GET PROJECTION().wkt("EPSG:4326") (now with holes)
geojson .geojson("EPSG:4326")
type MINIMUM_BOUNDING_RECTANGLE PROJECTION(MINIMUM_RECTANGLE)
type SLICE, {height_mm: 1200} SLICE(1200 mm)
slice reference: LOWEST / ABSOLUTE SLICE(1200 mm, FROM LOWEST) / FROM ABSOLUTE
slice tolerance_mm: 10 SLICE(1200 mm, TOLERANCE 10 mm)
slice fill_holes (on by default) FILL_HOLES (off by default)
slice selection: ENVELOPE / ALL no WHERE / a WHERE that names the objects
area_m2, cut_mm .area; the bare SLICE(1200 mm) answers the measures and the cut
anchor_point, zero_point getGeoReference(vid, null, {placedPoints: true}): bounds_centre, zero_point
a geo_reference of your own none: store the geo reference first, or take the outline in model coordinates

The query needs the query:run scope where getFootprint needed geometry:read.

In the app#

With EXPORT_WKT, the export menu of a model copies the projection, a slice at the site level or a slice at 300 mm to the clipboard as WKT: in WGS84 when the model has a geo reference, else in metres in its own coordinates.

Check#

The outline lies where the model sits in the 3D viewer's geo mode, turned the same way, with bounds_centre in the middle of it (just outside it in the bend of an L-shaped building). If it is in the wrong place, the geo reference is: compare it with Get the geo reference.