I have a raster file representing a vegetation index. I want to reclassify that raster into 5 classes using the Natural Breaks method in Google Earth Engine. Additionally, I want to export the break values as a table.

Could someone provide me with a guide on how to approach this implementation?

1 Answer 1


An easy way of classifying your image into classes is to use the where function, e.g.:

var ndvi = ee.ImageCollection('MODIS/061/MOD13Q1')

var ndviClass = ndvi.where({
  test: ndvi.lt(2000),
  value: 1
  test: ndvi.lt(4000).and(ndvi.gt(2000)),
  value: 2
  test: ndvi.lt(6000).and(ndvi.gt(4000)),
  value: 3
  test: ndvi.lt(8000).and(ndvi.gt(6000)),
  value: 4
  test: ndvi.gt(8000),
  value: 5

Here is the link to the code for this example: https://code.earthengine.google.com/e9fd699697f98101cca6b454547fd2e5

Regarding identifying natural breaks in the data, to the best of my knowledge, there isn't a straightforward method to accomplish this within GEE, and I haven't been able to devise a workaround that wouldn't require the use of external software, except maybe doing so visually with a frequency histogram:

var chart = ui.Chart.image.histogram({
  image: ndvi, 
  region: geometry, 
  scale: 500,
  • Thanks, but that code does not follow the natural breaks Jenks method.
    – Isa
    Commented Apr 3 at 10:20
  • Yes, as I said, it is not possible on GEE, though the code does show you how to reclassify your image.
    – M. Nicolas
    Commented Apr 3 at 15:37

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.