Manage Workspaces
This tutorial shows how to create and manage interactive workspaces using the ZillionInfo API. You’ll learn how to create a workspace with multiple data layers using different classification methods.
Prerequisites
- A ZillionInfo account. If you don’t have one, you can sign up at ZillionInfo.
- An API key for authentication.
- Spatial data and attribute data already uploaded to the platform (see the Data Management tutorial if needed)
Steps
-
Get your data IDs
Before creating a workspace, you need the IDs of the spatial and attribute data you want to include. You can get these using the
getDataLists
API.Terminal window curl -X GET "https://services.zillioninfo.com/zi/data/app/api/getDataLists" \-H "Authorization: Bearer YOUR_API_KEY"import requestsimport json# API endpointurl = "https://services.zillioninfo.com/zi/data/app/api/getDataLists"# Headersheaders = {"Authorization": "Bearer YOUR_API_KEY"}# Make the GET requestresponse = requests.get(url, headers=headers)# Print the responseprint(json.dumps(response.json(), indent=2))# Store data IDs for use in creating the workspacedata_list = response.json().get("data", {})# Example: Find data IDs by namespatial_data_id = Noneattribute_data_id = Nonefor data_id, data_name in data_list.items():if data_name == "My Spatial Data":spatial_data_id = int(data_id)elif data_name == "My Attribute Data":attribute_data_id = int(data_id)print(f"Spatial Data ID: {spatial_data_id}")print(f"Attribute Data ID: {attribute_data_id}")Response:
{"data": {"1234": "My Spatial Data","5678": "My Attribute Data"}} -
Create a workspace with multiple layers
Now, create a workspace with two layers: one using multivariate classification and one using univariate classification.
Terminal window curl -X POST "https://services.zillioninfo.com/zi/data/app/api/createWorkspace" \-H "Authorization: Bearer YOUR_API_KEY" \-H "Content-Type: application/json" \-d '{"name": "My Multi-Layer Workspace","accessType": "private","params": [{"dataId": 1234,"classification": {"type": "multivariate","param": {"variables": [{"vars": [0, 1, 2],"nors": [-1, -1, -1],"weights": [1.0, 1.0, 1.0]}],"method": "SOM","somSize": 3}}},{"dataId": 1234,"classification": {"type": "univariate","param": {"mode": "numeric","field": "population","type": "getClassJenks","numClasses": 5}}}],"showAttributeTable": true,"showFieldTable": true,"showPcp": true,"showRightPanel": true}'import requestsimport json# API endpointurl = "https://services.zillioninfo.com/zi/data/app/api/createWorkspace"# Headersheaders = {"Authorization": "Bearer YOUR_API_KEY","Content-Type": "application/json"}# Request payloadpayload = {"name": "My Multi-Layer Workspace","accessType": "private","params": [{# First layer - Multivariate classification"dataId": 1234, # Spatial data ID"classification": {"type": "multivariate","param": {"variables": [{"vars": [0, 1, 2], # Indices of variables to use"nors": [-1, -1, -1], # Normalization variables (-1 for none)"weights": [1.0, 1.0, 1.0] # Equal weights for each variable}],"method": "SOM", # Self-Organizing Map method"somSize": 3 # 3x3 grid (9 clusters)}}},{# Second layer - Univariate classification"dataId": 1234, # Same spatial data ID"classification": {"type": "univariate","param": {"mode": "numeric", # Numeric field classification"field": "population", # Field name to classify"type": "getClassJenks", # Jenks natural breaks classification"numClasses": 5 # Number of classes}}}],"showAttributeTable": True,"showFieldTable": True,"showPcp": True, # Show parallel coordinate plot"showRightPanel": True}# Make the POST requestresponse = requests.post(url, headers=headers, json=payload)# Print the responseprint(json.dumps(response.json(), indent=2))# Store the workspace key and job ID for checking statusresult = response.json()workspace_key = result.get("workspaceKey")job_id = result.get("jobID")print(f"Workspace Key: {workspace_key}")print(f"Job ID: {job_id}")Parameters:
name
: Name of the workspaceaccessType
: Sharing scope of the workspace (private, public, etc.)params
: Array of layer parametersdataId
: Spatial data IDcsvDataId
: Attribute data IDclassification
: Classification settings- For multivariate classification:
type
: “multivariate”param.variables.vars
: Array of variable indicesparam.variables.nors
: Array of normalization variable indicesparam.variables.weights
: Array of weightsparam.method
: Classification method (e.g., “SOM”)param.somSize
: Size of the SOM grid
- For univariate classification:
type
: “univariate”param.mode
: “numeric” or “categorical”param.field
: Field name to classifyparam.type
: Classification methodparam.numClasses
: Number of classes
- For multivariate classification:
showAttributeTable
: Whether to show the attribute tableshowFieldTable
: Whether to show the field tableshowPcp
: Whether to show the parallel coordinate plotshowRightPanel
: Whether to show the right panel
Response:
{"jobID": 9876,"workspaceKey": "abc123xyz456","error": null}The response provides:
jobID
: The ID of the job to create the workspaceworkspaceKey
: The key of the created workspaceerror
: Error message if the creation failed
-
Check the status of the workspace creation job
Creating a workspace may take some time. You can check the status of the job using the workspace key and job ID.
Terminal window curl -X POST "https://services.zillioninfo.com/zi/data/app/api/statusWorkspace" \-H "Authorization: Bearer YOUR_API_KEY" \-H "Content-Type: application/json" \-d '{"jobID": 9876,"workspaceKey": "abc123xyz456"}'import requestsimport jsonimport time# API endpointurl = "https://services.zillioninfo.com/zi/data/app/api/statusWorkspace"# Headersheaders = {"Authorization": "Bearer YOUR_API_KEY","Content-Type": "application/json"}# Request payloadpayload = {"jobID": 9876, # Job ID from previous step"workspaceKey": "abc123xyz456" # Workspace key from previous step}# Function to check job statusdef check_workspace_status():response = requests.post(url, headers=headers, json=payload)return response.json()# Poll for job completionstatus = 444 # Initial status: waitingwhile status in [333, 444]: # 333: running, 444: waitingresult = check_workspace_status()status = result.get("status")status_text = {111: "finished",222: "failed",333: "running",444: "waiting"}.get(status, "unknown")print(f"Current status: {status_text}")if status in [111, 222]: # 111: finished, 222: failedprint(json.dumps(result, indent=2))break# Wait before checking againtime.sleep(3)Parameters:
jobID
: The job ID from the previous stepworkspaceKey
: The workspace key from the previous step
Response:
{"status": 111,"result": "Job result","error": null}The status codes are:
111
: Finished222
: Failed333
: Running444
: Waiting
-
Get data list in the workspace
You can retrieve a list of data resources in the workspace.
Terminal window curl -X POST "https://services.zillioninfo.com/zi/data/app/api/getDataListInWorkspace" \-H "Authorization: Bearer YOUR_API_KEY" \-H "Content-Type: application/json" \-d '{"workspaceKey": "abc123xyz456"}'import requestsimport json# API endpointurl = "https://services.zillioninfo.com/zi/data/app/api/getDataListInWorkspace"# Headersheaders = {"Authorization": "Bearer YOUR_API_KEY","Content-Type": "application/json"}# Request payloadpayload = {"workspaceKey": "abc123xyz456" # Workspace key from previous steps}# Make the POST requestresponse = requests.post(url, headers=headers, json=payload)# Print the responseprint(json.dumps(response.json(), indent=2))# Process the data listsresult = response.json()spatial_data = result.get("spatialData", [])attribute_data = result.get("attributeData", [])print("Spatial data in workspace:")for data in spatial_data:print(f"ID: {data['id']}, Name: {data['name']}")print("\nAttribute data in workspace:")for data in attribute_data:print(f"ID: {data['id']}, Name: {data['name']}")Parameters:
workspaceKey
: The key of the workspace
Response:
{"spatialData": [{"id": 1234,"name": "My Spatial Data"}],"attributeData": [{"id": 5678,"name": "My Attribute Data"}],"error": null} -
Update a workspace
You can update a workspace to replace data resources or modify settings.
Terminal window curl -X POST "https://services.zillioninfo.com/zi/data/app/api/updateWorkspace" \-H "Authorization: Bearer YOUR_API_KEY" \-H "Content-Type: application/json" \-d '{"dashboardKey": "abc123xyz456","oldDataId": 1234,"newDataId": 4321,"keepUrl": true}'import requestsimport json# API endpointurl = "https://services.zillioninfo.com/zi/data/app/api/updateWorkspace"# Headersheaders = {"Authorization": "Bearer YOUR_API_KEY","Content-Type": "application/json"}# Request payloadpayload = {"dashboardKey": "abc123xyz456", # Workspace key"oldDataId": 1234, # ID of the spatial data to replace"newDataId": 4321, # ID of the new spatial data"keepUrl": True # Keep the same URL for the workspace}# Make the POST requestresponse = requests.post(url, headers=headers, json=payload)# Print the responseprint(json.dumps(response.json(), indent=2))# Store the workspace key and job ID for checking statusresult = response.json()workspace_key = result.get("workspaceKey")job_id = result.get("jobID")print(f"Updated Workspace Key: {workspace_key}")print(f"Job ID: {job_id}")Parameters:
dashboardKey
: The key of the workspace to updateoldDataId
: The ID of the spatial data to replacenewDataId
: The ID of the new spatial dataoldCsvDataId
: (Optional) The ID of the attribute data to replacenewCsvDataId
: (Optional) The ID of the new attribute datakeepUrl
: Whether to keep the same URL for the workspace
Response:
{"jobID": 9877,"workspaceKey": "abc123xyz456","error": null}The response provides:
jobID
: The ID of the job to update the workspaceworkspaceKey
: The key of the updated workspaceerror
: Error message if the update failed
-
Share the workspace
Once your workspace is created, you can find it in the workspace list. It’s private by default. You can edit it to share it with your groups, your organization, or the public. Then they can access it via the workspace URL.
https://services.zillioninfo.com/zi/workspace/abc123xyz456
Next Steps
- Explore your workspace to analyze patterns in your data
- Create additional layers with different classification methods