I am new to R and GEE. I am trying to establish a link, using time series analysis, between land use change (different classes) and evapotranspiration (if possible also temperature, precipitation and evapotranspiration).

I have data on a monthly timestep for my four climate variables so will need land use change data on the same time step. I have existing GeoTIFF land use maps for 1990, 2013/14 and 2020. I would like to use the 2013/14 land use map as a training 'map' by extracting points with land use classes assigned to them so in essence point data.

The steps that I have followed so far is like this:

  1. Call the image collection and filter according to date ('2013-03-01','2022-04-01')
  2. Apply scaling factors
  3. Apply cloud masking
  4. Create an image collection of monthly composites
  5. Upload the GeoTIFF and specify legend (the land use class associated with each pixel. This info is extracted using the attribute table in ArcGIS)
  6. Converting pixels to points
  7. Assigning land use classes to each point*
  8. Splitting up the data into training and testing*
  9. Setting up and running random forest*
  10. Uploading climate variables (if possible all four, but at the very least evapotranspiration) and doing a correlation with each land use class. *

I am stuck at step 7* (so cannot complete step 8 to 10 either) at the moment. My code runs successfully, but when I look at the properties of each point it still says 'land use class: unknown'. The snippet of code where I am trying to assign a land use class to each pixel (according to a pixel value) is as follows (b1 is the only band in my geotiff image):

// Function to assign land use class to a point based on pixel value
var assignLandUseClass = function(point) {
  var pixelValue = ee.Number(point.get('b1'));

  // Use a conditional to handle missing values or unrecognized pixel values
  var landUseClass = ee.String(

  // Set the land use class as a property of the point
  return point.set('LandUseClass', landUseClass);

// Map the function to the points collection
var pointsWithLandUse = points.map(assignLandUseClass);

// Print the resulting FeatureCollection with land use classes

What is wrong?

  • Thanks for your comment Vince. It doesn't assign the land use class to the point Commented Nov 2, 2023 at 17:56

1 Answer 1


You haven't included enough code to make this reproducible, but legend[pixelValue] will for sure give you problems.

You are performing client-side operations with a server-side object (read up on the difference here).

  • If legend is a plain JavaScript Object, e.g. {}, you cannot use pixelValue, a server-side object, to extract the legend value.
  • If it's an ee.Dictionary, you cannot extract values using [], that only works on client-side objects.

To solve this, make sure legend is an ee.Dictionary and extract the value using the get() method. This method also allow you to specify a default value to return when dictionary doesn't contain the key. As a bonus, this allows you to get rid of the ee.Algorithms.If statement, which you normally should try to avoid.

var landUseClass = ee.String(
  ee.Dictionary(legend).get(pixelValue, 'Unknown')
  • Thank you so much! Commented Nov 8, 2023 at 12:40
  • Since I posted this I came right with ee.Dictionary and I also managed to get a summary of each land use class and the number of points. My points are grossly unevenly distributed so the next question is how do I limit the maximum number of points to 1000? And is this an appropriate number of points to use for training in an area of 5947,22km2? I have 20 land use classes Commented Nov 8, 2023 at 12:45
  • * my points are unevenly distributed among the respective land use classes, just for clarification Commented Nov 8, 2023 at 12:47
  • Make a new question about that. Commented Nov 8, 2023 at 16:29

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.