Google earth engine 기초 문법 요약

38546 단어 GEE
GEE API: https://developers.google.com/earth-engine/api_docs
//       GEE         JS  ,
//         、  、   、  、  、    、  、  
//string    
var str = "hello world!";
print(str);

//number   
var age = 12;
print("age is " + age);

var percent = 0.02;
print("percent is " + percent);

//bool    
var flag = true;

//condition     
if (flag) {
 print("this is true");
} else {
 print("this is false");
}

//list   
var names = ["a", "b", "c"];
print(names);

//for loop   
for(var n in names) {
 print("for loop is " + n);
}

//while loop   
var index = 0;
while (index  < names.length) {
 print("while loop is " + names[index]);
 index ++;
}

//object   
var info = {
 name: "ABC",
 age: 20,
 desc: "this is a boy!"
};
print(info);
print("age is " + info["age"]);
print("name is " + info.name);

//function   
var add = function(a, b) {
 return a+b;
};
print("10 + 20 = " + add(10, 20));

function sub(a, b) {
 return a-b;
}
print("20 - 10 = " + sub(20, 10));

GEE 에서 흔히 볼 수 있 는 데이터 형식의 동작:
//ee.String     
var base_str = "this is string.";
var ee_str1 = ee.String(base_str);
print("ee string is", ee_str1);

//      
print("ee string length ", ee_str1.length());

//     
var ee_str2 = ee.String(" second string");
var ee_str3 = ee_str1.cat(ee_str2);
print(ee_str3);


//     
var ee_str4 = ee.String("my name is AA, so i am a boy.")
var ee_str5 = ee_str4.replace("AA", "BB")
print(ee_str5)

//     、   
var ee_str6 = ee.String("China");
print(ee_str6.toUpperCase())
print(ee_str6.toLowerCase())

var ee_str7 = ee.String("This is landsat8 image”);
//      ,        0
print(ee_str7.slice(1, 6));
//     
print(ee_str7.split(" "));
//ee.Number   
var num = 100.01;
var ee_num1 = ee.Number(num);
print("ee number is", ee_num1);

//    
print("ee abs is", ee.Number(-100).abs());
//         
print("float to int", ee_num1.toInt());
 
  

//ee.Array

var ee_arr1 = ee.Array([[1,2], [2,2]]);print("ee_arr1 is", ee_arr1);var ee_arr2 = ee.Array(ee.List([[1,1], [3,3]]));// 、 、 、 print("add result ", ee_arr1.add(ee_arr2));print("subtract result", ee_arr1.subtract(ee_arr2));print("divide result", ee_arr1.divide(ee_arr2));print("multiply result", ee_arr1.multiply(ee_arr2));
//basice gee data type
//ee.Date   
var ee_date1 = ee.Date("2017-01-01”);
print("ee_date1 is", ee_date1);
print("ee date is", ee.Date.fromYMD({
 year:2010,
 month:1,
 day:1
}));

//      
var now = Date.now();
print("js now is " + now);
print("ee date now is", ee.Date(now));
//basice gee data type
//ee.Dictionary   
var ee_dict1 = ee.Dictionary({
 name: "AA",
 age: 10,
 desc: "this is a boy"
});
print("keys is", ee_dict1.keys());
print("age is ", ee_dict1.get("age"));
print("name is ", ee_dict1.get("name"));
//basice gee data type
//ee.List   
var ee_list1 = ee.List([1,2,3,4,5]);
print("ee list create first method", ee_list1);


//             Js  ,         
var ee_list2 = ee.List.sequence(1, 5);
print("ee list create second method", ee_list2);
print("ee_list2[1] = ", ee_list2.get(1));


print("step is 2", ee.List.sequence(1, 5, 2));
print("count is 2", ee.List.sequence({
 start:1,
 end:5,
 count:2
}));


//     4  ,     10   
print("repeat ", ee.List.repeat(10, 4));

좋은 웹페이지 즐겨찾기