2

Is there a way to export the coordinates of regions that have been drawn on a map in google earth engine to a .csv file?

1 Answer 1

4

Yes, you can:

  1. Open up the Google Earth Engine Code Editor.
  2. Zoom and pan the interactive map to your area of interest.
  3. Use the point, line, or polygon Geometry Tools to draw regions on the map. By default this will create an object named geometry, which will be listed on a new Geometry Imports menu that will appear to the right of the Geometry Tools.

Various geometry types drawn on the map

  1. In the Geometry Imports menu, click on the settings (gear) icon for the geometry layer. In the "Import as" dropdown menu, select FeatureCollection.
  2. In the code editing section, add a command for exporting a table:
Export.table.toDrive({
  collection:geometry,
  description:'export_my_regions',
  fileFormat:'csv'
});
  1. Click the Run button to run the script. This will create a new task in the Tasks tab called "export_my_regions".
  2. In the Tasks tab, click Run next to the "export_my_regions" task. This will display a task dialog box. Click the Run button to initiate the export task.
  3. Wait for the task to complete. After it finishes, there will be a new CSV available at the destination you specified. This example wrote the file to Google Drive, but you can write to Google Cloud Storage as well.
  4. Open the CSV file in Google Sheets, or download it to your local computer to use in other software packages.

CSV content displayed in Google Sheets

If you want to export multiple feature collections as a single file, you can merge the feature collections into a single collection using ee.FeatureCollection.merge(). The following code also adds metadata to each feature that can be used to track the source once the features are merged.

var merged = featurecollection1.map(function (f) {return f.set({'source': 'source #1'})})
      .merge(featurecollection2.map(function (f) {return f.set({'source': 'source #2'})}))
      .merge(featurecollection3.map(function (f) {return f.set({'source': 'source #3'})}));

Export.table.toDrive({
  collection: merged,
  description:'merged_regions',
  fileFormat: 'CSV'
});
4
  • I have done this and it works but the all coordinates appear on just the first line instead of multiple lines like the image above. How do I make the coordinates appear one line at a time?
    – Vaderstalk
    Jan 31, 2018 at 14:30
  • Check step #4 and verify that your variable (i.e. 'geometry') is set to be a FeatureCollection. If you already tried that, could you share a link to your script (i.e. use the "Get Link" button to get a URL for sharing your script) so that others can try to replicate your issue? Jan 31, 2018 at 23:59
  • @MichaelSaneke I appended a paragraph showing how to deal with multiple feature collections. Feb 2, 2018 at 17:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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