I have a shapefile, consisting of 408 polygons. I want to either read images corresponding to all polygons, or iterate through them. However, it seems my code does not work.
In order to test EE actually provides me all images of all polygons, I did subset first and second polygons and saved them. And also I combined the two.
Read images of first polygon, read images of second polygon, and then read images of the combined polygons (consisting of the two).
The number of images of the shapefile consisting of two polygons, is the same as number of images of the second polygon. Which is suggesting, EE only reads images corresponding to the last polygon in the shapefile.
Moreover, in order to iterate through polygons I converted the Shapefile to a list list_of_regions
. and then used list_of_regions.get(1)
to get images corresponding to first polygon. But it throws error at me.
The shapefiles are here: https://drive.google.com/drive/folders/1KgWdBFhKa5v2ahL_aAsjb0_F09lKWAnT?usp=sharing
////////
//////// Read ShapeFiles from asset directory
////////
var double_LatLong_regions = ee.FeatureCollection(double_LatLong_SF);
var double_2018_first_region = ee.FeatureCollection(double_first_2018)
var double_2018_second_region = ee.FeatureCollection(double_second_2018)
var double_2018_first_and_second_region = ee.FeatureCollection(
double_first_and_second_2018)
var double_2018_last_region = ee.FeatureCollection(double_last_2018)
var needed_bands = ['B8', 'B4']
var year = '2018'
var start_date = year.concat('-03-01')
var end_date = year.concat('-10-01')
print ('double_LatLong_regions is \n of size: ',
double_LatLong_regions.size())
var list_of_regions = double_LatLong_regions.toList(double_LatLong_regions.size())
print ("list_of_regions is of length: ", list_of_regions.size())
// print ((list_of_regions.get(1)))
///////////////////////////////////////////////////
///////
/////// check whether we are getting all images or not.
///////
///////////////////////////////////////////////////
//
// first field
//
var double_first_2018_IC = ee.ImageCollection('COPERNICUS/S2')
.filterDate( start_date, end_date )
.filterBounds(double_2018_first_region)
.filterMetadata('CLOUDY_PIXEL_PERCENTAGE', "less_than", 10)
.select(needed_bands);
print ("------ 1st region ------")
print ("there are ", double_2018_first_region.size(), "regions in first region SF")
print ("number of images \n for first regions is ",
double_first_2018_IC.size())
//////////////////////////////////////////////////////
//
// second field
//
//////////////////////////////////////////////////////
var double_second_2018_IC = ee.ImageCollection('COPERNICUS/S2')
.filterDate( start_date, end_date )
.filterBounds(double_2018_second_region)
.filterMetadata('CLOUDY_PIXEL_PERCENTAGE', "less_than", 10)
.select(needed_bands);
print ("------ 2nd region ------")
print ("there are ", double_2018_second_region.size(), "regions in second region SF")
print ("number of images \n for second regions is ",
double_second_2018_IC.size())
//
// first and second fields
//
var double_first_and_second_2018_IC = ee.ImageCollection('COPERNICUS/S2')
.filterDate( start_date, end_date )
.filterBounds(double_2018_first_and_second_region)
.filterMetadata('CLOUDY_PIXEL_PERCENTAGE', "less_than", 10)
.select(needed_bands);
print ("------ 1st and 2nd region ------")
print ("there are ", double_2018_first_and_second_region.size(),
"regions in first and last region")
print ("number of images \n for first and second regions is ",
double_first_and_second_2018_IC.size())
////////////////////////////
//
// all fields
//
var double_LatLong_IC = ee.ImageCollection('COPERNICUS/S2')
.filterDate( start_date, end_date )
.filterBounds(double_LatLong_regions)
.filterMetadata('CLOUDY_PIXEL_PERCENTAGE', "less_than", 10)
.select(needed_bands);
print ("------ all shapeFile ------")
print ("there are ", double_LatLong_regions.size(), "regions in total")
print ("number of images for all regions is ",
double_LatLong_IC.size())
////////////////////////////////////////////////
//
// last region
//
var double_last_2018_IC = ee.ImageCollection('COPERNICUS/S2')
.filterDate( start_date, end_date )
.filterBounds(double_2018_last_region)
.filterMetadata('CLOUDY_PIXEL_PERCENTAGE', "less_than", 10)
.select(needed_bands);
print ("------ last region ------")
print ("there are ", double_2018_last_region.size(), "regions in last region")
print ("number of images \n for last regions is ",
double_last_2018_IC.size())
////////////////////////////////////////////
////////////////////////////////////////////
////////////////////////////////////////////
// print (ee.FeatureCollection(list_of_regions.get(1)))
// var list_of_regions_1_IC = ee.ImageCollection('COPERNICUS/S2')
// .filterDate( start_date, end_date )
// .filterBounds(list_of_regions.get(1))
// .filterMetadata('CLOUDY_PIXEL_PERCENTAGE', "less_than", 10)
// .select(needed_bands);
// print ("------ list of regions ------")
// print (list_of_regions_1_IC)
// print ("there are ", list_of_regions.size(), "items in last region list")
// print ("number of images is ", list_of_regions_1_IC.size())