I'm trying to extract specific field data which is in shapefile. There was an error while executing the following code in GEE as argument invalid type. the screenshot shows the error message.

Can you help to solve the problem?

error I have got when executing the code

var startYear = 2018;
var endYear = 2019;
for(var i=0;i<countries.size().getInfo();i++){
  var startMonth =countries.filter(ee.Filter.eq('startMonth',i));
  for(var j=0;j<countries.size().getInfo();j++){
    var startDay = countries.filter(ee.Filter.eq('startDay',j));
    var start = ee.Date.fromYMD(startYear, startMonth,startDay);

for(var i=0;i<countries.size().getInfo();i++){
  var endMonth =countries.filter(ee.Filter.eq('endMonth',i));
  for(var j=0;j<countries.size().getInfo();j++){
    var endDay = countries.filter(ee.Filter.eq('endDay',j));
    var end  = ee.Date.fromYMD(endYear, endMonth, endDay);
    //print(typeof endMonth)
print(typeof startDay)

Here startMonth,startDay and endMonth,endDate are the fields in attribute table(in shapefile) I want to extract these field data based on the country.special thing is there is another column country as 'ADM0_NAME'.

  • 1
    Please do not include images of error messages, as they are illegible on many devices and not searchable on any device. Instead, always include the full error message as text in the body of the question.
    – Vince
    May 29, 2019 at 10:02

1 Answer 1


The filter function does not give you a value but instead is used to filter your larger collection to narrow it down to the datasets that you want. If you know your filter is going to give you one feature and you want to get a value out of it, you first need to extract a feature out of it and get the value of that property.

In your case it would be

var countriesWithStartDayj = countries.filter(ee.Filter.eq('startDay',j));
// you can get the first feature with
var country = countriesWithStartDayj.first();
// now you can get the property value
var startDay = country.get('startDay');

Since it looks like you want to get start month and end month of each feature you can use the aggregate_array function

var startDays = countries.aggregate_array('startDay');
var endDays = countries.aggregate_array('endDay');

This would give you ee.List objects with values of field startDay and endDay of all features.


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.