A new question derived from my Seeking website to do geoprocessing online?
In Google Earth Engine, is it possible (if so, how?) to draw a polygon and extract the land cover inside?
I would guess so, since it says in the Google Earth Engine API page:
The functionality of Earth Engine is exposed through an API available in both JavaScript and Python. The API supports complex geospatial analyses including overlay, map algebra, array operations, image processing, classification, change detection, time series analysis, joins, raster-vector conversions, vector-based extraction of image statistics and much more. Algorithms are constantly being added, enhanced and updated. Through the API, users are free to script more complex analyses and creatively recombine existing algorithms. Reporting of results is supported through charting, mapping and table or image export.
Answer
To use Earth Engine to extract landcover information for a polygon region, do the following steps. The example demonstrates using the ESA GlobCover 2009 landcover dataset, but other landcover datasets could be analyzed similarly.
- Open up the Earth Engine Code Editor application at https://code.earthengine.google.com/. If you do not currently have access to Earth Engine, you will be presented with instructions on how to register for access.
- In the search box, type in landcover.
- From the results returned, select the GlobCover: Global Land Cover Map landcover dataset.
- Click the Import button to add the dataset as a variable to the Imports section of the Code Editor. Rename the variable from the default name "image" to "globcover".
- Using the Draw a shape tool located in the upper left corner of the map, draw a polygon on the map. By default, the polygon will be named "geometry"
- Type in the following Javascript code into the editor window:
// Extract the landcover band
var landcover = globcover.select('landcover');
// Clip the image to the polygon geometry
var landcover_roi = landcover.clip(geometry);
// Add a map layer of the landcover clipped to the polygon.
Map.addLayer(landcover_roi);
// Print out the frequency of landcover occurrence for the polygon.
var frequency = landcover.reduceRegion({
reducer:ee.Reducer.frequencyHistogram(),
geometry:geometry,
scale:1000
});
print('landcover frequency', frequency.get('landcover'));
- Click "Run" to execute the code, which will display landcover for the polygon, and print the landcover frequency statistics (sampled on a 1000m grid) to the console tab.
No comments:
Post a Comment