0

I am using the GEE API for Javascript in Node.js, i need import a shape file and use it for clipping raster, my shape file have many polygons, in the GEE console my code work fine:

var AOI = ee.FeatureCollection("my_shape_file");

var image = ee.Image("my_image");

Export.image.toAsset({
  'image': image.clip(AOI),
  'description': 'Region',
  'assetId': 'Region',
  'scale': 120,
  'region': AOI,
  'maxPixels': 1e12,
  });

but in Node.js:

var ee = require('@google/earthengine');
var privateKey = require('my privatekey');

var runAnalysis = function() {
  ee.initialize(null, null, function() {

  var AOI = ee.FeatureCollection("my_shape_file");
  var image = ee.Image("my_image");
  var task = ee.batch.Export.image.toAsset({
      image: image.clip(AOI),
      description: 'Region',
      assetId: 'Region',
      region: AOI,
      scale: 120,
      crs: 'EPSG:4326'
  });
    
  task.start(function () {
    console.log('Started task #: ' + task.id);    
    }, function (error) {
      console.log('Error: ' + error);
    });  

  }, function(e) {
    console.error('Initialization error: ' + e);
  });
};

ee.data.authenticateViaPrivateKey(privateKey, runAnalysis, function(e) {
  console.error('Authentication error: ' + e);
});

it fail with the error:

Uncaught Error: Invalid GeoJSON geometry: {"func":{"signature_":{"args":[{"description":"The asset ID of the table to load.","type":"String","name":"tableId","default":null},{"description":"The name of the column to use as the main feature geometry. Not used if tableId is an asset ID.","type":"String","name":"geometryColumn","default":null,"optional":true},{"description":"The version of the asset. -1 signifies the latest version. Ignored unless tableId is an asset ID.","type":"Long","name":"version","default":null,"optional":true}],"description":"Returns a Collection of features from a specified table.","returns":"FeatureCollection","name":"Collection.loadTable"}},"args":{"tableId":"projects/..."},"varName":null}

i understand it fails because it is expecting geojson like information, not a shape file. How can I convert my shape file into GeoJSON in my Node.js App?

Thanks!

gurrumo
  • 83
  • 2
  • 10

0 Answers0