www.abzwater.com TM


Feature Collection
In JavaScript API of Google Earth Engine (GEE), feature collections can be constructed from the following arguments:
- A string: assumed to be the name of a collection.
- A number: assumed to be the ID of a Fusion Table.
- A single geometry.
- A single feature.
- A list of features.
- A computed object: reinterpreted as a collection.
For example, as shown in the below code snippet, few feature collections are formed by changing the constructor of the feature collection. The variable named statesData is used to construct a feature collection by specifying the ID. Similarly, pFCfromGeometry, pFCfromFeature, and pFCfromFeatures are constructed by specifying a geometry, feature, and a list of features, respectively.
1.	var COLOR = {  
2.	  RED: 'ff0000',  
3.	  BLUE: '0000ff',  
4.	  BLACK:'000000'  
5.	};  
7.	var statesData = ee.FeatureCollection('ft:1dZ78QI6P_HrZ6oabSKitytOhWM__fI9O1ayP4AoI');  
9.	var pRectangle1 = ee.Geometry.Rectangle(-107.49, 36.04, -106.49, 36.84);  
10.	var pRectangle2 = ee.Geometry.Rectangle(-106.49, 36.04, -105.49, 36.84);  
12.	var pFCfromGeometry=ee.FeatureCollection(pRectangle1);  
13.	var pFCfromFeature=ee.FeatureCollection(ee.Feature(pRectangle1));  
14.	var pFCfromFeatures=ee.FeatureCollection([ee.Feature(pRectangle1),ee.Feature(pRectangle2)]);  
16.	print(statesData);  
17.	print(pFCfromGeometry);  
18.	print(pFCfromFeature);  
19.	print(pFCfromFeatures);  
22.	Map.addLayer(statesData, {'color': COLOR.BLUE});  
23.	Map.addLayer(pFCfromGeometry, {'color': COLOR.RED});  
24.	Map.addLayer(pFCfromFeature, {'color': COLOR.BLACK});  
25.	Map.addLayer(pFCfromFeatures, {'color': COLOR.BLUE});  
27.	Map.setCenter(-107.49, 36.04, 5);  
To get the information about the features in a feature collection, the JavaScript API of GEE comes with several aggregation methods (e.g., aggregate_count_distinct (),aggregate_max(), aggregate_mean(), and aggregate_min(). In the below code snippet, aggregate_count_distinct () is used to aggregate over the property named high_record to calculate the number of distinct values for the selected property (i.e., high_record).
1.	var statesData = ee.FeatureCollection('ft:1dZ78QI6P_HrZ6oabSKitytOhWM__fI9O1ayP4AoI');    
2.	var aggregate_count_distinct=statesData.aggregate_count_distinct("high_record");  
3.	print(aggregate_count_distinct);  
A feature collection is made of one or many features. Therefore, the JavaScript API of GEE comes with few methods such as filterBounds (), filter (), and filterDate () to filter a feature collection. For example, to filter a feature collection based on the geometry, the filterBounds () is used. The below code snippet is used to extract all the features that fall within a rectangle bound of interest.
1.	var statesData = ee.FeatureCollection('ft:1dZ78QI6P_HrZ6oabSKitytOhWM__fI9O1ayP4AoI');    
2.	var pGeometry=ee.Geometry.Rectangle(-106.17, 27.77,-93.52, 34.31);  
3.	var filteredRecord=statesData.filterBounds(pGeometry);  
5.	print(filteredRecord);  
6.	Map.addLayer(filteredRecord);  
7.	Map.addLayer(pGeometry); 
If the feature collection is made of many features, sometimes it may be required to limit the number of features returned and rendered. The JavaScript API is provided with a limit (max, property, ascending) method to limit a feature collection to the specified number of elements, optionally sorting them by a specified property first. The below code snippet limits the number of features to five. Since the third argument is set to “false”, the features are returned in the descending order of “high_record”.
1.	var statesData = ee.FeatureCollection('ft:1dZ78QI6P_HrZ6oabSKitytOhWM__fI9O1ayP4AoI');  
2.	print(statesData);  
3.	Map.addLayer(statesData);  
5.	var limitedData=statesData.limit(5, "high_record",false);  
7.	print(limitedData);  
8.	Map.addLayer(limitedData);

Continue Reading
Copyright © 2016 - 2020 abzWater Operating Company, LLC. All Rights Reserved.