Create spaces

When you upload a floorplan file (DXF, DWG, PNG, JPEG, or PDF) using the @gospace-ai/api SDK’s layersUpload method, spaces (e.g., desks) are automatically created within the layer. If you need to add additional spaces or did not use a floorplan upload, you can create spaces manually using the /spatial/v1/spaces endpoint with geometry data in WKT, GeoJSON, or IMDF format.

Create a Script

Create a JavaScript file to create a space with WKT geometry:

// create_space.js
const { GospaceClient } = require('@gospace-ai/api');
require('dotenv').config();

async function createSpace() {
  try {
    const client = new GospaceClient({ api_key: process.env.GOSPACE_API_KEY || '' });
    const space = await client.spatial.spacesCreate({
      layer_id: 'lay_67890',
      name: 'Desk 101',
      type: 'desk',
      geometry: {
        type: 'WKT',
        data: 'POINT (10 10)'
      },
      labels: ['ergonomic_chair', 'near_window']
    });
    console.log('Space created:', space.id);
  } catch (error) {
    console.error('Error creating space:', error);
  }
}

createSpace();

Run the Script

Ensure your .env file contains a valid GOSPACE_API_KEY, then run:

node create_space.js

You should see the created space’s ID printed, such as:

Space created: spc_12345

Note: Replace 'lay_67890' with a valid layer_id. If you uploaded a floorplan (DXF, DWG, PNG, JPEG, or PDF) via layersUpload, spaces are auto-created, and this step is only needed for additional spaces. The API supports WKT, GeoJSON, or IMDF geometries (WKT is default). The @gospace-ai/api SDK supports TypeScript for type-safe development. To use TypeScript, rename the file to create_space.ts, install ts-node (npm install ts-node --save-dev), and run with npx ts-node create_space.ts. See developer.gospace.com for details on geometry formats and API

Last updated

Was this helpful?