1

I'm attempting to calculate the proportion of landcover classes for each county in Oregon in GEE and export values as a CSV, but I get the following error: Error: Error in map(ID=00000000000000000000): Dictionary.set: Parameter 'value' is required. (Error code: 3). I see this question was asked before, but not answered. Can someone help me address this error? Here is my Code.

snippet of the code:

//calculate area of each class for each county in the shapefile
var calculateClassArea = function(feature) {
  var areaImage = ee.Image.pixelArea().addBands(ORlandcover);
  
  var areas = areaImage.reduceRegion({
    reducer: ee.Reducer.sum().group({
      groupField: 1,
      groupName: 'class',
    }),
      geometry: feature.geometry(),
      scale: 30,
      maxPixels: 10364007075
  });
  var classAreas = ee.List(areas.get('groups'));
  var classAreasLists = classAreas.map(function(item) {
    var areaDict = ee.Dictionary(item);
    var classNumber = ee.Number(
      areaDict.get('class')).format();
      var area2 = ee.Number(
        areaDict.get('sum')).divide(1e6).round();
        return ee.List([classNumber, area2]);
  });
  var result = ee.Dictionary(classAreasLists.flatten());
  var county = feature.get('Name');
  return ee.Feature(
    feature.geometry(),
    result.set('county', county));
};

var countyAreas = table.map(calculateClassArea);
//print(countyAreas);

var classes = ee.List.sequence(1, 16);
var outputFields = ee.List(
    ['county']).cat(classes).getInfo();
 
Export.table.toDrive({
    collection: countyAreas,
    description: 'class_area_by_county',
    folder: 'GEO Stuff',
    fileNamePrefix: 'class_area_by_county',
    fileFormat: 'CSV',
    selectors: outputFields
    })
1

2 Answers 2

0

Issue can be solved as follows ('set' method is not adequately used with ee.Feature object and it is also eliminated selectors parameter in Export.table):

//calculate area of each class for each county in the shapefile
var calculateClassArea = function(feature) {
  var areaImage = ee.Image.pixelArea().addBands(ORlandcover);
  
  var areas = areaImage.reduceRegion({
    reducer: ee.Reducer.sum().group({
      groupField: 1,
      groupName: 'class',
    }),
      geometry: feature.geometry(),
      scale: 30,
      maxPixels: 10364007075
  });
  var classAreas = ee.List(areas.get('groups'));
  var classAreasLists = classAreas.map(function(item) {
    var areaDict = ee.Dictionary(item);
    var classNumber = ee.Number(
      areaDict.get('class')).format();
      var area2 = ee.Number(
        areaDict.get('sum')).divide(1e6).round();
        return ee.List([classNumber, area2]);
  });
  var result = ee.Dictionary(classAreasLists.flatten());
  var county = feature.get('Name');
  return ee.Feature(feature.set('result', result));
};

var countyAreas = table.map(calculateClassArea);
print("countyAreas", countyAreas);

var classes = ee.List.sequence(1, 16);
var outputFields = ee.List(
    ['county']).cat(classes).getInfo();

print(outputFields);

Export.table.toDrive({
    collection: countyAreas,
    description: 'class_area_by_county',
    folder: 'GEO Stuff',
    fileNamePrefix: 'class_area_by_county',
    fileFormat: 'CSV',
    });

After running the task in GEE code editor (link here), without any error, I got following CSV file opened with LibreOffice.

enter image description here

3
  • Do you have any suggestions on how to incorporate the variable outputFields into the exported CSV file to ensure that it has values for each landcover type even if the value is 0? Or do you know of another solution to address this challenge? Currently each row does not necessarily have a value for each landcover type so it is difficult to delineate into columns for each landcover type. Commented Aug 19, 2022 at 15:53
  • outputFields variable is following list: ["county",1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]. There is not information associated to it. For this reason I deleted it as descriptor. How these values are associated with result dictionary?
    – xunilk
    Commented Aug 21, 2022 at 15:06
  • This is the keys list 11, 12, 21, 22, 23, 24, 31, 41, 42, 43, 52, 71, 81, 82, 90, 95 presents in result dictionary. Sometimes has 15 values, sometimes 16.
    – xunilk
    Commented Aug 21, 2022 at 15:23
0

I was also using the same code from Spatial Thoughts, it worked for few shapefile records (my own shapefile units in asset), but for bigger number of records, I was getting the same error.

Deleting all the fields except the one required helped me and I did not get any error after that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.