Google Earth Engine(GEE)——影像分类中出现的错误(Classifier confusionMatrix: Property ‘type‘ of feature ‘000000)

简介: Google Earth Engine(GEE)——影像分类中出现的错误(Classifier confusionMatrix: Property ‘type‘ of feature ‘000000)

问题:

I'm trying to use a classifier to classify the land use of Landsat images, but when I use the function which is "classifier. conflusionMatrix", I get an error as follows: Classifier confusionMatrix: Property 'type' of feature '00000000000000000014_ 0' is missing.  (Error code: 3). I don't know how to correct it. I really need your help to solve this problem. By the way, I finally remembered to share the assets.

我正在尝试使用分类器对 Landsat 图像的土地利用进行分类,但是当我使用“classifier.conflusionMatrix”函数时,出现如下错误:Classifier confusionMatrix: Property 'type' of feature '000000000000000000014_ 0 ' 不见了。 (错误代码:3)。我不知道如何纠正它。我真的需要你的帮助来解决这个问题。对了,我终于记得分享资产了。

This is the link:

https://code.earthengine.google.com/d789c5e1a86b1406dbb93d5d9420d4a5?noload=1

 

代码:

var table = ee.FeatureCollection("users/yongxin/henan_bese"),
    table3 = ee.FeatureCollection("users/yongxin/zhengzhou_sample");
//确定区域
var table = ee.FeatureCollection("users/yongxin/henan_bese");
var roi = ee.Geometry.Point([113.663221,34.7568711]);
var sCol = table.filterBounds(roi);
Map.centerObject(sCol,6);
Map.addLayer(sCol,{color:"red"},"zhengzhou");
/** 
forest 0 
urban 1 
paddyrice 2 
water 3 
crop 4 
*/  
//iazai加载yangbendianshujv加载样本点数据
var sampleData = ee.FeatureCollection("users/yongxin/zhengzhou_sample");
Map.addLayer(sampleData, {}, "sampleData");  
//Landsat8 SR数据去云  
function rmCloud(image) {  
  var cloudShadowBitMask = (1 << 3);  
  var cloudsBitMask = (1 << 5);  
  var qa = image.select("pixel_qa");  
  var mask = qa.bitwiseAnd(cloudShadowBitMask).eq(0)  
                 .and(qa.bitwiseAnd(cloudsBitMask).eq(0));  
  return image.updateMask(mask);  
}  
//缩放  
function scaleImage(image) {  
  var time_start = image.get("system:time_start");  
  image = image.multiply(0.0001);  
  image = image.set("system:time_start", time_start);  
  return image;  
}  
//NDVI  
function NDVI(image) {  
  return image.addBands(  
    image.normalizedDifference(["B5", "B4"])  
         .rename("NDVI"));  
}  
//NDWI  
function NDWI(image) {  
  return image.addBands(  
    image.normalizedDifference(["B3", "B5"])  
         .rename("NDWI"));  
}  
//NDBI  
function NDBI(image) {  
  return image.addBands(  
    image.normalizedDifference(["B6", "B5"])  
         .rename("NDBI"));  
}  
//加载影像数据(未分类的Landsat影像数据)
var l8Col = ee.ImageCollection("LANDSAT/LC08/C01/T1_SR")  
              .filterBounds(sCol)  
              .filterDate("2016-1-1", "2017-1-1")  
              .map(rmCloud)  
              .map(scaleImage)  
              .map(NDVI)  
              .map(NDWI)  
              .map(NDBI);  
              
//DEM  
var srtm = ee.Image("USGS/SRTMGL1_003");  
var dem = ee.Algorithms.Terrain(srtm);  
var elevation = dem.select("elevation");  
var slope = dem.select("slope");  
//定义波段
var bands = [  
  "B1", "B2", "B3", "B4", "B5", "B6", "B7",  
  "NDBI", "NDWI", "NDVI","SLOPE", "ELEVATION"  
]; 
//影像处理
var l8Image = l8Col.median()  
                   .addBands(elevation.rename("ELEVATION"))  
                   .addBands(slope.rename("SLOPE"))  
                   .clip(sCol)  
                   .select(bands); 
                   
//rgb参数设置
var rgbVisParam = {  
  min: 0,  
  max: 0.3,  
  bands: ["B4", "B3", "B2"]  
}; 
Map.addLayer(l8Image, rgbVisParam, "l8Image");  
//切分生成训练数据和验证数据  
sampleData = sampleData.randomColumn('random');  
var sample_training = sampleData.filter(ee.Filter.lte("random", 0.7));   
var sample_validate  = sampleData.filter(ee.Filter.gt("random", 0.7));  
  
