Within Google Earth Engine, I have reduced the USGS NLCD land cover dataset to my specific shapefile (consisting of 952 counties within the United States; I have limited my shapefile to the first 10 counties for simplicity until I get the code to work and then I will run this over my entire shapefile).

I need to calculate the proportion of each land cover type in each county and export the results (while keeping the 'GEOID' in the csv) as a csv for analyses in R.

I have tried code from previous questions that have worked for others doing similar things, but the code (labeled: "//Convert frequencies to proportions for each county") always returns the error: "Dictionary (Error) Array: No numbers in 'values', must provide a type."

The previous examples used 'reduceRegion' rather than 'reduceRegions'; I'm new to Google Earth Engine, but is it possible that this is the reason for my error, and is there a way to write the code so I am able to avoid this error and calculate the proportion of each land cover type in each county?

Here is my current code:

//Shapefile: 15 states, all counties
var countyList = ee.FeatureCollection(table).limit(10);
//  .select ('GEOID');

print(countyList.size(), 'counties');

countyList = ee.FeatureCollection(countyList.map(function (feat) {
  var GEOID = feat.get('GEOID')
  return ee.Feature(feat.geometry().simplify({'maxError':1}), {'GEOID': feat.id()})
    .set('GEOID', GEOID);
   //return ee.Feature(feat.geometry());

//Imports NLCD Land Cover Data
var landcover = ee.ImageCollection('USGS/NLCD_RELEASES/2019_REL/NLCD')
  .filter(ee.Filter.eq('system:index', '2019')).first()

//Reduce frequency of land cover occurrence to each county 
var frequency = landcover.reduceRegions({
    collection: countyList,


////Convert histogram frequencies (from the reducer) to new properties for each county
////I would prefer the results in this format, but I am not sure how to do this in 
////conjunction with converting the frequencies to proportions
//var frequency = frequency.map(function(feature){
//  var dict = ee.Dictionary(feature.toDictionary().get('histogram'))
//  feature = feature.set(dict)
//  return feature

//print('per class landcover frequency properties', frequency);

//Convert frequencies to proportions for each county
var dict = ee.Dictionary(frequency.get('landcover'))
var sum = ee.Array(dict.values()).reduce(ee.Reducer.sum(),[0]).get([0]);
var new_dict = dict.map(function(k,v) {
  return ee.Number(v).divide(sum);

print('Land Cover (%)',new_dict);

//Export county-level NLCD proportion data to Google Drive
    collection: new_dict, 
    description: 'nlcd10', 
    folder: 'nlcd',
    fileNamePrefix: 'nlcd10', 
    fileFormat: 'CSV',

Here is a link to my code: https://code.earthengine.google.com/00faca61cc789f6c54aa85bf837cf324

1 Answer 1


I think rather than going on this, you can directly calculate the area of each landcover for each counties, export it as CSV. (find the codes https://spatialthoughts.com/2020/06/19/calculating-area-gee/ )

For few counties, I see this could have been done in excel. But, for 900+ counties, you have to change it in proportions in R/python. i. Then you can total the row wise to get the total area of the landcover, this would be for each county. ii. Then you can divide the each column with that total area for each landcover class. [ https://www.geeksforgeeks.org/how-to-find-the-proportion-of-row-values-in-r-dataframe/ ]

Hope my comment helps if your objective is not to do everything in GEE. I will also like to learn this to do in GEE. Let me know if you find the solution within GEE.

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.