Google Earth Engine – How to Carry Over Geometry Imports Between Scripts

google-earth-engine

I am trying to access my Geometry Imports in all scripts within a repository in Google Earth Engine (for testing purposes, I want to make a copy of my main script that also has all of the Geometry Imports). By accident, I created a new script that happens to have my Geometry Imports from my main script, but I cannot figure out how that happened. Every time I try to create a new script with the Scripts Manager New drop-down button, it creates a new, empty script, but I cannot see the Geometry Imports from my main script in that repository.

How can I make a copy of a script (or a new one) that also has the Geometry Imports visible in another script in that same repository?

Best Answer

You can make the script that has the Geometry Imports a module that you can import into other scripts by exporting the vars you need with exports and then in your script import them with require.

E,g, script named "imports" with the Geometry imports:

enter image description here

// code to export the variables 
exports.geometry1 = geometry1;
exports.geometry2 = geometry2;

Script named "script" that gets the geometry variables from "imports" and does something with them:

enter image description here

var imports = require('users/myusername/scripts:imports');
print(imports.geometry1);
print(imports.geometry2);
  • scripts - the folder where imports file is located
Related Question