2

From https://medium.com/google-earth/making-it-easier-to-reuse-code-with-earth-engine-script-modules-2e93f49abb13 I'm learning how to use modules.

So I can have mdl1:

var timeField = 'system:time_start';
exports.timeField = timeField;

Then on mdl2 I can:

var mdl1 = require('users/user/rs:mdl1');

Then I have mdl3 which required mdl2:

var mdl2 = require('users/user/rs:mdl2');

What if I need mdl1 on mdl3 as well, should I do the following on mdl3 again?

var mdl1 = require('users/user/rs:mdl1');

I put a print("module numnber") on each module and looks like the require call actually executes the script, I think by doing like above I'm executing mdl1 two times, which looks wrong. Isn't?

3

The modules in Earth Engine work a little like Python modules (if you are familiar with using Python). You won't need to call/require mdl1 again within mdl3 as long as you export the mdl1 object within mdl2. I think this should get the result you are looking for.

mdl1 module:

var timeField = 'system:time_start';
exports.timeField = timeField;

mdl2 module:

var mdl1 = require('users/user/rs:mdl1');
exports.mdl1 = mdl1

mdl3 module:

var mdl2 = require('users/user/rs:mdl2');
var field = mdl2.mdl1.timeField
print(field)

This will prevent mdl1 from being executed twice and will allow you to access the variables. I hope this helps!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.