javascriptgoogle-earth-engineoutsystems

How to process data using JavaScript API for Google Earth Engine on an external application?


I'm using the JavaScript API in an application that I'm building in OutSystems. I imported the API javascript but all the scripts examples that I'm finding create objects. The print(object) command in the console outputs values but I don't know of any equivalent command that I can use in an external script to read these objects.

I'm using the following script:

// Load watersheds from a data table and filter to the continental US.
var sheds = ee.FeatureCollection('USGS/WBD/2017/HUC06')
  .filterBounds(ee.Geometry.Rectangle(-127.18, 19.39, -62.75, 51.29));

// This function computes the squared difference between an area property
// and area computed directly from the feature's geometry.
var areaDiff = function(feature) {
  // Compute area in sq. km directly from the geometry.
  var area = feature.geometry().area().divide(1000 * 1000);
  // Compute the difference between computed area and the area property.
  var diff = area.subtract(ee.Number.parse(feature.get('areasqkm')));
  // Return the feature with the squared difference set to the 'diff' property.
  return feature.set('diff', diff.pow(2));
};

// Calculate RMSE for population of difference pairs.
var rmse = ee.Number(
  // Map the difference function over the collection.
  sheds.map(areaDiff)
  // Reduce to get the mean squared difference.
  .reduceColumns(ee.Reducer.mean(), ['diff'])
  .get('mean')
)
// Compute the square root of the mean square to get RMSE.
.sqrt();

// Print the result.
console.log('RMSE=', rmse);

However what it outputs is "RMSE= Qo {H: N, args: {…}, T: null, Uc: null}"

On the Google Earth Engine console, replacing console.log() with print(), I've got the result RMSE= 50.29671057565058

Please advise.


Solution

  • All of these objects are not values that you can usefully print; they are descriptions of computations that could be performed, but haven't yet been. You need to call .evaluate() with a callback to send the request to the Earth Engine servers.

    The reason print() works in the Earth Engine console is because it does this for you automatically.