0

I have a raster file with pixel values between 11010 and 812210 and I would like to change all these values in integers between 0 and 5. The problem here is that there is no pattern that I can use (at least not obvious to me) to reclassify this values with logical expressions and I have more than 2000 combinations. Is there any way to make a reclassification, maybe with a CSV file or something?

This values were gotten with the .expression function in GEE with ESA Land Cover and Potentials Ecosystems Data.

I´m sorry that I can´t give you any sample code but here there is an example of the combinations that I must to get.

enter image description here

Any idea on to solve this problem? Or even a confirmation that I should write more than 2000 lines of code with .map function jeje.

2 Answers 2

1

If you upload the CSV file as a FeatureCollection asset you should be able to use it as a lookup table to supply the ee.Image.remap function with from-to reclassification pairs.

Before you upload the CSV file, rename the desired columns as "from" and "to". Once the CSV is uploaded, you can use either of the following options to fetch the "from" and "to" columns for input to ee.Image.remap.

Pseudo code:

Using ee.Reducer.toList()

var fromToFc = ee.FeatureCollection('users/<username>/<fromToFc>');

var propNames = ee.List(['from', 'to']);
var fromToList = ee.List(
  fromToFc.reduceColumns({
    reducer: ee.Reducer.toList().repeat(propNames.size()),
    selectors: propNames
  })
  .get('list')
);

var from = fromToList.get(0);
var to = fromToList.get(1);

var yourImg = ee.Image('users/<username>/<yourImg>');
var reclassedImg = yourImg.remap(from, to, null, '<BandName>');

Using ee.FeatureCollection.aggregate_array

var fromToFc = ee.FeatureCollection('users/<username>/<fromToFc>');

var from = fromToFc.aggregate_array('from');
var to = fromToList.aggregate_array('to');

var yourImg = ee.Image('users/<username>/<yourImg>');
var reclassedImg = yourImg.remap(from, to, null, '<BandName>');
1
  • Thank you so much for your explanation, it is really clear and it works very well. Before I read your message I wrote all the combinations in the console and with ee.Reducer.toList() I got the same results. Awesome @JustinBraaten Jun 22, 2021 at 4:01
0

Can you rank order the pixel values and then reclassify using 5/2000 (0.0025) increments?

1
  • Thank you so much for your comment. I can´t change the pixel values because they are not equally spaced. In addition, each value tells me three features of the pixel. For example the pixel value 32150 is because the pixel have the ecosystem 3, with transformation in the year of study (2), and the ESA Land cover code 150. @JustinBraaten answered with two interest ways to solve this problem. Thank you so much :) Jun 22, 2021 at 4:11

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.