0

I'm trying to add values from a table to a cluster image. The cluster image has 50 cluster classes, and my table has 50 values for each cluster class. How do I add the values from that table to the image so that each pixel within that cluster class represents that value from the table? I've included an image for clarification.

I understand this might get flagged as too broad, but I've reached the limit of my ability, and I'm in need of some direction. Is something like this even possible in GEE?

Link to my code: https://code.earthengine.google.com/0d4094a289c9f7f139809b4e9e1f1d05

enter image description here

  • I can't see the table with cluster's values in the code. How do you decide which value goes to the cluster? In the example case you showed, why new_value is 0.212 and not -0.212? (last value of the table) – Rodrigo E. Principe Oct 13 '18 at 21:34
  • @ Rodrigo E. Principe - my bad, I created that pic in paint, didn't change the values. I haven't uploaded the table yet and the values in the pic are for demonstration purposes. Is what I'm proposing possible? – Samual Chance Oct 13 '18 at 23:06
1

The function you're looking for is remap. I give you three ways to do it:

  1. Imported Table

If you want to remap a lot of clusters and you have a table in a local spreadsheet:

  • convert it to a csv file
  • upload it to a fusion table
// replace `fusion_table_id` to the fusion table id
var table = ee.FeatureCollection('ft:fusion_table_id')

var changeValue = function(feat, image) {
  // cast values
  image = ee.Image(image)
  feat = ee.Feature(feat)

  // get cluster's values
  var cluster = ee.Number(feat.get('cluster'))
  var value = ee.Number(feat.get('value'))

  // remap
  return image.remap([cluster], [value])
}

// iterate over the table
var remapped = ee.Image(table.iterate(changeValue, result))
  1. A dictionary of cluster: value
// dict (this is just an example)
var values = ee.Dictionary({
  1: 0.1,
  2: 0.2,
  13: 0.13
})

// as dict's keys are string, you have to parse them as numbers
var keys = values.keys().map(function(key){return ee.Number.parse(key)})

// remap
var remapped = result.remap(keys, values.values())
  1. 2 lists
var clusters = [1,   2,   3,   4,   5,   13]
var values =   [0.1, 0.2, 0.3, 0.4, 0.5, 0.13]
var remapped = result.remap(clusters, values)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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