I am trying to extract a stacked ee.Image()using sampleRegions. The first step is running without any issues. However after running sampleRegions, I want to add coordinates.
var dem_30m = ee.Image('projects/isdasoil/covariates/dem_30m');
var dem_100m = ee.Image('projects/isdasoil/covariates/dem_100m');
var landcover_100m = ee.Image('projects/isdasoil/covariates/landcover_100m');
var landcover_30m = ee.Image('projects/isdasoil/covariates/landcover_30m');
var landsat7_2000 = ee.Image('projects/isdasoil/covariates/landsat7_2000');
var landsat8_2015 = ee.Image('projects/isdasoil/covariates/landsat8_2015');
var landsat8_2018 = ee.Image('projects/isdasoil/covariates/landsat8_2018');
var sentinal2_l2a_s1 = ee.Image('projects/isdasoil/covariates/sentinel2_l2a_s1');
var sentinel2_l2a_s2 = ee.Image('projects/isdasoil/covariates/sentinel2_l2a_s2');
var surface_water = ee.Image('projects/isdasoil/covariates/surface_water');
var stack = dem_30m
.addBands(dem_100m)
.addBands(landcover_100m)
.addBands(landcover_30m)
.addBands(landsat7_2000)
.addBands(landsat8_2015)
.addBands(landsat8_2018)
.addBands(sentinal2_l2a_s1)
.addBands(sentinel2_l2a_s2)
.addBands(surface_water);
// Get the values for all pixels in each polygon in the training.
var collection = stack.sampleRegions({
// Get the sample from the polygons FeatureCollection.
collection: table,
// Keep this list of properties from the polygons.
properties: ['farm_id', 'T_Year'],
// Set the farm to get Landsat pixels in the polygons.
scale: 30
});
I receive the following error when running collection_with_latlon:
FeatureCollection (Error)
Error in map(ID=00000000000000000000_2):
List.get: List is empty (index is 1).
What can I do to solve this issue?
// Break point coordinates up into properties (table columns) explicitly.
var collection_with_latlon = collection.map(function (feature) {
var coordinates = feature.geometry().transform('epsg:4326').coordinates();
return feature.set('lon', coordinates.get(0), 'lat', coordinates.get(1));
});
print(collection_with_latlon);
Export.table.toDrive({
collection: collection_with_latlon,
description: 'hist_tx',
fileFormat: 'CSV',
});