GEE土地分类——Property ‘B1‘ of feature ‘LE07_066018_20220603‘ is missing.错误

简介: GEE土地分类——Property ‘B1‘ of feature ‘LE07_066018_20220603‘ is missing.错误

简介:

我正在尝试使用我在研究区域中选择的训练点对图像集合中的每个图像进行分类。就背景而言,我正在进行的项目正在研究陆地卫星生命周期内冰川面积的变化以及随后的植被变化。这意味着自 1984 年以来,我正在处理大量图像,每年一到两张。因此,我真的很希望拥有可以映射集合的函数,而不必手动执行此操作。

当我将分类器映射到 imageCollection 或采样图像后创建的 featureCollection 时,我在这篇文章的主题行中收到错误。

这是一个简化的代码来向您展示我的问题:

https://code.earthengine.google.com/0a7f4a322e18e8cb666acfef63b00d14

错误:

model

FeatureCollection (Error)

Property 'B1' of feature 'LE07_066018_20220603' is missing.

classifiedImages

ImageCollection (Error)

Property 'B1' of feature 'LE07_066018_20220603' is missing.

原始代码:

var wtrshd = ee.FeatureCollection("users/masonbull/nj_wtrshd_ocean"),
    classes = ee.FeatureCollection("projects/ee-masonbull/assets/allClasses");
//identify my classes for classification
var classes = ee.FeatureCollection('projects/ee-masonbull/assets/allClasses');
var wtrshd = ee.FeatureCollection('users/masonbull/nj_wtrshd_ocean');
//set start and end date to get imagery
var date_i = '1999-03-01'; // set initial date (YYYY-MM-DD)
var date_f = '2023-06-30'; // Set final date (YYY-MM-DD)
//grab landsat 7 data
var l7 = ee.ImageCollection("LANDSAT/LE07/C02/T1_RT")
  .filterDate(date_i, date_f)
  .filter(ee.Filter.calendarRange(5, 10, 'month'))
  .filterBounds(ee.Geometry.Point(-148.8904089876178,60.362297433254604))
  .select('B1', 'B2', 'B3', 'B4', 'B5', 'B7', 'B8')
  .filter(ee.Filter.lte('CLOUD_COVER_LAND', 25));
//create a function to clip all of the imagery to the watershed boundaries
var clipping = function(image) {
  return image.clip(wtrshd);
};
var l7_clip = l7.map(clipping);
print(l7_clip);
//define bands and a label for the sampling
var l7Bands = ['B1', 'B2', 'B3', 'B4', 'B5', 'B7', 'B8'];
var label = 'Class';
//create a funciton to sample each image in the imageCollection
var sampleCollectionFunc = function(image){
  var sampler =  image.sampleRegions({
  'collection': classes,
  'properties': [label],
  'scale': 30,
  'geometries': true
});
return sampler;
};
var sampleCollection = l7_clip.map(sampleCollectionFunc);
print('sampleCollection', sampleCollection);
//add random column to sampled images (now featureCollections)
var addRandomFunc = function(FeatureCollection){
  var random = ee.FeatureCollection(FeatureCollection).randomColumn({'seed': 0, 'distribution': 'uniform'});
  return ee.FeatureCollection(random).set('band_order', ['B1', 'B2', 'B3', 'B4', 'B5', 'B7', 'B8', 'NDSI', 'elevation']);
};
var randomCollection = sampleCollection.map(addRandomFunc);
//create training data from random column
var createTraining = function(in_FeatureCollection){
  var filter = ee.FeatureCollection(in_FeatureCollection).filter(ee.Filter.lt('random', 0.8));
  return filter;
};
var training = randomCollection.map(createTraining);
//train the classifier, in this case an SVM
var classifierSVM = ee.Classifier.libsvm({'decisionProcedure': 'Voting',
 'svmType': 'C_SVC', 
 'kernelType': 'RBF', 
 'shrinking': true,
 'gamma': 0.00125,
 'cost': null}).train({
 'features': training,
 'classProperty': label,
 'inputProperties': l7Bands,
 'subsamplingSeed':0
 });
 
//create a function to map over the feature and imageCollections to classify them 
var classSamp = function(FeatureCollection){
  return ee.FeatureCollection(FeatureCollection).classify(classifierSVM, 'predicted');
};
var model = ee.FeatureCollection(sampleCollection).map(classSamp);
print('model', model);
var imageClassifier = function(image){
  return image.classify(classifierSVM, 'predicted');
};
var classVisParams = {min: 0, max: 5, 'palette': ['062EF5', 'E8EAF5', 'E5330C', '0E5B07', '938507', '00EF12']};
var classifiedImages = l7_clip.map(imageClassifier);
print('classifiedImages', classifiedImages);

