欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Google Earth Engine(gee)中的List

程序员文章站 2022-05-26 19:10:20
...

目录

ee.List

List.repeat()

List.sequence()

List中的get、set

List中的replace、replaceAll

List中的add、insert、reverse、swap

List中的sort

List 中的remove、removeAll

List中的equals、contains、containsAll

List.map()

List中的iterate

List中的size、length

 


类似于js中的数组 

ee.List

Google Earth Engine(gee)中的List

print('ee.List([1, 2, 3, 4, 5]):',  ee.List([1, 2, 3, 4, 5]));
print('ee.List.sequence(1, 5):', ee.List.sequence(1, 5));
print('ee.List.sequence(1, 5).get(2):', ee.List.sequence(1, 5).get(2));

print('ee.List(["a","b","c","d"]):',  ee.List(["a","b","c","d"]));
print('ee.List(["a","b","c","d"]).get(2):',  ee.List(["a","b","c","d"]).get(2));

print('ee.List.sequence(1,  365,  16)',ee.List.sequence(1,  365,  16))

List.repeat()

Google Earth Engine(gee)中的List

List.sequence()

ee.List.sequenee.List.sequencece ( start , end,step , 等差数列由几个数字构成)

Google Earth Engine(gee)中的List

Google Earth Engine(gee)中的List

List中的get、set

Google Earth Engine(gee)中的List


print(ee.List([1992,23,45,"hello"]))
print(ee.List([1992,23,45,"hello"]).set(0,2000))
print(ee.List([1992,23,45,"hello"]).set(1,"hahahah"))
print(ee.List([1992,23,45,"hello"]).set(-1,"world"))

print(ee.List([1992,23,45,"hello"]).get(0))

List中的replace、replaceAll

Google Earth Engine(gee)中的List

print(ee.List([1992,23,"hello",1992]))
print("replace",ee.List([1992,23,"hello",1992]).replace(1992,2000))
print("replaceAll",ee.List([1992,235,"hello",1992]).replaceAll(1992,2000))

List中的add、insert、reverse、swap

Google Earth Engine(gee)中的List

print("add",ee.List([1992,23,"hello",1992]).add("lijiang"))
print("insert",ee.List([1992,23,"hello",1992]).insert(2,"sichuan"))
print("reverse",ee.List([1992,23,"hello",1992]).reverse())
print("swap",ee.List([1992,23,2,1992,56]).swap(1,4))

List中的sort

Google Earth Engine(gee)中的List

print(ee.List([1992,23,1,1992]).sort())
print(ee.List(["beijing","shanghai","sichuan","chongqing"]).sort())

List 中的remove、removeAll

Google Earth Engine(gee)中的List

print(ee.List([1992,23,"hello",1992]))
print(ee.List([1992,23,"hello",1992]).get(2))

print(ee.List([1992,23,"hello",1992]).remove("hello"))//移除操作不是用索引
print(ee.List([1992,23,"hello",1992]).removeAll([1992,"hello"]))

List中的equals、contains、containsAll

Google Earth Engine(gee)中的List

var list1=ee.List(["a","b","c","d"])
var list2=ee.List(["a","b","d","c"])
var list3=ee.List(["a","b","c"])

print(list1.equals(list2))
print(list1.contains("a"))
print(list1.contains(list3))
print(list1.containsAll(list3))

List.map()

Google Earth Engine(gee)中的List

var list1=ee.List(["a","b","c","d"])

function repeatName(name){
  return ee.List.repeat(name,3)
}

print("list1",list1)
print("list1.map(repeatName)",list1.map(repeatName))

List中的iterate

Google Earth Engine(gee)中的List

var list=ee.List([1,2,3,4,5])

function myAdd(num1,num2){
  return ee.Number(num1).add(num2)
}

print(list.iterate(myAdd,0))
print(list.iterate(myAdd,10))

List中的size、length

size()和.length()指令具有相同的效果

Google Earth Engine(gee)中的List