How-to guide·Geo referencingJavaScript · Java

Set the geo reference

Store a geo reference and its anchor point on a version from JavaScript or Java, and refresh the loaded model in the viewer.

Setting a Geo reference writes metadata on the Version; the IFC file is untouched. The values usually come from an extraction (Extract a geo reference from an EPSG code or WKT) or from a survey.

Before you start#

You need a client with the gis:write scope, the Vid of a processed version, and:

  • latitude, longitude in WGS84 degrees, elevation in metres, rotation in degrees (0–360, counter-clockwise, applied around the anchor point), and epsg, which is "EPSG:4326" for those values;
  • which north the rotation is from: "TRUE", or "GRID" for a rotation measured against the grid of the projected system it came from, as an extraction's is. Without it the rotation counts as grid-relative when the version has an original EPSG, and as true north otherwise;
  • the anchor point {x, y, z} in the model's coordinates: the point the latitude and longitude describe. {x: 0, y: 0, z: 0} means the model's local origin; an extraction returns the anchor it used.

The OpenAPI has no operation for this call.

Steps#

  1. Store it. In JavaScript, originalEpsg is optional and records the projected system the values were derived from, and rotationNorth says which north the rotation is from; the Java call has neither argument.

    const factory = new BimWorksClientFactory("https://bim.works");
    const client = await factory.createClientWithApiToken("<your API token>");
    
    const geoReference = {
    	epsg: "EPSG:4326",
    	latitude: 48.858222,     // the Eiffel tower
    	longitude: 2.294500,
    	elevation: 0,
    	rotation: 0
    };
    const anchorPoint = {x: 0, y: 0, z: 0};
    
    await client.gis.setGeoReference("<version uuid of the first demo model>", geoReference, anchorPoint, undefined, "TRUE");
    
    // From an extraction, keeping the system it came from: its rotation is against that grid
    const extraction = await client.gis.extractGeoReferenceUsingEpsg("<version uuid of the first demo model>", "EPSG:28992");
    await client.gis.setGeoReference("<version uuid of the first demo model>", extraction.geo_reference, extraction.anchor_point, extraction.original_epsg, "GRID");
    try (BimWorksClientFactory factory = new BimWorksClientFactory("https://bim.works");
         BimWorksClient client = factory.createClientWithApiToken("<your API token>")) {
    	UUID version = UUID.fromString("<version uuid of the first demo model>");
    
    	GeoReference geoReference = new GeoReference(48.858222, 2.294500, 0, 0);   // latitude, longitude, elevation, rotation
    	geoReference.setEpsg("EPSG:4326");
    	client.gis.setGeoReference(version, geoReference, new Vector3d(0, 0, 0));
    
    	// From an extraction
    	GeoReferenceExtraction extraction = client.gis.extractGeoReference(version, "EPSG:28992");
    	client.gis.setGeoReference(version, extraction.getGeoReference(), extraction.getAnchorPoint());
    }
  2. Refresh what is loaded. A viewer that already shows the version does not notice the change: call viewer.updateModel(versionUuid) and, in GEO mode, the model moves to its new place.

Copy the geo reference of another version#

A geo reference places a version's aligned coordinates: the alignment applies first. So a drawing (PDF, DWG) aligned onto an IFC model lies on the earth where that model is once it has the model's geo reference. copyGeoReference stores it: the same latitude, longitude, elevation, rotation, north and original EPSG, and the same anchor point converted to the drawing's length unit. It needs gis:write and write access to the target, and read access to the source. The OpenAPI operation is CopyGeoReference.

JavaScript#
const copied = await client.gis.copyGeoReference("<version uuid of the second demo model>", "<version uuid of the first demo model>");
// copied.geo_reference_source: {version_uuid, alignment}, the source and the target's alignment at the time;
// copied.warnings: for example that the target has no alignment, so the location places its raw coordinates
const stored = await client.gis.getGeoReference("<version uuid of the second demo model>", null, {includeSource: true});

getGeoReference with includeSource answers where a copied geo reference came from (geo_reference_source, with the source's node name) and its original_epsg. setGeoReference(versionUuid, null) removes a version's geo reference. In the app the same is the Use the location of … option of Align models and Copy from another model… on the Location section (Place a drawing on the map).

The server normalises the reference before storing it in EPSG:4326; read it back with Get the geo reference.

Check#

getGeoReference returns the values you stored, and the Map view of BIM.works shows the footprint at the new position.