iTranslated by AI
Google Earth Engine Learning Notes: Basics - Data Types and EE Objects
[Google Earth Engine Mega Course] Learning Notes
Hello, I'm Kokan from Nanakana Farm.
Towards solving the problem of remote agriculture, I have finally started learning Google Earth Engine (GEE) in earnest. This time, I will summarize my learning records, including the code I wrote along with the course, about 'EE objects,' which are fundamental when handling data in GEE, based on the Udemy course 'Google Earth Engine Mega Course' and the official documentation.
- Why learn 'EE objects'?
Remote sensing data consists of various data types such as dates, numbers, lists, and dictionaries. In GEE, to efficiently process these data on the server side, they must be handled as dedicated 'EE objects' rather than regular JavaScript data types.
Since they can be used with almost the same feel as basic data types in 'Vanilla JavaScript,' the feature is that they can be understood smoothly if you have programming experience.
GEE Basic Data Types: Code Practice and Learnings
Below are the code I practiced and the results.
1. Strings
By using ee.String(), you can treat JavaScript strings as GEE objects. You can see that the console returns strings processed on the server.
// Earth Engine objects
// Strings
// Example: define a string and put it into the ee.String() container to send it to Earth Engine.
var testString = '最初の文字列の例です。';
var eeStrig = ee.String(testString);
print('これは:', eeStrig);
// Define a string that exists on the server.
var myString = ee.String('これはEarth Engineサーバ上にあります。');
print('サーバ上の文字列:', myString);
// Emojis can also be used in strings.
print(ee.String('🧲⚡️👀'));
// Empty strings can also be handled.
var empty = ee.String('');
print(empty);
print(empty.length());
Console results:
• This is: An example of the first string.
• String on server: This is on the Earth Engine server.
• 🧲⚡️👀
• 0
2. Numbers
By using ee.Number(), you can treat numbers as server-side objects.
// Numbers
// Create a number object on the server using ee.Number().
// Example: Use JavaScript's Math.E method to create a constant on the server.
var myNumber = ee.Number(Math.E);
print('Number on server:', myNumber);
Console results:
• Number on server: 2.718281828459045
3. Lists
ee.List() is similar to JavaScript arrays and allows you to group multiple values. Using ee.List.sequence(), you can easily create sequential lists. You can retrieve values from a list by specifying an index with the get() method.
// Lists
// Create a sequence.
var eeList = ee.List([1,2,3,4,5]);
print(eeList);
var sequence = ee.List.sequence(1,5);
print(sequence);
// Use ee.List methods to retrieve a value.
var value = sequence.get(3);
print(value);
Console results:
• [1,2,3,4,5]
• [1,2,3,4,5]
• 4
4. Dates
ee.Date() is one of the most important data types for remote sensing data. You can specify year, month, and day using ee.Date.fromYMD(), or calculate dates using the advance() method.
// Dates
// Define a date in Earth Engine.
var date = ee.Date('2015-12-31');
print('Date:', date);
var aDate = ee.Date.fromYMD(2017, 1, 13);
print('Date:', aDate);
var testDate = ee.Date.fromYMD({
day: 23,
month: 4,
year: 2023
});
print('testDSate:', testDate);
var date = ee.Date('2019-01-01');
var futureDate = date.advance(1, 'year');
print(futureDate);
Console results:
• Date: Date (2015-12-31 00:00:00)
• Date: Date (2017-01-13 00:00:00)
• testDSate: Date (2023-04-23 00:00:00)
• Date (2020-01-01 00:00:00)
5. Dictionaries
ee.Dictionary() is a data type that manages data in key-value pairs. It uses JavaScript objects (associative arrays) converted to GEE objects.
// Dictionaries
// Convert a JavaScript object to an Earth Engine object.
var data = {'city': 'アディスアベバ', 'population': 9000000, 'elevation': 2500};
var eeData = ee.Dictionary(data);
print(eeData.get('city'));
Console results:
• Addis Ababa
Impressions and Future Outlook
The code I practiced this time taught me how to handle basic JavaScript data types as GEE 'EE objects'. Since they can be used with almost the same feel as JavaScript data types, I found it very easy to understand for those with programming experience, lowering the learning barrier.
However, note that the Udemy course uses the var keyword (pre-ECMAScript 2015 syntax). Moving forward, I will be conscious of using const and let, and continue progressing through the GEE official documentation and course.
Next time, I plan to learn how to load satellite imagery and apply filters. Stay tuned!
Discussion