解决方案:

这里主要的问题在于我们给svm分类器的训练数据传参的时候出现了一个问题,也就是,训练数据需要的是一个矢量集合,而这里我们可以看到经过下面代码处理后的并不是一个矢量集合,而是集合中嵌套的集合

var training = randomCollection.map(createTraining)

这里我们使用flatten()函数来减少一个嵌套就可以分析了

函数:

train(features, classProperty, inputProperties, subsampling, subsamplingSeed)

Trains the classifier on a collection of features, using the specified numeric properties of each feature as training data. The geometry of the features is ignored.

Arguments:

this:classifier (Classifier):

An input classifier.

features (FeatureCollection):

The collection to train on.

classProperty (String):

The name of the property containing the class value. Each feature must have this property, and its value must be numeric.

inputProperties (List, default: null):

The list of property names to include as training data. Each feature must have all these properties, and their values must be numeric. This argument is optional if the input collection contains a 'band_order' property, (as produced by Image.sample).

subsampling (Float, default: 1):

An optional subsampling factor, within (0, 1].

subsamplingSeed (Integer, default: 0):

A randomization seed to use for subsampling.

Returns: Classifier

flatten()

Flattens collections of collections.

Arguments:

this:collection (FeatureCollection):

The input collection of collections.

Returns: FeatureCollection

修改后的代码:

var wtrshd = ee.FeatureCollection("users/masonbull/nj_wtrshd_ocean"),
    classes = ee.FeatureCollection("projects/ee-masonbull/assets/allClasses");
//identify my classes for classification
var classes = ee.FeatureCollection('projects/ee-masonbull/assets/allClasses');
var wtrshd = ee.FeatureCollection('users/masonbull/nj_wtrshd_ocean');
//set start and end date to get imagery
var date_i = '1999-03-01'; // set initial date (YYYY-MM-DD)
var date_f = '2023-06-30'; // Set final date (YYY-MM-DD)
//grab landsat 7 data
var l7 = ee.ImageCollection("LANDSAT/LE07/C02/T1_RT")
  .filterDate(date_i, date_f)
  .filter(ee.Filter.calendarRange(5, 10, 'month'))
  .filterBounds(ee.Geometry.Point(-148.8904089876178,60.362297433254604))
  .select('B1', 'B2', 'B3', 'B4', 'B5', 'B7', 'B8')
  .filter(ee.Filter.lte('CLOUD_COVER_LAND', 25));
//create a function to clip all of the imagery to the watershed boundaries
var clipping = function(image) {
  return image.clip(wtrshd);
};
var l7_clip = l7.map(clipping);
print(l7_clip);
//define bands and a label for the sampling
var l7Bands = ['B1', 'B2', 'B3', 'B4', 'B5', 'B7', 'B8'];
var label = 'Class';
//create a funciton to sample each image in the imageCollection
var sampleCollectionFunc = function(image){
  var sampler =  image.sampleRegions({
  'collection': classes,
  'properties': [label],
  'scale': 30,
  'geometries': true
});
return sampler;
};
var sampleCollection = l7_clip.map(sampleCollectionFunc);
print('sampleCollection', sampleCollection);
//add random column to sampled images (now featureCollections)
var addRandomFunc = function(FeatureCollection){
  var random = ee.FeatureCollection(FeatureCollection).randomColumn({'seed': 0, 'distribution': 'uniform'});
  return ee.FeatureCollection(random).set('band_order', ['B1', 'B2', 'B3', 'B4', 'B5', 'B7', 'B8', 'NDSI', 'elevation']);
};
var randomCollection = sampleCollection.map(addRandomFunc);
//create training data from random column
var createTraining = function(in_FeatureCollection){
  var filter = ee.FeatureCollection(in_FeatureCollection).filter(ee.Filter.lt('random', 0.8));
  return filter;
};
var training = randomCollection.map(createTraining).flatten();
//train the classifier, in this case an SVM
var classifierSVM = ee.Classifier.libsvm({'decisionProcedure': 'Voting',
 'svmType': 'C_SVC', 
 'kernelType': 'RBF', 
 'shrinking': true,
 'gamma': 0.00125,
 'cost': null}).train({
 'features': training,
 'classProperty': label,
 'inputProperties': l7Bands,
 'subsamplingSeed':0
 });
 
