JavaScript中Feature和FeatureCollection数据类型

张昊穹
2023-12-01

一、描述
feature是带属性的geometry,他除了能进行geometry的空间操作,还能进行相关的属性操作
二、基本语法
Feature

函数表达函数描述
var Feature_Fobidden_City = ee.Feature(geometry_City,{name:‘故宫’, location:‘北京’})添加属性
var Feature_select_1 = Feature_City.select([‘name’],[‘名称’])有点起到按属性拷贝的作用,若只有[‘name’],就简单拷贝,但这个是拷贝后并将那么命名为名称,若名称处为location也是拷贝,同时拷贝了name和location属性
var Feature_Set = Feature_Fobidden_City.set(‘name’,‘Gugong’, ‘location’,‘Beijing’)属性设置
var Feature_Set_Multi = Feature_Fobidden_City.setMulti({‘name’:'紫禁城 ', ‘location’:'首都 '})多属性设置
var TGR_geometry = feature_city.geometry();提取feature_city的空间信息
var TGR_get = TGR.get(‘name’)得到对应的属性值

FeatureCollection

函数表达函数描述
var Proction_Area_China = featurecollection_Area.filterMetadata(‘ISO3’,‘equals’,‘CHN’)进行属性筛选,(筛选字段,关系,筛选值)
greater_than”,“not_equals”,“not_less_than”,“not_greater_than”,“starts_with”,“ends_with”,“not_starts_with”, “not_ends_with”, “contains”,“not_contains常见的筛选关系
featurecollection_Area.limit(5,‘Shape_Area’,false)数量限制命令常用来观察数据,(最大数,[限制字段],[是否从小到大])
featurecollection_Area.filterDate(‘2019-03-01’,‘2019-03-16’)日期限制
var China_Area = featurecollection_Area.select([‘NAME’,‘Shape_Area’])相当于复制操作
var China_Area = featurecollection_Area.distinct([‘NAME’])去除具有相同属性 Feature
var China_Union = featurecollection_Area.union()联合
var CQ_SC_Merge = Chongqing.merge(Si_Chuan)
var CQ_SC_Merge_Set = CQ_SC_Merge.set(‘NAME’,‘Chuan_Yu’)属性改写
var China_Remap = China_Provinces.remap(Old_Provinces_ID,New_Provinces_ID,‘OBJECTID’)重分类,(修改前的值,只改后的值,要修改的key)
var China_Sort_Area = China_Provinces.sort(‘Shape_Area’,false)排序,排序字段,排序方式-false代表从大到小
var China_Geometry = featurecollection_Area.geometry()提取几何信息
var China_to_Image = China_Provinces.reduceToImage([‘OBJECTID’],ee.Reducer.first())矢量转栅格 (依据字段,数据处理),利用 ee.Reducer.first()的目的是不对数值进行任何处理
var China_List = featurecollection_Area.sort(‘Shape_Area’,false).toList(10)将 featurecollection转化为list,方便处理数据,如:var Area_No_1 = ee.Feature(China_List.get(0)),得到第一个feature
.mapfeaturecollection具有map操作,就是对每个feature进行同样的操作
 类似资料: