Classification (part two)
Welcome to the dataset training module, again!
That’s right, a sequel.
Due to popular demand, we have decided to extend this module, so we did what any self-respecting Hollywood production company would do — slashed the budget, reduced the timeline, and ramped up the advertising. This module extends the classification analysis that was accomplished in Training 5! In the previous exercise, we created a land cover map, where GEE’s machine learning algorithm categorized the Earth's surface into distinct classes based on vegetation, urban infrastructure, water bodies, and agricultural areas. This is incredibly useful for providing information about the spatial distribution of various land uses and surface cover types. However, sometimes pictures are not enough. Sometimes we just need hard data. And that’s what this low-budget training will provide — nothing fancy, no special effects, just numbers.
Video not available for low-budget sequel.
“I only want to be in sequels. No. 2 of whatever.”
Advanced classification (the sequel)
Welcome to our blockbuster: "When Maps Just Don't Cut It: The Art of Turning Pretty Pictures into Hard Numbers." Sure, maps are great. But they're like the Instagram of geographic information, showing us the Earth's surface with all the filters of land cover, urban sprawl, and those adorable little forested areas. But here's the kicker: sometimes, looking pretty just isn't enough.
.This module will guide you through the process of turning those picturesque satellite maps into square kilometers, so that you can quantify change, calculate percentages, and, most importantly, throw around some impressive stats at your next red carpet premier — the quantitative data that policymakers salivate over!
Training 5's success will be a tough act to follow, so keep your expectations low. What we're doing in this module is somewhat obligatory and unlikely to dazzle, but it will get the job done. So in the spirit of direct-to-video sequels, get ready for something that might not be groundbreaking but is necessary and functional.
Exercise
We will add the following code to the training exercise from Training 5, where we classified the land around Rio de Janeiro, Brazil.
var histogram = ui.Chart.image.histogram({ image: classified, region: classified.geometry(), // Use the whole image scale: 30, // Scale in meters maxPixels: 1e8 // Adjust this value if the computation fails due to too many pixels });
The simplest way in Google Earth Engine to transform a classified image into quantitative data uses the histogram function. The above code uses the ui.Chart.image.histogram function to count the number of pixels that belong to each of your four categories, for a refresher see the table below. It uses the whole image (the variable “classified”) for this.
We then pass the histogram function several parameters
image: this is the classified image
region: classified.geometry() tells the computer to look at the entire area of your categorized image
scale: This parameter zooms in to a specific level of detail. (Here, it's 30 meters, meaning each pixel represents a 30-meter by 30-meter square on the ground).
maxPixels: 1e8 is a limit set to avoid overloading the computer with too much data. If your picture is too big, you might have to adjust this number.
Now, in the grand tradition of those second-rate horror thriller sequels that barely scrape by on the original's glory, this section of code is the equivalent of cinematic minimalism. What we are creating is a bare-bones, no-frills histogram — largely because Google Earth Engine has a very clunky method of chart generation. That's right, prepare yourself to do the absolute least, yet somehow still delivering something that audiences are willing to pay for.
// Set histogram options histogram.setOptions({ title: 'Histogram of Classified Image', fontSize: 12, hAxis: {title: 'Class Value'}, vAxis: {title: 'Count'}, });
Here in the second act, we present to you the minimum-viable histogram. There are limitations in customization for the ui.Chart.image.histogram function, and that stems from how Google Earth Engine's UI components are designed to interact with image data. They are optimized for handling and displaying large-scale geospatial data rather than for detailed customization of chart aesthetics.
The labels on the horizontal axis (hAxis) represent each class value, corresponding to a specific category of land cover within the image. The values on the vertical axis (vAxis) represent the count, or total number of pixels that fall into each of the class categories. These axes labels are done for practical reasons, any other option becomes overly complicated. The ui.Chart library primarily expects numerical data and doesn't handle categorical parameters directly in histograms.
In essence, we're not trying to win any data visualization awards here. We're simply on a mission to export our data.
// Print the histogram to the console print(histogram);
And for the grand finale, we print our histogram to the console.
But wait… what’s this?
Last five minutes of the movie, the grand reveal, the pièce de résistance, the twist ending!
Nestled unassumingly in the upper right corner of our histogram chart, there is a gray button. Clicking this button opens the histogram into full screen mode, and then some magical box appears in the full screen version where you can export your histogram to Excel. And then in Excel, you can customize to your hearts content.
Fin.
Recap
Here’s what we learned in this training:
Discussed the significance of converting visual map data into quantitative data for analysis.
Introduced the idea of using a histogram function in Google Earth Engine (GEE) to quantify classified images.
Learned to export that histogram into Excel for further customization.