Google Earth Engine与Google Earth的区别:
Google Earth:观测工具
Google Earth Engine:对地球科学数据的分析
GEE注册:https://signup.earthengine.google.com
GEE案例:https://earthengine.google.com/case_studies/
https://explorer.earthengine.google.com/#workspace
String Number Array List Dictionary
1.String
print('Hello World')
var string_1 = ee.String('Hello')
var string_2 = ee.String('World')
var cat_string = string_1.cat(string_2)
print(cat_string)
var string_1 = ee.String('ABC AEF AMN')
var string_2 = string_1.replace('A', '-')
print(string_1, string_2)
ABC AEF AMN
-BC AEF AMN
var string_1 = ee.String('A_B_C_D_E')
var string_2 = string_1.split('_')
print(string_1, string_2)
A_B_C_D_E
[“A”,“B”,“C”,“D”,“E”]
i:忽略大小写
g:全局匹配
var string_1 = ee.String('A B C D C')
var string_2 = string_1.match('C','i')
print(string_1, string_2)
var string_2 = string_1.match('C','g')
print(string_1, string_2)
A B C D C
[“C”]
A B C D C
[“C”,“C”]
var string_1 = ee.String('1234 5678 9876')
var string_2 = string_1.slice(5,10)
print(string_1, string_2)
var string_2 = string_1.slice(5)
print(string_1, string_2)
1234 5678 9876
5678
1234 5678 9876
5678 9876
var string_1 = ee.String('1234 5678 9876')
var number = string_1.length()
print(string_1, number)
1234 5678 9876
14
var number = ee.Number(-3.1415926)
var number_1 = number.int8()
var number_2 = number.toInt8()
print(number, number_1, number_2)
var panDuan = number_1.eq(number)
print(panDuan)
var panDuan = ee.Algorithms.IsEqual(number, number_1)
print(panDuan)
var panDuan = ee.Algorithms.IsEqual(number_2, number_1)
print(panDuan)
/*
eq:= neq:不等号 gt:> gte:>= lt:< lte:<=
and() or() not()
*/
var abs = number.floor().abs()
print(abs)
/*
round:四舍五入 ceil:向上取整 sqrt exp log log10
*/
-3.1415926
-3
-3
0
false
true
4
3.Dictionary
var Dictionary_Profile = ee.Dictionary({
Name:'Houyw',
Gerder:'Male',
Age:'>20',
Location:'BeiJing'
})
print(Dictionary_Profile) //输出的顺序是key的字典字典顺序
var Dict_1 = ee.Dictionary({Weight:'50kg', Hight:'160cm'})
var Dict_2 = ee.Dictionary({Weight:'70g', Age:'26'})
print(Dict_1.combine(Dict_2, true)) // true:发生冲突的时候以第二个为准
print(Dict_1.combine(Dict_2, false))
Object (4 properties)
Age: >20
Gerder: Male
Location: BeiJing
Name: Houyw
Object (3 properties)
Age: 26
Hight: 160cm
Weight: 70g
Object (3 properties)
Age: 26
Hight: 160cm
Weight: 50kg
var Dictionary_Profile = ee.Dictionary({
Name:'Houyw',
Gerder:'Male',
Age:'>20',
Location:'BeiJing'
})
var Dict_Change = Dictionary_Profile.set('Age', '<30')
print(Dict_Change) //输出的顺序是key的字典字典顺序
print(Dict_Change.keys())
print(Dict_Change.get('Name'))
print(Dict_Change.values(['Name','Age','Location']))
print(Dict_Change.contains('Hight')) // 判断 Dict_Change 是否包含 Hight
print(Dict_Change.size())
Object (4 properties)
Age: <30
Gerder: Male
Location: BeiJing
Name: Houyw
[“Age”,“Gerder”,“Location”,“Name”]
0: Age
1: Gerder
2: Location
3: Name
Houyw
[“Houyw”,“<30”,“BeiJing”]
0: Houyw
1: <30
2: BeiJing
false
4
var list = ee.List([1,2,3,2,'A','B',['c','d','e']])
print(list)
print(ee.List.repeat('Hello', 5))
// 最后一个是产生的个数
print(ee.List.sequence(0,9,1,null))
print(ee.List.sequence(0,9,null,4))
print(list.set(0,2))
print(list.set(-1,33333))
print(list.replace(2,20))
print(list.replaceAll(2,20))
[1,2,3,2,“A”,“B”,[“c”,“d”,“e”]]
[“Hello”,“Hello”,“Hello”,“Hello”,“Hello”]
[0,1,2,3,4,5,6,7,8,9]
[0,3,6,9]
[2,2,3,2,“A”,“B”,[“c”,“d”,“e”]]
[1,2,3,2,“A”,“B”,33333]
[1,20,3,2,“A”,“B”,[“c”,“d”,“e”]]
[1,20,3,20,“A”,“B”,[“c”,“d”,“e”]]
var list = ee.List([1,1,2,3])
print(list.add('add')) // 末尾add
print(list.insert(2,'insert'))
var list_zip = ee.List([4,5,6,7])
print(list.zip(list_zip))
print(list.reverse())
print(list.rotate(2)) //2 is value , 以2开头 在排序
print(list_zip.sort())
var list_flatten = ee.List([
[[22],[33]],
[[44],[55]]
])
print(list_flatten.flatten())
print(list.get(0)) // 0:index
print(list.remove(1))
print(list.removeAll([1,2]))
[1,1,2,3,“add”]
[1,1,“insert”,2,3]
[[1,4],[1,5],[2,6],[3,7]]
[3,2,1,1]
[2,3,1,1]
[4,5,6,7]
[22,33,44,55]
1
[1,2,3]
[3]
var List_1 = ee.List(['a','b','c'])
var List_2 = ee.List(['c','b', 'a'])
var List_3 = ee.List(['a','b'])
print(List_1.equals(List_2)) //false
print(List_1.contains('a')) //true
print(List_1.containsAll(List_3)) //true
var List_number = ee.List([1,2,3,4,5,6,4,5,6,5,5,5])
print(List_number.indexOf(5)) //5 第一次 出现的 index 4
print(List_number.indexOfSublist([4,5,6])) //[4,5,6] 第一次 出现的 index 3
print(List_number.lastIndexOfSubList([4,5,6])) // 6
print(List_number.frequency(5)) // 5
var list = ee.List(['a','b'])
function Do(Name){
return ee.List.repeat(Name, 3)
}
print(list.map(Do)) // [["a","a","a"],["b","b","b"]]
// 循环函数是 GEE非常不推荐一函数
var list = ee.List.sequence(1,100,1)
function Do(number1, number2){
return ee.Number(number1).add(number2)
}
print(list.iterate(Do, 0)) // 5050
print(list.size()) // 100
var array1 = ee.Array([[1],[2],[3]])
var array2 = ee.Array([[1,2,3]])
print(ee.Array.identity(5))
List (5 elements)
0: [1,0,0,0,0]
1: [0,1,0,0,0]
2: [0,0,1,0,0]
3: [0,0,0,1,0]
4: [0,0,0,0,1]
ar array1 = ee.Array([[1,1],[2,2],[3,3],[4,4]])
var array2 = ee.Array([[0],[0],[1],[0]])
print(array1.mask(array2)) // [[3,3]]
// 转置 array1.transpose()