FeatureCollection in Google Earth Engine (gee)

table of Contents

basic structure

FeatureCollection.geometry()

Generate random points: FeatureCollection.randomPoints()

FeatureCollection中limit()、sort()

FilterBounds(), filterMetadata() in FeatureCollection

First(), select() in FeatureCollection

FeatureCollection.union()

FeatureCollection.merge()

Get, set, setMulti in FeatureCollection

Vector to raster: FeatureCollection.reduceToImage()

FeatureCollection.toList()

Feature Collection attribute statistics commands: Feature Collection.aggregate_array() etc.

Feature Collection.map()


 

basic structure

FeatureCollection.geometry()

Generate random points: FeatureCollection.randomPoints()

FeatureCollection中limit()、sort()

In the parameter, true means ascending order, false means descending order

var fc_sichuan = ee.FeatureCollection("users/lcljv1066965/test/sichuan");

print("fc_sichuan",fc_sichuan)
print("fc_sichuan.limit(1)",fc_sichuan.limit(1))
print("subFeature_asc",fc_sichuan.limit(3,'subFeature',true))
print("sort_asc",fc_sichuan.sort('subFeature',true).limit(3))

FilterBounds(), filterMetadata() in FeatureCollection

var fc_sichuan = ee.FeatureCollection("users/lcljv1066965/test/sichuan");

Map.centerObject(fc_sichuan)

Map.addLayer(fc_sichuan)
Map.addLayer(fc_sichuan.filterBounds(ee.Geometry.Point([104.091,30.598])),{color:'FF0000'})
Map.addLayer(fc_sichuan.filterMetadata('name','equals','绵阳市'),{color:'FFF000'})

First(), select() in FeatureCollection

var fc_sichuan = ee.FeatureCollection("users/lcljv1066965/test/sichuan");
print(fc_sichuan.first())
print(fc_sichuan.limit(3).select(['name','adcode']))

FeatureCollection.union()

union: Union. The effect is to form a single Feature and erase all attributes

FeatureCollection.merge()

Merge: merge two data sets

var fc_sichuan = ee.FeatureCollection("users/lcljv1066965/test/sichuan");
var chengdu=fc_sichuan.filterMetadata('name','equals','成都市')
var deyang=fc_sichuan.filterMetadata('name','equals','德阳市')

Map.centerObject(fc_sichuan)

Map.addLayer(fc_sichuan,{},"fc_sichuan")
Map.addLayer(chengdu,{color:'FF0000'},"chengdu")
Map.addLayer(deyang,{color:'FFF000'},"deyang")
Map.addLayer(chengdu.merge(deyang),{color:'00ff00'},"merge")

print(chengdu)
print(deyang)
print(chengdu.merge(deyang))

Get, set, setMulti in FeatureCollection

When using set, if the attribute does not exist, add it; if it has, update it

var fc =ee.FeatureCollection(ee.Geometry.Point([95.169, 34.513]));
      
print(fc)
print(fc.set('create','lijiang'))
print(fc.set('create','lijiang').get('create'))
print(ee.FeatureCollection(fc.set('create','lijiang')).set('create','xiaoming'))
print(fc.setMulti({"create":"lijiang","age":22}))

Vector to raster: FeatureCollection.reduceToImage()

var fc_sichuan = ee.FeatureCollection("users/lcljv1066965/test/sichuan");

var sichuan_toImage=fc_sichuan.reduceToImage(['subFeature'],ee.Reducer.first())

Map.centerObject(fc_sichuan)
Map.addLayer(fc_sichuan,{},"fc_sichuan")
Map.addLayer(sichuan_toImage,{"min":1,"max":30,"palette":["ff9c07","f0ff1b","1aff0b"]},"sichuan_toImage")

print("fc_sichuan",fc_sichuan)
print("sichuan_toImage",sichuan_toImage)

FeatureCollection.toList()

var fc_sichuan = ee.FeatureCollection("users/lcljv1066965/test/sichuan");

print("fc_sichuan",fc_sichuan)
print(fc_sichuan.toList(5))
print(fc_sichuan.toList(5).get(0))

Feature Collection attribute statistics commands: Feature Collection.aggregate_array() etc.

var fc_sichuan = ee.FeatureCollection("users/lcljv1066965/test/sichuan");

print(fc_sichuan)
print(fc_sichuan.aggregate_array("subFeature"))
print(fc_sichuan.aggregate_stats("subFeature"))
print("aggregate_first",fc_sichuan.aggregate_first("subFeature"))
print("aggregate_max",fc_sichuan.aggregate_max("subFeature"))
print("aggregate_count",fc_sichuan.aggregate_count("subFeature"))

The following are the attribute statistics commands related to Feature Collection in GEE:

Feature Collection.map()

var fc_sichuan = ee.FeatureCollection("users/lcljv1066965/test/sichuan");

function Add_Center (feature){
  return feature.centroid()
}

print("fc_sichuan",fc_sichuan.limit(3))
print("fc_sichuan.map(Add_Center)",fc_sichuan.map(Add_Center).limit(3))

Map.centerObject(fc_sichuan)
Map.addLayer(fc_sichuan)
Map.addLayer(fc_sichuan.map(Add_Center),{color:'ff0000'})

 

Guess you like

Origin blog.csdn.net/qq_40323256/article/details/110203913