print("sample_training", sample_training);  
print("sample_validate", sample_validate);  
// //生成监督分类训练使用的样本数据  
// var training = l8Image.sampleRegions({  
//   collection: sample_training,   
//   properties: ["type"],   
//   scale: 30  
// });  
// //生成监督分类验证使用的样本数据  
// var validation = l8Image.sampleRegions({  
//   collection: sample_validate,   
//   properties: ["type"],   
//   scale: 30  
// });  
// //初始化分类器  
// var classifier = ee.Classifier.smileCart().train({  
//   features: training,   
//   classProperty: "type",  
//   inputProperties: bands  
// }); 
//生成监督分类训练使用的样本数据  
var training = l8Image.sampleRegions({  
  collection: sample_training,   
  properties: ["class"],   
  scale: 30  
});  
//生成监督分类验证使用的样本数据  
var validation = l8Image.sampleRegions({  
  collection: sample_validate,   
  properties: ["class"],   
  scale: 30  
});  
//初始化分类器  
var classifier = ee.Classifier.smileCart().train({  
  features: training,   
  classProperty: "class",  
  inputProperties: bands  
});  
//影像数据调用classify利用训练数据训练得到分类结果  
var classified = l8Image.classify(classifier);  
//训练结果的混淆矩阵  
var trainAccuracy = classifier.confusionMatrix();  
//导出训练精度结果CSV  
Export.table.toDrive({  
  collection: ee.FeatureCollection([  
    ee.Feature(null, {  
      matrix: trainAccuracy.array(),  
      kappa: trainAccuracy.kappa(),  
      accuracy: trainAccuracy.accuracy()  
    }  
  )]),  
  description: "l8TrainConf_zhengzhou",  
  folder:"training_zhengzhou",  
  fileFormat: "CSV"  
});  
//导出影像  
var resultImg = classified.clip(sCol).toByte();  
resultImg = resultImg.remap([0,1,2,3,4], [1,2,3,4,5]);  
Export.image.toAsset({  
  image: resultImg,   
  description: 'Asset-l8Classifiedmap_zhengzhou',  
  assetId: "training_zhengzhou/l8Classifiedmap_zhengzhou",  
  region: sCol,  
  scale:30,  
  crs: "EPSG:4326",  
  maxPixels: 1e13  
});  
//影像导出
Export.image.toDrive({  
  image:resultImg,  
  description:'Drive-l8Classifiedmap_zhengzhou',  
  fileNamePrefix: "l8Classifiedmap_zhengzhou",  
  folder:"training_zhengzhou",  
  region: sCol,  
  scale:30,  
  crs: "EPSG:4326",  
  maxPixels:1e13  
});

我们根据提示可以看出,文件中不存在属性,所以我们需要查看我们打印或者输出的结果中到底有没有这个属性,可以看到这个属性中并没有“type”属性。我们要注意的是这里我们所需的不是矢量文件中每个属性,这是值得注意的,这里选择的就是分类后产生的新的分类属性。

矢量中的类型“type”代表的并不是属性列表,而是表明矢量类型就是矢量。

 

需要修改的代码:

//生成监督分类训练使用的样本数据  
var training = l8Image.sampleRegions({  
  collection: sample_training,   
  properties: ["class"],   
  scale: 30  
});  
//生成监督分类验证使用的样本数据  
var validation = l8Image.sampleRegions({  
  collection: sample_validate,   
  properties: ["class"],   
  scale: 30  
});  
//初始化分类器  
var classifier = ee.Classifier.smileCart().train({  
  features: training,   
  classProperty: "class",  
  inputProperties: bands  
});

修改后成功的下载结果

 

相关文章
|
3月前
|
数据可视化 定位技术 Sentinel
如何用Google Earth Engine快速、大量下载遥感影像数据?
【2月更文挑战第9天】本文介绍在谷歌地球引擎(Google Earth Engine,GEE)中,批量下载指定时间范围、空间范围的遥感影像数据(包括Landsat、Sentinel等)的方法~
580 0
如何用Google Earth Engine快速、大量下载遥感影像数据?
|
3月前
|
编解码 人工智能 算法
Google Earth Engine——促进森林温室气体报告的全球时间序列数据集
Google Earth Engine——促进森林温室气体报告的全球时间序列数据集
27 0
|
3月前
|
机器学习/深度学习 算法 数据可视化
基于Google Earth Engine云平台构建的多源遥感数据森林地上生物量AGB估算模型含生物量模型应用APP
基于Google Earth Engine云平台构建的多源遥感数据森林地上生物量AGB估算模型含生物量模型应用APP
107 0
|
3月前
GEE——Google dynamic world中在影像导出过程中无法完全导出较大面积影像的解决方案(投影的转换)EPSG:32630和EPSG:4326的区别
GEE——Google dynamic world中在影像导出过程中无法完全导出较大面积影像的解决方案(投影的转换)EPSG:32630和EPSG:4326的区别
41 0
|
3月前
|
API Go 网络架构
GEE Colab——如何从本地/Google云盘/Google Cloud Storage (GCS)上传和下载
GEE Colab——如何从本地/Google云盘/Google Cloud Storage (GCS)上传和下载
96 4
|
3月前
|
机器学习/深度学习 存储 人工智能
GEE Colab——初学者福音快速入门 Google Colab(Colaboratory)
GEE Colab——初学者福音快速入门 Google Colab(Colaboratory)
74 3
|
3月前
|
数据处理
Google Earth Engine(GEE)——sentinel-1数据处理过程中出现错误Dictionary does not contain key: bucketMeans
Google Earth Engine(GEE)——sentinel-1数据处理过程中出现错误Dictionary does not contain key: bucketMeans
30 0
|
3月前
|
编解码 人工智能 数据库
Google Earth Engine(GEE)——全球道路盘查项目全球道路数据库
Google Earth Engine(GEE)——全球道路盘查项目全球道路数据库
46 0
|
3月前
|
编解码
Open Google Earth Engine(OEEL)——matrixUnit(...)中产生常量影像
Open Google Earth Engine(OEEL)——matrixUnit(...)中产生常量影像
23 0
|
3月前
Google Earth Engine(GEE)——导出指定区域的河流和流域范围
Google Earth Engine(GEE)——导出指定区域的河流和流域范围
49 0