How-to guide·Geo referencingJavaScript · Java

Get the geo reference

Read the geo reference stored on a version, in WGS84 or converted to another EPSG system, from JavaScript, Java or the OpenAPI, and detect a model that has none.

BIM.works stores every Geo reference in WGS84 (EPSG:4326). This guide reads it, optionally converted to the projected CRS your application works in.

Before you start#

You need a client with the gis:read scope and the Vid of a processed version. Note that almost every IFC model has a geo reference after processing: extraction runs at upload, and what it finds in IfcSite is often wrong. A stored reference is not proof that the model is placed correctly.

Steps#

  1. Read it. The result carries the geo reference and the anchor point, the point in model coordinates (millimetres) that the latitude and longitude refer to; it is null for a version without one. Pass a target EPSG code to receive the coordinates in that system instead of WGS84.

    const factory = new BimWorksClientFactory("https://bim.works");
    const client = await factory.createClientWithApiToken("<your API token>");
    
    const stored = await client.gis.getGeoReference("<version uuid of the first demo model>", null);
    if (stored == null) {
    	console.log("no geo reference");
    } else {
    	const {latitude, longitude, elevation, rotation, epsg} = stored.geo_reference;   // epsg is "EPSG:4326"
    	console.log(latitude, longitude, elevation, rotation, stored.anchor_point);
    }
    
    // The same, converted to the Dutch RD New system
    const rd = await client.gis.getGeoReference("<version uuid of the first demo model>", "EPSG:28992");
    try (BimWorksClientFactory factory = new BimWorksClientFactory("https://bim.works");
         BimWorksClient client = factory.createClientWithApiToken("<your API token>")) {
    	GeoReferenceExtraction stored = client.gis.getGeoReference(UUID.fromString("<version uuid of the first demo model>"));
    	if (stored == null) {
    		System.out.println("no geo reference");
    	} else {
    		GeoReference geoReference = stored.getGeoReference();   // always EPSG:4326
    		System.out.println(geoReference.getLatitude() + ", " + geoReference.getLongitude() + " at " + stored.getAnchorPoint());
    	}
    }
    # The OpenAPI has no geo-reference operation; the version carries it. Bearer token from LoginWithApiToken.
    ADDRESS="https://bim.works"
    curl -s -X POST "$ADDRESS/openapi/fs/GetVersion" \
      -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
      -d '{"uuid": ""<version uuid of the first demo model>""}' | jq .geo_reference
  2. Use it. rotation is in degrees around the anchor point, elevation in metres. To place two models on one map, compare their references: the viewer does this itself in GEO mode (Geo mode).

    In JavaScript, getGeoReference(versionUuid, null, {placedPoints: true}) also answers bounds_centre and zero_point, {latitude, longitude, elevation}: where the centre of the model's bounds and its origin land on the earth, to mark next to its outline (Get the footprint).

The Java getGeoReference has no target-EPSG argument and always returns WGS84; the OpenAPI (GetVersion) returns the stored reference without the anchor point and without conversion.

Note

The JavaScript type definitions declare the result as a GeoReference; the object actually returned is {geo_reference, anchor_point}, as shown above and as the BIM.works UI reads it.

Check#

For a model you placed in the UI (Set a geo reference), latitude and longitude are the values shown in its Location section.