0

I need to convert a Feature Collection containing only numeric data to a 2D matrix. I have written the following code however it gives matA as a list of arrays despite explicit type conversion, here table is my feature collection and data is the list of properties I need to extract into the matrix

// list of data to extract from FC
var data=ee.List(['bio01','bio02','bio03','bio04','bio05','bio06','bio07',
              'bio08','bio09','bio10','bio11','bio12','bio13','bio14',            
       'bio15','bio16','bio17','bio18','bio19','dem','tmax','tmin','prec']);

//data becomes the list from which the user wants to remove the ones he doesn't need

var tableArray=table.toList(200,0)  // list of features

var tableList=ee.List(tableArray.map(function(element){
  var feat=ee.Feature(element)  
  var array=feat.toArray(data)  //feature to array
  return ee.List(array) //array to list 
}))

// array needs all elements of list only not array inside list so we change feature to list

var matA=ee.Array(tableList)

print(matA)

The error I am getting is:

Array (Error)
Array: Unrecognized type, may only use numbers or lists, found type Array.

1 Answer 1

1

The following code works to convert feature collection to arrays

var tableList = table.toList(200).map(function(element) {
  return ee.Feature(element).toArray(data)
})

var matA = ee.Array.cat(tableList, 1)

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.