Google Earth Engine
JavaScript
API
ee.Feature
Prepared By: Sivarajah Mylevaganam
1
Table of Contents
1)
2)
3)
4)
5)
6)
7)
8)
9)
10)
11)
12)
13)
14)
15)
16)
17)
18)
19)
20)
21)
22)
23)
24)
25)
26)
27)
28)
29)
30)
31)
32)
33)
34)
ee.Feature(geometry, properties)
area(maxError, proj)
bounds(maxError, proj)
buffer(distance, maxError, proj)
centroid(maxError, proj)
containedIn(right, maxError, proj)
contains(right, maxError, proj)
convexHull(maxError, proj)
copyProperties(source, properties, exclude)
cutLines(distances, maxError, proj)
difference(right, maxError, proj)
disjoint(right, maxError, proj)
dissolve(maxError, proj)
distance(right, maxError, proj)
get(property)
getInfo(callback)
getMap(visParams, callback)
id()
intersection (right, maxError, proj)
intersects(right, maxError, proj)
length (maxError, proj)
perimeter(maxError, proj)
propertyNames()
select(propertySelectors, newProperties, retainGeometry)
set(var_args)
setGeometry(geometry)
setMulti(properties)
simplify(maxError, proj)
symmetricDifference(right, maxError, proj)
toArray(properties)
toDictionary(properties)
transform(proj, maxError)
union(right, maxError, proj)
withinDistance(right, distance, maxError, proj)
References
2
1) ee.Feature(geometry, properties)
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
var COLOR = {
RED: 'ff0000',
BLACK:'000000',
GREEN:'00ff00'
};
17.
18.
19.
20.
21.
22.
23.
24.
25.
var filteredRecord=statesData.filter(ee.Filter.gt("high_record", 44.4));
var firstRecord=filteredRecord.first();
var pFeaturefromComputedObject=ee.Feature(firstRecord);
var pRectangle1 = ee.Geometry.Rectangle(-84.46, 39.71, -82.18, 41.12);
var pRectangle2 = ee.Geometry.Rectangle(-82.18, 39.71, -81.18, 41.12);
var pFeaturefromGeometry=ee.Feature(pRectangle1);
var pGeoJSON=pRectangle2.toGeoJSON();
print(pGeoJSON);
var pFeaturefromGeoJSON=ee.Feature(pGeoJSON);
var statesData = ee.FeatureCollection('ft:1dZ78QI6P_HrZ6oabSKitytOhWM__fI9O1ayP4AoI');
Map.addLayer(pFeaturefromGeometry, {'color': COLOR.RED});
Map.addLayer(pFeaturefromGeoJSON, {'color': COLOR.BLACK});
Map.addLayer(pFeaturefromComputedObject, {'color': COLOR.GREEN});
Map.setCenter(-84.46, 39.71, 8);
2) area(maxError, proj)
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
var COLOR = {
RED: 'ff0000',
BLACK:'000000'
};
var pPolygon = ee.Geometry.Polygon(-107.49, 36.04, -106.49, 36.84, -108.2, 36.9);
var pFeaturefromGeometry=ee.Feature(pPolygon);
//Coordinate system
var areaGeometry=pFeaturefromGeometry.area();
print(areaGeometry);
Map.addLayer(pFeaturefromGeometry, {'color': COLOR.RED});
Map.setCenter(-107.49, 36.04, 8);
3) bounds(maxError, proj)
1. var COLOR = {
2.
RED: 'ff0000',
3.
BLACK:'000000'
4. };
5.
6. var pPolygon = ee.Geometry.Polygon(-107.49, 36.04, -106.49, 36.84, -108.2, 36.9);
3
7.
8.
9.
10.
11.
12.
13.
14.
var pFeaturefromGeometry=ee.Feature(pPolygon);
var pBounds=pFeaturefromGeometry.bounds();
Map.addLayer(pPolygon, {'color': COLOR.BLACK});
Map.addLayer(pBounds, {'color': COLOR.RED});
Map.setCenter(-107.49, 36.04, 8);
4) buffer(distance, maxError, proj)
1. var COLOR = {
2.
RED: 'ff0000',
3.
BLACK:'000000'
4. };
5.
6. var statesData = ee.FeatureCollection('ft:1dZ78QI6P_HrZ6oabSKitytOhWM__fI9O1ayP4AoI');
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
print(statesData);
Map.addLayer(statesData);
var filteredRecord=statesData.filter(ee.Filter.gt("high_record", 44.4));
if (filteredRecord!= null){
var firstRecord=filteredRecord.first();
var bufferedFeature=ee.Feature(firstRecord).buffer(100000);
print(firstRecord);
print(bufferedFeature);
Map.addLayer(bufferedFeature, {'color': COLOR.RED});
5) centroid(maxError, proj)
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
var COLOR = {
RED: 'ff0000',
BLACK:'000000'
};
var pPolygon = ee.Geometry.Polygon(-107.49, 36.04, -106.49, 36.84, -108.2, 36.9);
var pFeaturefromGeometry=ee.Feature(pPolygon);
var pCentroid=pFeaturefromGeometry.centroid();
print(pCentroid);
Map.addLayer(pFeaturefromGeometry, {'color': COLOR.RED});
Map.addLayer(pCentroid, {'color': COLOR.BLACK});
Map.setCenter(-107.49, 36.04, 8);
4
6) containedIn(right, maxError, proj)
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
var COLOR = {
RED: 'ff0000',
BLACK:'000000',
GREEN:'00ff00'
};
var pRectangle1 = ee.Geometry.Rectangle(-107.49, 36.04, -106.49, 36.84);
var pRectangle2 = ee.Geometry.Rectangle(-107.19, 36.04, -106.49, 36.84);
var pRectangle3 = ee.Geometry.Rectangle(-107.19, 36.24, -107.29, 36.64);
var pFeaturefromGeometry1=ee.Feature(pRectangle1);
var pFeaturefromGeometry2=ee.Feature(pRectangle2);
var pFeaturefromGeometry3=ee.Feature(pRectangle3);
var pRec2ContainedInRec1=pFeaturefromGeometry2.containedIn(pFeaturefromGeometry1);
print(pRec2ContainedInRec1);
var pRec3ContainedInRec1=pFeaturefromGeometry3.containedIn(pFeaturefromGeometry1);
print(pRec3ContainedInRec1);
Map.addLayer(pFeaturefromGeometry1, {'color': COLOR.RED});
Map.addLayer(pFeaturefromGeometry2, {'color': COLOR.BLACK});
Map.addLayer(pFeaturefromGeometry3, {'color': COLOR.GREEN});
Map.setCenter(-107.49, 36.04, 8);
7) contains(right, maxError, proj)
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
var COLOR = {
RED: 'ff0000',
BLACK:'000000',
GREEN:'00ff00'
};
var pRectangle1 = ee.Geometry.Rectangle(-107.49, 36.04, -106.49, 36.84);
var pRectangle2 = ee.Geometry.Rectangle(-107.19, 36.04, -105.49, 36.84);
var pRectangle3 = ee.Geometry.Rectangle(-107.19, 36.24, -107.29, 36.64);
var pFeaturefromGeometry1=ee.Feature(pRectangle1);
var pFeaturefromGeometry2=ee.Feature(pRectangle2);
var pFeaturefromGeometry3=ee.Feature(pRectangle3);
var pRec1ContainsRec2=pFeaturefromGeometry1.contains(pFeaturefromGeometry2);
print(pRec1ContainsRec2);
var pRec1ContainsRec3=pFeaturefromGeometry1.contains(pFeaturefromGeometry3);
print(pRec1ContainsRec3);
Map.addLayer(pFeaturefromGeometry1, {'color': COLOR.RED});
Map.addLayer(pFeaturefromGeometry2, {'color': COLOR.BLACK});
Map.addLayer(pFeaturefromGeometry3, {'color': COLOR.GREEN});
Map.setCenter(-107.49, 36.04, 8);
5
8) convexHull(maxError, proj)
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
var COLOR = {
BLACK:'000000',
GREEN:'00ff00'
};
var pPolygon = ee.Geometry.Polygon(-107.49, 36.04, -106.49, 36.84, -108.2, 36.9);
var pFeaturefromPolygon=ee.Feature(pPolygon);
var pConvexHullfromPolygon=pFeaturefromPolygon.convexHull();
print(pFeaturefromPolygon);
print(pConvexHullfromPolygon);
Map.addLayer(pFeaturefromPolygon, {'color': COLOR.BLACK});
Map.addLayer(pConvexHullfromPolygon, {'color': COLOR.GREEN});
Map.setCenter(-107.49, 36.04, 8);
9) copyProperties(source, properties, exclude)
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
var COLOR = {
RED: 'ff0000',
BLACK:'000000',
GREEN:'00ff00'
};
var pRectangle1 = ee.Geometry.Rectangle(-107.49, 36.04, -106.49, 36.84);
var pRectangle2 = ee.Geometry.Rectangle(-107.19, 36.04, -105.49, 36.84);
var pFeature1=ee.Feature(pRectangle1);
var pFeature2=ee.Feature(pRectangle2);
print(pFeature1);
print(pFeature2);
var pFeature1Modified=ee.Feature(pFeature1).set("high_record",40);
var pFeature2Modified=pFeature2.copyProperties(pFeature1Modified);
print(pFeature1Modified);
print(pFeature2Modified);
Map.addLayer(pFeature1Modified, {'color': COLOR.RED});
Map.addLayer(ee.Feature(pFeature2Modified), {'color': COLOR.BLACK});
Map.setCenter(-107.49, 36.04, 8);
10) cutLines(distances, maxError, proj)
1. var COLOR = {
2.
RED: 'ff0000',
3.
BLACK:'000000',
4.
GREEN:'00ff00'
5. };
6
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
var pLineString = ee.Geometry.LineString(-107.49, 36.04, -106.49, 36.84);
var pFeaturefromGeometry=ee.Feature(pLineString);
print(pFeaturefromGeometry);
var pLength=pFeaturefromGeometry.length();
print(pLength);//126171.93754653326
var pCutLines=pLineString.cutLines([pLength.multiply(0.5)]);
print(pCutLines);
print(pCutLines.length());
print(pCutLines.geometries());
print(pCutLines.geometries().get(0));
print(pCutLines.geometries().get(1));
Map.addLayer(pFeaturefromGeometry, {'color': COLOR.RED});
Map.addLayer(pCutLines, {'color': COLOR.BLACK});
Map.setCenter(-107.49, 36.04, 8);
11) difference(right, maxError, proj)
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
var COLOR = {
RED: 'ff0000',
BLACK:'000000',
GREEN:'00ff00'
};
var pRectangle1 = ee.Geometry.Rectangle(-107.49, 36.04, -106.49, 36.84);
var pRectangle2 = ee.Geometry.Rectangle(-107.19, 36.04, -105.49, 36.84);
var pFeaturefromGeometry1=ee.Feature(pRectangle1);
var pFeaturefromGeometry2=ee.Feature(pRectangle2);
var pDifference=pFeaturefromGeometry1.difference(pFeaturefromGeometry2);
print(pDifference);
Map.addLayer(pFeaturefromGeometry1, {'color': COLOR.RED});
Map.addLayer(pFeaturefromGeometry2, {'color': COLOR.BLACK});
Map.addLayer(pDifference, {'color': COLOR.GREEN});
Map.setCenter(-107.49, 36.04, 8);
12) disjoint(right, maxError, proj)
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
var COLOR = {
RED: 'ff0000',
BLACK:'000000',
GREEN:'00ff00'
};
var pRectangle1 = ee.Geometry.Rectangle(-107.49, 36.04, -106.49, 36.84);
var pRectangle2 = ee.Geometry.Rectangle(-106.19, 36.04, -105.49, 36.84);
var pRectangle3 = ee.Geometry.Rectangle(-107.19, 36.04, -105.49, 36.84);
7
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
var pFeaturefromGeometry1=ee.Feature(pRectangle1);
var pFeaturefromGeometry2=ee.Feature(pRectangle2);
var pFeaturefromGeometry3=ee.Feature(pRectangle3);
var p1Disjoint2=pFeaturefromGeometry1.disjoint(pFeaturefromGeometry2);
var p1Disjoint3=pFeaturefromGeometry1.disjoint(pFeaturefromGeometry3);
print(p1Disjoint2);
print(p1Disjoint3);
Map.addLayer(pFeaturefromGeometry1, {'color': COLOR.RED});
Map.addLayer(pFeaturefromGeometry2, {'color': COLOR.BLACK});
Map.addLayer(pFeaturefromGeometry3, {'color': COLOR.GREEN});
Map.setCenter(-107.49, 36.04, 8);
13) dissolve(maxError, proj)
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
var COLOR = {
RED: 'ff0000',
BLACK:'000000',
GREEN:'00ff00'
};
var pLineString = ee.Geometry.LineString(-107.49, 36.04, -106.49, 36.84);
var pFeaturefromGeometry=ee.Feature(pLineString);
var pLength=pFeaturefromGeometry.length();
var pCutLines=pLineString.cutLines([pLength.multiply(0.5)]);
var pDissolvedGeometries=pCutLines.dissolve();
print(pCutLines);
print(pDissolvedGeometries);
Map.addLayer(pFeaturefromGeometry, {'color': COLOR.RED});
Map.addLayer(pCutLines, {'color': COLOR.BLACK});
Map.addLayer(pDissolvedGeometries, {'color': COLOR.GREEN});
Map.setCenter(-107.49, 36.04, 8);
14) distance(right, maxError, proj)
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
var COLOR = {
RED: 'ff0000',
BLACK:'000000',
GREEN:'00ff00'
};
var pRectangle1 = ee.Geometry.Rectangle(-107.49, 36.04, -106.49, 36.84);
var pRectangle2 = ee.Geometry.Rectangle(-106.19, 36.04, -105.49, 36.84);
var pRectangle3 = ee.Geometry.Rectangle(-107.19, 36.04, -105.49, 36.84);
var pFeaturefromGeometry1=ee.Feature(pRectangle1);
var pFeaturefromGeometry2=ee.Feature(pRectangle2);
8
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
var pFeaturefromGeometry3=ee.Feature(pRectangle3);
var pDistance1to2=pFeaturefromGeometry1.distance(pFeaturefromGeometry2);
var pDistance1to3=pFeaturefromGeometry1.distance(pFeaturefromGeometry3);
print(pDistance1to2);
print(pDistance1to3);
Map.addLayer(pFeaturefromGeometry1, {'color': COLOR.RED});
Map.addLayer(pFeaturefromGeometry2, {'color': COLOR.BLACK});
Map.addLayer(pFeaturefromGeometry3, {'color': COLOR.GREEN});
Map.setCenter(-107.49, 36.04, 8);
15) get(property)
1. var statesData = ee.FeatureCollection('ft:1dZ78QI6P_HrZ6oabSKitytOhWM__fI9O1ayP4AoI');
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
print(statesData);
Map.addLayer(statesData);
var filteredRecord=statesData.filter(ee.Filter.gt("high_record", 51.4));
print(filteredRecord);
if(filteredRecord!=null){
print(ee.Feature(filteredRecord.first()).get("high_record"));
}
16) getInfo(callback)
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
var statesData = ee.FeatureCollection('ft:1dZ78QI6P_HrZ6oabSKitytOhWM__fI9O1ayP4AoI');
//Not Ajaxified
print(ee.Feature(statesData.first()).getInfo());
print(ee.Feature(statesData.first()).getInfo().properties);
print(ee.Feature(statesData.first()).getInfo().properties.low_record);
print(ee.Feature(statesData.first()).getInfo().id);
print(ee.Feature(statesData.first()).getInfo().type);
print(ee.Feature(statesData.first()).getInfo().geometry);
print(ee.Feature(statesData.first()).getInfo().geometry.coordinates);
print(ee.Feature(statesData.first()).getInfo().geometry.coordinates[0]);
17) getMap(visParams, callback)
1. var statesData = ee.FeatureCollection('ft:1dZ78QI6P_HrZ6oabSKitytOhWM__fI9O1ayP4AoI');
2. var firstRecord=ee.Feature(statesData.first());
3.
4. print(firstRecord.getMap());
5. print(firstRecord.getMap().mapid);
9
6. print(firstRecord.getMap().token);
7. print(firstRecord.getMap().image);
18) id()
1. var statesData = ee.FeatureCollection('ft:1dZ78QI6P_HrZ6oabSKitytOhWM__fI9O1ayP4AoI');
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
print(statesData);
Map.addLayer(statesData);
var filteredRecord=statesData.filter(ee.Filter.gt("high_record", 44.4));
if (filteredRecord!= null){
var firstRecord=filteredRecord.first();
var firstRecordID=ee.Feature(firstRecord).id();
print(firstRecord);
print(firstRecordID);
}
19) intersection (right, maxError, proj)
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
var COLOR = {
RED: 'ff0000',
BLACK:'000000',
GREEN:'00ff00'
};
var pRectangle1 = ee.Geometry.Rectangle(-107.49, 36.04, -106.49, 36.84);
var pRectangle2 = ee.Geometry.Rectangle(-106.99, 36.04, -105.49, 36.84);
var pFeaturefromGeometry1=ee.Feature(pRectangle1);
var pFeaturefromGeometry2=ee.Feature(pRectangle2);
var pIntersectedRegion=pFeaturefromGeometry1.intersection(pFeaturefromGeometry2);
print(pIntersectedRegion);
Map.addLayer(pFeaturefromGeometry1, {'color': COLOR.RED});
Map.addLayer(pFeaturefromGeometry2, {'color': COLOR.BLACK});
Map.addLayer(pIntersectedRegion, {'color': COLOR.GREEN});
Map.setCenter(-107.49, 36.04, 8);
20) intersects(right, maxError, proj)
1. var COLOR = {
2.
RED: 'ff0000',
3.
BLACK:'000000',
4.
GREEN:'00ff00'
5. };
10
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
var pRectangle1 = ee.Geometry.Rectangle(-107.49, 36.04, -106.49, 36.84);
var pRectangle2 = ee.Geometry.Rectangle(-106.19, 36.04, -105.49, 36.84);
var pFeaturefromGeometry1=ee.Feature(pRectangle1);
var pFeaturefromGeometry2=ee.Feature(pRectangle2);
var pIntersects=pFeaturefromGeometry1.intersects(pFeaturefromGeometry2);
print(pIntersects);
Map.addLayer(pFeaturefromGeometry1, {'color': COLOR.RED});
Map.addLayer(pFeaturefromGeometry2, {'color': COLOR.BLACK});
Map.setCenter(-107.49, 36.04, 8);
21) length (maxError, proj)
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
var COLOR = {
RED: 'ff0000',
BLACK:'000000',
BLUE:'0000ff',
GREEN:'00ff00'
};
var pLineString = ee.Geometry.LineString(-107.49, 36.04, -106.49, 36.84);
var pFeaturefromLineString=ee.Feature(pLineString);
var pLengthLineString=pFeaturefromLineString.length();
var pCutLines=pFeaturefromLineString.cutLines([pLengthLineString.multiply(0.5)]);
var pLengthMultiLineString=pCutLines.length();
var pRectangle = ee.Geometry.Rectangle(-107.49, 36.04, -106.49, 36.84);
var pFeaturefromRectangle=ee.Feature(pRectangle);
var pLengthRectangle=pFeaturefromRectangle.length();
var pLinearRing = ee.Geometry.LinearRing(-107.49, 36.04, -106.49, 36.84, 107.1, 36.5);
20. var pFeaturefromLinearRing=ee.Feature(pLinearRing);
21. var pLengthLinearRing=pFeaturefromLinearRing.length();
22.
23. print(pLengthLineString);
24. print(pLengthMultiLineString);
25. print(pLengthRectangle);
26. print(pLengthLinearRing);
27.
28.
29. Map.addLayer(pFeaturefromLineString, {'color': COLOR.RED});
30. Map.addLayer(pCutLines, {'color': COLOR.BLACK});
31. Map.addLayer(pFeaturefromRectangle, {'color': COLOR.BLUE});
32. Map.addLayer(pFeaturefromLinearRing, {'color': COLOR.GREEN});
33.
34. Map.setCenter(-107.49, 36.04, 8);
11
22) perimeter(maxError, proj)
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
var COLOR = {
RED: 'ff0000',
BLACK:'000000'
};
var pRectangle1 = ee.Geometry.Rectangle(-107.49, 36.04, -106.49, 36.84);
var pRectangle2 = ee.Geometry.Rectangle(-106.49, 36.04, -105.49, 36.84);
var pFeaturefromGeometry1=ee.Feature(pRectangle1);
var pFeaturefromGeometry2=ee.Feature(pRectangle2);
//Coordinate system
var perimeterGeometry1=pFeaturefromGeometry1.perimeter();
var perimeterGeometry2=pFeaturefromGeometry2.perimeter();
print(perimeterGeometry1);
print(perimeterGeometry2);
Map.addLayer(pFeaturefromGeometry1, {'color': COLOR.RED});
Map.addLayer(pFeaturefromGeometry2, {'color': COLOR.BLACK});
Map.setCenter(-107.49, 36.04, 8);
23) propertyNames()
1. var statesData = ee.FeatureCollection('ft:1dZ78QI6P_HrZ6oabSKitytOhWM__fI9O1ayP4AoI');
2. var pFeaturesPropertyList=ee.Feature(statesData.first()).propertyNames();
3.
4. print(pFeaturesPropertyList);
5. print(pFeaturesPropertyList.get(2));
24) select(propertySelectors, newProperties, retainGeometry)
1. var statesData = ee.FeatureCollection('ft:1dZ78QI6P_HrZ6oabSKitytOhWM__fI9O1ayP4AoI');
2. var filteredRecord=statesData.filter(ee.Filter.gt("high_record", 44.4));
3.
4. if(filteredRecord!= null){
5.
var firstRecord=filteredRecord.first();
6.
var pFeaturefromComputedObject=ee.Feature(firstRecord);
7.
var pElementwithSelected=pFeaturefromComputedObject.select(["high_record", "low_recor
d"], ["high", "low"]);
8.
var pFeaturewithSelected=ee.Feature(pElementwithSelected);
9.
10. print(pFeaturefromComputedObject);
11. print(pFeaturewithSelected);
12. }
12
25) set(var_args)
1. var statesData = ee.FeatureCollection('ft:1dZ78QI6P_HrZ6oabSKitytOhWM__fI9O1ayP4AoI');
2. var filteredRecord=statesData.filter(ee.Filter.gt("high_record", 35));
3.
4. if(filteredRecord!=null)
5. {
6.
var firstRecord=statesData.first();
7.
var modifiedFirstRecord=ee.Feature(firstRecord).set("high_record", ee.Number(ee.Featu
re(firstRecord).get("high_record")).multiply(1.2));
8.
print(firstRecord);
9.
print(modifiedFirstRecord);
10. }
26) setGeometry(geometry)
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
var COLOR = {
BLACK:'000000',
GREEN:'00ff00'
};
var pPolygon = ee.Geometry.Polygon(-107.49, 36.04, -106.49, 36.84, -108.2, 36.9);
var pRectangle = ee.Geometry.Rectangle(-107.49, 36.04, -106.49, 36.84);
var pFeaturefromPolygon=ee.Feature(pPolygon);
var pFeaturefromRectangle=ee.Feature(pRectangle);
var pPolygonwithAttributes=pFeaturefromPolygon.set("high_record", 40);
var pRectanglewithAttributes=pPolygonwithAttributes.setGeometry(pRectangle);
print(pFeaturefromPolygon);
print(pFeaturefromRectangle);
print(pPolygonwithAttributes);
print(pRectanglewithAttributes);
Map.addLayer(pPolygonwithAttributes, {'color': COLOR.BLACK});
Map.addLayer(ee.Feature(pRectanglewithAttributes), {'color': COLOR.GREEN});
Map.setCenter(-107.49, 36.04, 8);
27) setMulti(properties)
1. var pPolygon = ee.Geometry.Polygon(-107.49, 36.04, -106.49, 36.84, -108.2, 36.9);
2. var pFeaturefromGeometry=ee.Feature(pPolygon);
3. var pFeaturewithAttributes=pFeaturefromGeometry.setMulti({high_record:35, low_record:40});
4.
5. print(pFeaturefromGeometry);
6. print(pFeaturewithAttributes);
13
28) simplify(maxError, proj)
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
var COLOR = {
RED: 'ff0000',
BLACK:'000000'
};
var pLineString1 = ee.Geometry.LineString(-107.49, 36.04, -106.49, 36.84);
var pLineString2 = ee.Geometry.LineString(-106.49, 36.84, -102.49, 36.14);
var pLineString3 = ee.Geometry.LineString(-102.49, 36.14, -99.49, 36.94);
var pLineString4 = ee.Geometry.LineString(-99.49, 36.94, -106.49, 36.14);
var pMultiLineString=ee.Geometry.MultiLineString([pLineString1, pLineString2, pLineStri
ng3, pLineString4]);
var pFeaturefromMultiLineString=ee.Feature(pMultiLineString);
var pSimplifiedMultiLineString=pFeaturefromMultiLineString.simplify(0.00001);
print(pFeaturefromMultiLineString);
print(pSimplifiedMultiLineString);
Map.addLayer(pFeaturefromMultiLineString, {'color': COLOR.BLACK});
Map.addLayer(pSimplifiedMultiLineString, {'color': COLOR.RED});
Map.setCenter(-107.49, 36.04, 8);
29) symmetricDifference(right, maxError, proj)
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
var COLOR = {
RED: 'ff0000',
BLACK:'000000',
GREEN:'00ff00',
BLUE:'0000ff',
PINK:'FFC0CB'
};
var pRectangle1 = ee.Geometry.Rectangle(-107.49, 36.04, -106.49, 36.84);
var pRectangle2 = ee.Geometry.Rectangle(-107.19, 36.24, -106.79, 36.64);
var pFeaturefromGeometry1=ee.Feature(pRectangle1);
var pFeaturefromGeometry2=ee.Feature(pRectangle2);
var pSymmetricDifference=pFeaturefromGeometry2.symmetricDifference(pFeaturefromGeometry
1);
16. var pDifference1from2=pFeaturefromGeometry2.difference(pFeaturefromGeometry1);
17. var pDifference2from1=pFeaturefromGeometry1.difference(pFeaturefromGeometry2);
18.
19. print(pSymmetricDifference);
20. print(pDifference1from2);
21. print(pDifference2from1);
22.
23. Map.addLayer(pFeaturefromGeometry1, {'color': COLOR.RED});
24. Map.addLayer(pFeaturefromGeometry2, {'color': COLOR.BLACK});
25. Map.addLayer(pSymmetricDifference, {'color': COLOR.GREEN});
26. Map.addLayer(pDifference1from2, {'color': COLOR.BLUE});
14
27. Map.addLayer(pDifference2from1, {'color': COLOR.PINK});
28.
29.
30. Map.setCenter(-107.49, 36.04, 8);
30) toArray(properties)
1. var statesData = ee.FeatureCollection('ft:1dZ78QI6P_HrZ6oabSKitytOhWM__fI9O1ayP4AoI');
2. var filteredRecord=statesData.filter(ee.Filter.gt("high_record", 44.4));
3.
4. if(filteredRecord!= null){
5.
var firstRecord=filteredRecord.first();
6.
var pFeaturefromComputedObject=ee.Feature(firstRecord);
7.
var pFeatureArray=pFeaturefromComputedObject.toArray(["high_record", "low_record"])
8.
9.
print(pFeaturefromComputedObject);
10. print(pFeatureArray);
11. print(pFeatureArray.get([0]));
12. print(pFeatureArray.get([1]));
13.
14. }
31) toDictionary(properties)
1. var statesData = ee.FeatureCollection('ft:1dZ78QI6P_HrZ6oabSKitytOhWM__fI9O1ayP4AoI');
2. var filteredRecord=statesData.filter(ee.Filter.gt("high_record", 44.4));
3.
4. if(filteredRecord!= null){
5.
var firstRecord=filteredRecord.first();
6.
var pFeaturefromComputedObject=ee.Feature(firstRecord);
7.
var pFeatureDictionary=pFeaturefromComputedObject.toDictionary(["high_record", "low_r
ecord"])
8.
9.
print(pFeaturefromComputedObject);
10. print(pFeatureDictionary);
11. print(pFeatureDictionary.keys());
12. print(pFeatureDictionary.values());
13. print(pFeatureDictionary.get("high_record"));
14. }
32) transform(proj, maxError)
1.
var COLOR = {
2.
BLACK:'000000',
3.
GREEN:'00ff00'
4. };
5.
6. var pPolygon = ee.Geometry.Polygon(-107.49, 36.04, -106.49, 36.84, -108.2, 36.9);
7. var pFeaturefromPolygon=ee.Feature(pPolygon);
15
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
var PTransformedPolygon=pFeaturefromPolygon.transform("EPSG:2152", 0.00001);
print(pPolygon.projection());
print(pPolygon.projection().crs());
print(ee.FeatureCollection([PTransformedPolygon]).geometry().projection().crs());
print(ee.FeatureCollection([PTransformedPolygon]).geometry().projection().wkt());
Map.addLayer(pFeaturefromPolygon, {'color': COLOR.GREEN});
Map.addLayer(PTransformedPolygon, {'color': COLOR.BLACK});
Map.setCenter(-107.49, 36.04, 8);
33) union(right, maxError, proj)
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
var COLOR = {
RED: 'ff0000',
BLACK:'000000',
GREEN:'00ff00'
};
var pRectangle1 = ee.Geometry.Rectangle(-107.49, 36.04, -106.49, 36.84);
var pRectangle2 = ee.Geometry.Rectangle(-106.49, 36.04, -105.49, 36.84);
var pFeaturefromGeometry1=ee.Feature(pRectangle1);
var pFeaturefromGeometry2=ee.Feature(pRectangle2);
var pUnion=pFeaturefromGeometry1.union(pFeaturefromGeometry2);
print(pUnion);
Map.addLayer(pFeaturefromGeometry1, {'color': COLOR.RED});
Map.addLayer(pFeaturefromGeometry2, {'color': COLOR.BLACK});
Map.addLayer(pUnion, {'color': COLOR.GREEN});
Map.setCenter(-107.49, 36.04, 8);
34) withinDistance(right, distance, maxError, proj)
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
var COLOR = {
RED: 'ff0000',
BLACK:'000000',
GREEN:'00ff00'
};
var pRectangle1 = ee.Geometry.Rectangle(-107.49, 36.04, -106.49, 36.84);
var pRectangle2 = ee.Geometry.Rectangle(-106.19, 36.04, -105.49, 36.84);
var pFeaturefromGeometry1=ee.Feature(pRectangle1);
var pFeaturefromGeometry2=ee.Feature(pRectangle2);
//The actual distance between the features is 26759.334062457332
var pWithInDistance1to2=pFeaturefromGeometry1.withinDistance(pFeaturefromGeometry2, 267
59.234062457332);
15.
16
16.
17.
18.
19.
20.
21.
print(pWithInDistance1to2);
Map.addLayer(pFeaturefromGeometry1, {'color': COLOR.RED});
Map.addLayer(pFeaturefromGeometry2, {'color': COLOR.BLACK});
Map.setCenter(-107.49, 36.04, 8);
References
Google Earth Engine Team, 2015. Google Earth Engine: A planetary-scale geospatial analysis platform.
https://earthengine.google.com
17