Geographic Information Systems Asked by Inacio Bueno on February 26, 2021
I’m trying to edit string elements in a list object. I need to get a list of IDs of a image collection, and then replace the orbit row to another (in this case, 073 to 074). I’m new to GEE and got stucked creating the .map() function. Does anyone know how can I solve this?
var landsat = ee.ImageCollection('LANDSAT/LT05/C01/T1_SR')
.filterDate('2008-01-01', '2011-12-31')
.filter(ee.Filter.calendarRange(6,7,'month'))
.filter(ee.Filter.eq('WRS_PATH', 222))
.filter(ee.Filter.eq('WRS_ROW', 73))
.filterMetadata('CLOUD_COVER', 'equals', 0)
var names = ee.List(landsat.aggregate_array('system:index'));
print(names)
var replace = function(i){
var size = (i.size().subtract(1)) // get list size
var imgs = ee.List.sequence(0, 11) // creates list sequence to iterate
var replace = imgs.map(function(j) {
var str = ee.String(i.get(j)) // convert each element to a string
var str2 = str.replace('222073','222074')
var newlist = []
return newlist.add(str2)
})
}
var newnames = names.map(replace)
What I have:
What I need:
When you map
over names
, which is a list of the ids, the argument of the function would be each element of that list, thus the name. So you'd only need to rename that name
var landsat = ee.ImageCollection('LANDSAT/LT05/C01/T1_SR')
.filterDate('2008-01-01', '2011-12-31')
.filter(ee.Filter.calendarRange(6,7,'month'))
.filter(ee.Filter.eq('WRS_PATH', 222))
.filter(ee.Filter.eq('WRS_ROW', 73))
.filterMetadata('CLOUD_COVER', 'equals', 0)
var names = ee.List(landsat.aggregate_array('system:index'));
print(names)
var replace = function(name){
return ee.String(name).replace('073', '074')
}
var newnames = names.map(replace)
print(newnames)
Answered by Rodrigo E. Principe on February 26, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP