Google Earth Engine(GEE)——用10米分辨率土地分类数据进行土地面积计算出现错误
【摘要】
错误:
FeatureCollection (Error)
Error in map(ID=0): Feature, argument 'geometry': Invalid type. Expected type: Geometry. Actual type: Feature.
原始代码:
var bo...
错误:
FeatureCollection (Error)
Error in map(ID=0): Feature, argument 'geometry': Invalid type. Expected type: Geometry. Actual type: Feature.
原始代码:
-
var boten = ee.FeatureCollection("projects/ee-suraj7-28/assets/Boten");
-
var boten_shp = boten.geometry()
-
var Lunagprabang = ee.FeatureCollection("projects/ee-suraj7-28/assets/Luangprabang");
-
var Lunagprabang_shp = Lunagprabang.geometry()
-
var Vientiana = ee.FeatureCollection("projects/ee-suraj7-28/assets/Vientiana");
-
var Vientiana_shp = Vientiana.geometry()
-
-
// Buffer//
-
var boten_buffer=boten_shp.buffer(20000)
-
var Lunagprabang_buffer=Lunagprabang_shp.buffer(20000)
-
var Vientiana_buffer=Vientiana_shp.buffer(20000)
-
-
-
var features = ee.FeatureCollection([
-
ee.Feature(boten_buffer, {label: 'Boten'}),
-
ee.Feature(Lunagprabang_buffer, {label: 'Lunagprabang'}),
-
ee.Feature(Vientiana_buffer, {label: 'vientiana'}),
-
])
-
print(features)
-
-
var years = ee.List.sequence(2021,2022)
-
-
-
var calculateClassAreaByYear = features.map(function(feature){
-
var dw2=years.map(function(year){
-
var dw1= ee.ImageCollection('GOOGLE/DYNAMICWORLD/V1')
-
.filterDate(ee.Date.fromYMD(year, 1, 1), ee.Date.fromYMD(year, 12, 1)).filter(ee.Filter.bounds(feature)).select('label').reduce(ee.Reducer.mode()).eq(6);
-
return dw1
-
})
-
return ee.FeatureCollection(dw2)
-
})
-
-
print(calculateClassAreaByYear.flatten())
我们这里可以看到提示期待的类型不对,需求的类型是几何图形,但是这里给的确实矢量,所以我们需要再后面加一个.geometry()
修改后的代码:
-
-
var years = ee.List.sequence(2021,2022)
-
-
-
var calculateClassAreaByYear = features.map(function(feature){
-
var dw2=years.map(function(year){
-
var dw1= ee.ImageCollection('GOOGLE/DYNAMICWORLD/V1')
-
.filterDate(ee.Date.fromYMD(year, 1, 1), ee.Date.fromYMD(year, 12, 31)).filter(ee.Filter.bounds(feature.geometry())).select('label').reduce(ee.Reducer.mode()).eq(6);
-
var areaImage = dw1.multiply(ee.Image.pixelArea())
-
var area = areaImage.reduceRegion({
-
reducer: ee.Reducer.sum(),
-
geometry: feature.geometry(),
-
scale: 10,
-
maxPixels: 1e10
-
})
这里有一个矢量面积的计算函数:
ee.Image.pixelArea()
Generate an image in which the value of each pixel is the area of that pixel in square meters. The returned image has a single band called "area."
ee.Image.pixelArea()
生成一个图像,其中每个像素的值是该像素的面积,单位是平方米。返回的图像有一个称为 "面积 "的单带。
文章来源: blog.csdn.net,作者:此星光明,版权归原作者所有,如需转载,请联系作者。
原文链接:blog.csdn.net/qq_31988139/article/details/126406202
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)