4.1.2.1 Creating a New Dataset From an Existing Table

The Spatial Studio datasets are created from existing tables, views or models in a database connection.

The following request creates a new Spatial Studio dataset from an existing table.

HTTP POST Request

curl -k -X POST https://localhost:4040/spatialstudio/oauth/v1/datasets \
 --header "Authorization: Bearer <MY_TOKEN>" \
 --header "Content-Type: application/json" \
 --data '{
  "objectType": "dataset",
  "name": "MY_LOCATIONS",
  "refId": "<MY_CONN_ID>",
  "data": {
    "dataSourceId": "$MY_CONN_ID",
    "nodePath": "database://{data}{schema}{<MY_CONN_ID>}/{marker}{TableMarker}{<MY_CONN_ID>-table}/{dataset}{DatabaseTable}{MY_LOCATIONS}",
    "description": "",
    "dataSourceType": "database",
    "lastModifiedTime": "'$DATE'"
  }
}' 

The preceding request creates a dataset from MY_LOCATIONS table. Also, note the following:

  • The -X POST option make this a HTTP POST request. This is required when invoking a state-changing action (creating a new dataset on the server). You will also need an access token with the READ and WRITE permissions (changing the server’s state is considered a WRITE operation).
  • The -–data option is used to send a JSON payload as part of the REST request. In this example an env variable $DATE (export DATE=date) is used for the required lastModifiedTime field.
  • The string <MY_CONN_ID> represents the id of the data source or connection where the table exists.
  • For formatting purposes, the request is shown split into multiple lines. The backslash \ ensures that all the lines are concatenated and treated as a single unbroken command.

The response includes the new dataset id, which is used in subsequent requests.

Response

{
  ...
   "id" : "5c3b3a6d98eab545a0f9bd66e3d07886",
  ...
}

Although you will receive the JSON response almost instantly, note that there will be additional server-side tasks (for example, statistics gathering) that still continue to run. These background tasks may take a few seconds or more depending on the size of the source table. There are REST endpoints to query and check the status of such tasks. But for the purpose of creating a new dataset, you can safely ignore them.

You can also send a host of other commands that prepare your newly created dataset, such as creating a latitude/longitude index, updating its statistics, setting a key column, and so on.