Geographic Information Systems Asked by Dela Deladem on December 21, 2020
I am trying to run a land cover classification in GEE. I have a csv file which I converted and exported as a shapefile in GEE. The problem is when I specify the column name containing the land use class, I get the error below.
classification: Layer error:
Property ‘land_use_5’ of feature ‘00000000000000000011_0’ is missing.
What am I doing wrong? Here is my code:
https://code.earthengine.google.com/15a705dc1133e6978f09e5113bbbcb99
var rwanda = ee.FeatureCollection("users/sbrightaboh/edem");
print(rwanda)
//var count = rwanda.aggregate_count("_land_use_category_alias_class")
//print(count)
//var lookupIn = ee.List([0,1,2,3,4,5,6])
//var lookupOut = ee.List([6,5,4,3,2,1,0])
//var remaped = rwanda.remap(lookupIn, lookupOut, "land_use_c,C,254")
//print(remaped)
Map.addLayer(rwanda,{color:"red"},'Rwanda');
//var values = ee.Dictionary
// Input imagery is a cloud-free Landsat 8 composite.
var l8 = ee.ImageCollection('LANDSAT/LC08/C01/T1');
var image = ee.Algorithms.Landsat.simpleComposite({
collection: l8.filterDate('2018-01-01', '2018-12-31'),
asFloat: true
});
// Use these bands for prediction.
var bands = ['B2', 'B3', 'B4', 'B5', 'B6', 'B7', 'B10', 'B11'];
// Load training points. The numeric property 'class' stores known labels.
// This property of the table stores the land cover labels.
var label = 'land_use_1';
// Overlay the points on the imagery to get training.
var training = image.select(bands).sampleRegions({
collection: rwanda,
properties: [label],
scale: 30
});
// Train a CART classifier with default parameters.
var trained = ee.Classifier.cart().train(training, label, bands);
// Classify the image with the same bands used for training.
var classified = image.select(bands).classify(trained);
// Display the inputs and the results.
Map.centerObject(rwanda, 11);
Map.addLayer(image, {bands: ['B4', 'B3', 'B2'], max: 0.4}, 'image');
Map.addLayer(classified,
{min: 0, max: 2, palette: ['red', 'green', 'blue']},
'classification');
None of your assets are shared so we can't replicate the error - please share assets if you are going to include them in the linked script.
The error message does not seem to have been generated by the linked script you provided, because 'land_use_5' is not used in the script.
I can replicate the error in the following example that demonstrates the need to filter out features from the training
feature collection that have null
property values, which is likely what is causing the error in your case.
Here, I've mocked up a feature collection that includes a null
value for 'prop1' (note the third feature) and used it for training and predicting. The result is the same error message regarding a missing property value.
// Mock up a feature collection with a null value for one of the properties.
var fc = ee.FeatureCollection([
ee.Feature(ee.Geometry.Point([-122.0888, 37.1845]), {'prop1': 1}),
ee.Feature(ee.Geometry.Point([-121.9982, 37.1374]), {'prop1': 2}),
ee.Feature(ee.Geometry.Point([-122.0908, 37.1259]), {'prop1': null})
]);
// Get an image to train and apply classification to.
var img = ee.ImageCollection('LANDSAT/LC08/C01/T1')
.filterBounds(fc)
.first();
// Define the property to predict and what bands to use.
var label = 'prop1';
var bands = ['B4', 'B5', 'B6'];
// Overlay the points on the imagery to get training.
var training = img.select(bands).sampleRegions({
collection: fc,
properties: [label],
scale: 30
});
// Train a CART classifier with default parameters.
var trained = ee.Classifier.cart().train(training, label, bands);
// Classify the image with the same bands used for training.
var classified = img.select(bands).classify(trained);
print(classified);
Property 'prop1' of feature '2_0' is missing.
If I filter out null
values from the training feature collection and then try training and applying the classifier again, the operation is successful.
// Filter out the null property values and try again.
var trainingNoNulls = training.filter(
ee.Filter.notNull(training.first().propertyNames())
);
// Try taining a classifer and applying it with the filtered training collection.
var trained = ee.Classifier.cart().train(trainingNoNulls, label, bands);
var classified = img.select(bands).classify(trained);
print(classified);
Map.centerObject(fc, 11);
Map.addLayer(classified, {min: 1, max: 2});
Answered by Justin Braaten on December 21, 2020
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP