目录
生成随机点:FeatureCollection.randomPoints()
FeatureCollection中limit()、sort()
FeatureCollection中的filterBounds()、filterMetadata()
FeatureCollection中的first()、select()
FeatureCollection中的get、set、setMulti
矢量转栅格:FeatureCollection.reduceToImage()
Feature Collection属性统计命令:Feature Collection.aggregate_array()等
基本结构
FeatureCollection.geometry()
生成随机点:FeatureCollection.randomPoints()
FeatureCollection中limit()、sort()
参数中true表示升序,false表示降序
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))
FeatureCollection中的filterBounds()、filterMetadata()
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'})
FeatureCollection中的first()、select()
var fc_sichuan = ee.FeatureCollection("users/lcljv1066965/test/sichuan");
print(fc_sichuan.first())
print(fc_sichuan.limit(3).select(['name','adcode']))
FeatureCollection.union()
union:联合。其效果是形成一个单独的Feature,并且抹去所有属性
FeatureCollection.merge()
合并:将两个数据集合并起来
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))
FeatureCollection中的get、set、setMulti
在使用set时,如果属性没有,则添加;如果有,则更新
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}))
矢量转栅格: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属性统计命令:Feature Collection.aggregate_array()等
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"))
下边是GEE中Feature Collection相关的属性统计命令:
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'})