Is there any way to import a data, say handdrawn polygons (saved as coordinates) as json or text files? I have hard time reading a file into the code editor, even ones created locally, as the code editor doesn't allow use of packages such as FileReader and XMLHttpRequest (that are generally used in javascript programming). So is there any way to save to file, and read data from text/json files in earthengine code editor? other than importing them using asset manager which restricts us to import only raster and shape data.

edit: I am new to the earthengine or in fact any gis programming. But I am not sure why the question is unclear, it is simple. In every programming language/library there is a way to save/read data locally or to drive (in this case) using standard text, csv, json etc., formats. So is there a way here or are we restricted just to use asset manager to import the two types of data? (if you are aware even the python interface supports that (as it runs locally), which I came to know recently). Because it is very obvious need when I program unless my whole code going to be written in the code editor, which is unlikely, especially if I want to do any serious computing involving other 3rd party packages, plus it feels the programming is very restricted when using code editor.

  • What about just inserting the coordinates into ee.Geometry.Polygon()? – Kersten Aug 13 '17 at 13:56
  • I think you should be more specific in what you're trying to do, what is your goal, in which environment you are working. You won't be able to use XMLHttpRequest in the code editor.. you should give more details to get an answer – Rodrigo E. Principe Aug 13 '17 at 19:18
  • My goal is to read handdrawn coordinates stored in text/json files for exporting images. In addition, it would be a lot easier to store and retrieve data as it won't be possible to do the complete processing or use other libraries, in the editor. So I am trying to read a local file as mentioned in the question, in any way possible. – ArunKumar Aug 13 '17 at 22:41
  • 1
    You can do that in the python version of earth engine. – J Kelly Aug 14 '17 at 2:45
  • Yes, if you want to interact with local file I agree with @JKelly, use the Python API. But, if you still want to use the code editor, have you tried to upload your data to a fusion table? That way you could use it in the code editor. – Rodrigo E. Principe Aug 14 '17 at 10:55
  1. Draw a polygon in the Earth Engine Code Editor.
  2. Print it using print(geometry).
  3. Click the JSON tag in the console next to the printout.
  4. Copy the printed JSON and paste into a text file.
  5. Move the text file to a cloud storage bucket. (This is the 'read data locally' bit of your question which can be accomplished via command line or from the Storage interface of the Cloud Console).
  6. Make it publicly viewable.
  7. Load and display using the following script.

Code Editor script:

var url = 'gs://ee-docs-demos/polygon.json'; 
var blob = ee.Blob(url); 
var string = blob.string(); 
var json = ee.Deserializer.fromJSON(string.getInfo()); 
var polygon = ee.Geometry(json); 

See also this demo. It's also worth noting that this is a mechanism for getting drawn polygons out of the Earth Engine Explorer (Click Manage Workspace, Import/Export, then you'll find the JSON).


Earth Engine can import a Feature Collection from a Google Fusion Table. You can save you hand drawn polygons in a column of a fusion table. You can create and update a fusion table directly from javascript using the fusion tables api or use the Shape Escape tool to upload shape files to a fusion table.

Note your must make the fusion table public for earth engine to see it.

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.