Skip to content

Stage Plots

The /stage_plots API endpoint allows users to stage data for batch processing in Google Earth Engine.

This step checks the integrity of the uploaded file, and if the file is valid, it is staged in cloud storage. This means a collection_id is generated for the uploaded collection, and an initial record is created.

Currently, the following data formats are supported:

  • GeoJSON

  • CSV

  • Shapefile

  • GeoParquet

Staging data via Dashboard

Staging data via the dashboard can be done through the Suppliers pane.

Dashboard upload

The file will be checked for geometric validity, and indicate if some features are erroneous. In the above case, four features have empty geometries.

Upload validation

The easiest way to clean up a file is to use an open-source GIS software like QGIS, open the attribute table of the file, enable the layer editing (pencil icon in top menu bar) and delete the empty geometries. QGIS attribute table edit QGIS delete feature

Moreover, the data can be checked for topological inconsistencies using the Topology Checker plugin, and/or using the fix geometries functionality of QGIS on the file containing the erroneous features.

QGIS fix geometries

If no issues are detected with the file, the dashboard offers the possible to directly run the /upload_plots operation on the staged data.

The staged and uploaded data can then be consulted in the dashboard through the Suppliers pane.

Staging data using the API

Parameters and Headers

An example of a payload for the /stage_plots endpoint is the following:

import json 

request_data = {
    'request_data': json.dumps({'collection_name': '<collection_name>',
                                'description': '<custom_data_description>'})
}

files = {
    'file': ('<file_name>', open('<local_path_to_file>', 'rb'),
             '<file_format>') # (1)!
}
  1. Can be application/geo+json, text/csv, application/shapefile, application/geoparquet

With the headers being:

1
2
3
headers = {'Authorization': "Bearer <authorization_token>"
           'Content-Type': 'application/json'
}

The Authorization header must be replaced by your user token. Check this page for more information on how to authenticate.

Python

In python, you can submit a request in the following way:

stage_plots.py
import requests
import json

response = requests.post("https://epoch-sco2-api.com/stage_plots", 
                        files=files, 
                        data=request_data, 
                        headers=headers)

json_result = json.loads(response.content)
print(json_result)

Javascript

stage_plots.js
const axios = require('axios');
const fs = require('fs');
const FormData = require('form-data');

// Prepare the form data
const formData = new FormData();
formData.append('request_data', JSON.stringify({
    collection_name: '<collection_name>',
    description: '<custom_data_description>'
}));

// Append the file to the form data
formData.append('file', fs.createReadStream('<local_path_to_file>'), {
    filename: '<file_name>',
    contentType: 'application/geo+json' // Adjust content type as needed
});

// Set headers, including the authorization token
const headers = {
    ...formData.getHeaders(),
    'Authorization': "Bearer <authorization_token>"
};

// Send the POST request using Axios
axios.post('https://epoch-sco2-api.com/stage_plots', formData, { headers })
    .then(response => {
        console.log(response.data);
    })
    .catch(error => {
        console.error('Error:', error);
    });

Curl

1
2
3
4
curl -X POST "https://epoch-sco2-api.com/stage_plots" \
-H "Authorization: Bearer <authorization_token>" \
-F "request_data=$(jq -nc --arg cn '<collection_name>' --arg desc '<custom_data_description>' '{collection_name: $cn, description: $desc}')" \
-F "file=@<local_path_to_file>;filename=<file_name>;type=application/geo+json"

Response

The response looks like this:

1
2
3
response = {
    "collection_id": '0x2ac6cda336bf82ea3cdadde78baee651ced0a4093f81e702d68cd49a722db497'
}