//create a function to map over the feature and imageCollections to classify them 
var classSamp = function(FeatureCollection){
  return ee.FeatureCollection(FeatureCollection).classify(classifierSVM, 'predicted');
};
var model = ee.FeatureCollection(sampleCollection).map(classSamp);
print('model', model.first());
var imageClassifier = function(image){
  return image.classify(classifierSVM, 'predicted');
};
var classVisParams = {min: 0, max: 5, 'palette': ['062EF5', 'E8EAF5', 'E5330C', '0E5B07', '938507', '00EF12']};
var classifiedImages = l7_clip.map(imageClassifier);
print('classifiedImages', classifiedImages.first());

额外问题

除了上面的问题外,还会出现超限的问题:

model

FeatureCollection (Error)

User memory limit exceeded.

classifiedImages

ImageCollection (Error)

User memory limit exceeded.

出现上面问题的时候我们就不要在云端通过打印的方式来进行了,直接可以通过导出数据的方式来实现影像分类后的结果。

相关文章
|
6月前
Google Earth Engine(GEE)——当加载图表的时候出现错误No features contain non-null values of “system:time_start“.
Google Earth Engine(GEE)——当加载图表的时候出现错误No features contain non-null values of “system:time_start“.
120 0
|
6月前
|
编解码
Google Earth Engine(GEE)——监督分类出现ConfusionMatrix (Error) User memory limit exceeded.解决方案
Google Earth Engine(GEE)——监督分类出现ConfusionMatrix (Error) User memory limit exceeded.解决方案
185 0
|
6月前
Google Earth Engine(GEE)——影像分类中出现的错误(Classifier confusionMatrix: Property ‘type‘ of feature ‘000000)
Google Earth Engine(GEE)——影像分类中出现的错误(Classifier confusionMatrix: Property ‘type‘ of feature ‘000000)
59 0
|
6月前
Google Earth Engine(GEE)—— ConfusionMatrix (Error)Property ‘landcover‘ of feature ‘1_1_1_1_1_1_1_1
Google Earth Engine(GEE)—— ConfusionMatrix (Error)Property ‘landcover‘ of feature ‘1_1_1_1_1_1_1_1
80 0
|
6月前
|
Python
GEE—关于RSEI生态遥感指数中出现的问题 Layer error: Image.rename: The number of names (1) must match the number of..
GEE—关于RSEI生态遥感指数中出现的问题 Layer error: Image.rename: The number of names (1) must match the number of..
183 0
|
6月前
Google Earth Engine(GEE)——当你无法进行两个图像相减的时候发生错误lst2020.subtract is not a function
Google Earth Engine(GEE)——当你无法进行两个图像相减的时候发生错误lst2020.subtract is not a function
70 0
【sklearn报错解决方案】UndefinedMetricWarning: Precision is ill-defined and being set to 0.0
【sklearn报错解决方案】UndefinedMetricWarning: Precision is ill-defined and being set to 0.0
1679 0
【sklearn报错解决方案】UndefinedMetricWarning: Precision is ill-defined and being set to 0.0
Google Earth Engine(GEE)——下载矢量数据过程中出现Property joinedWaterFeature has type Feature错误
Google Earth Engine(GEE)——下载矢量数据过程中出现Property joinedWaterFeature has type Feature错误
273 0
Google Earth Engine(GEE)——下载矢量数据过程中出现Property joinedWaterFeature has type Feature错误
|
11月前
Google Earth Engine(GEE)——feature ‘1_1_1_1_1_1_1_1_0‘ is missing错误如何解决?
Google Earth Engine(GEE)——feature ‘1_1_1_1_1_1_1_1_0‘ is missing错误如何解决?
291 0
Google Earth Engine(GEE)——feature ‘1_1_1_1_1_1_1_1_0‘ is missing错误如何解决?
|
编解码 算法 ice
Google Earth Engine(GEE)——MOD10A1 V6 Snow Cover Daily Global 500m积雪、积雪反照率、部分积雪和质量评估 (QA) 数据
Google Earth Engine(GEE)——MOD10A1 V6 Snow Cover Daily Global 500m积雪、积雪反照率、部分积雪和质量评估 (QA) 数据
327 0
Google Earth Engine(GEE)——MOD10A1 V6 Snow Cover Daily Global 500m积雪、积雪反照率、部分积雪和质量评估 (QA) 数据