Is there a way to select all images in an image collection in Google Earth Engine or using Rgee?

I want to select all the images in an image collection after filtering the collection and then mosaic the images.

I know I can select individal images this way:

s2_sr16<-ee$ImageCollection('COPERNICUS/S2_SR')$filterBounds(SHP)$filterDate('2016-01-01', '2016-12-31')
listOfImages <- s2_sr16$toList(s2_sr16$size())
selected_images <- ee$ImageCollection$fromImages(list(ee$Image(listOfImages$get(1)), ee$Image(listOfImages$get(2)), 
                                                      ee$Image(listOfImages$get(3)), ee$Image(listOfImages$get(4)),
                                                      ee$Image(listOfImages$get(5)), ee$Image(listOfImages$get(6))))

1 Answer 1


s2_sr16 and selected_images are both Earth Engine ImageCollections. If you want all the images, then you can use s2_sr16 that you already have.

I'm not familiar with R syntax, but by analogy with what you have so far, your desired mosaic would be written s2_sr16$mosaic(), to produce an Earth Engine Image from the collection.

Side note: the example code you started with is unnecessarily inefficient. You should avoid using s2_sr16$toList(s2_sr16$size()) because it constructs a list as large as the entire collection, even though you are only ever using up to the 6th element of it. Instead, use toList(6) to use only the first 6 images from the collection. (But, in general, avoid using lists unless you need their precise functions — converting a large collection to a list is a good way to make your code run out of memory when you want it to work on larger problems.)

Your Answer

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

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