TransWikia.com

Reduce image using two image inputs - one with zones the other with data to summarize

Geographic Information Systems Asked by Kevin Barnes on December 22, 2020

I would like to reduce an image where the inputs are two images and the output is a table. One image will have zones (integer values) and the other data to summarize. For each zone in an image, I would like to calculate the mean of values in the other image that overlap that zone. In ArcGIS one could use the tool Zonal Statistics as Table.

https://pro.arcgis.com/en/pro-app/tool-reference/spatial-analyst/zonal-statistics-as-table.htm

//1- zone image (DEM binned 100m intervals)
//2- data to summarize (mean minimum temperature)
//3- figure out how to summarize mean tmin per dem zone and export as a csv


//zones (dem binned x 100m)
var DEM_binned = image.divide(100).ceil().clip(geometry);
Map.addLayer(DEM_binned, {min:0, max:40, palette:['blue', 'purple', 'green', 'yellow', 'orange', 'red', 'white']}, 'dem');

//data to summarize (mean long-term annual tmin)
var tmin = imageCollection.select('tmin');
var tmin = tmin.mean().clip(geometry);
Map.addLayer(tmin, {min: -5, max: 20, palette:['white', 'blue', 'green', 'yellow', 'red']}, 'tmin')

//get mean tmin per zone as a table

GEE working example script: https://code.earthengine.google.com/0f50cbfbbb8ee8eabad07d9569b9a58a

One Answer

You could try converting your DEM with .reduceToVectors() and using this with .reduceRegions() to get your mean values. This might be very slow though, because .reduceToVectors() can take a while on rasters with a higher resolution.

Instead something like this might be quicker:

var bins = ee.List.sequence({
  start: -1,
  end: 80,
  step: 1
})

var scale = tmin.projection().nominalScale()
var tmins = bins.map(function(bin){
  var masked = tmin.mask(DEM_binned.eq(ee.Number(bin).toInt()))
  return masked.reduceRegion({
    reducer: ee.Reducer.mean(),
    scale: scale
  })
})

print(tmins)

Here we define a range of dem values right at the start (-100 to 8,000 m) which should cover all the values we need and then map over this list. You can also use step to change the binning. The big advantage here is that we only use reduceRegion() on the masked tmin raster which has a pretty low resolution. That way the computation time is probably a lot lower than with other methods, however I haven't tested that.

Correct answer by JonasV on December 22, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP