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
Yes, you can:
- Open up the Google Earth Engine Code Editor.
- Zoom and pan the interactive map to your area of interest.
- 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.
- In the Geometry Imports menu, click on the settings (gear) icon for the
geometry
layer. In the "Import as" dropdown menu, select FeatureCollection. - In the code editing section, add a command for exporting a table:
Export.table.toDrive({
collection:geometry,
description:'export_my_regions',
fileFormat:'csv'
});
- Click the Run button to run the script. This will create a new task in the Tasks tab called "export_my_regions".
- 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.
- 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.
- Open the CSV file in Google Sheets, or download it to your local computer to use in other software packages.
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'
});
-
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? 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