I want to average a 30m raster at the resolution of a 1000m one. Specifically, I want to computer, for each Daymet raster cell, the percentage of cultivated land from the 30m CDL.
How can I do that in EarthEngine? My question is very similar to one asked on the EE list. The author was exploring 3 solutions:
- A bilinear resample
- Reproject
- ReduceRegions, using a coarser raster that has been converted to features.
Someone gave an answer using reduceNeighborhood() to use a mean reducer, then reproject(), but it does not give quite the right result (see below, not right scale). How can I adjust that solution (I'm giving wrong scale parameters presumably?), or is there another solution that would be better?
// DATA Import
var CDL = ee.ImageCollection("USDA/NASS/CDL")
var daymet = ee.ImageCollection("NASA/ORNL/DAYMET_V3").
filter(ee.Filter.calendarRange(2015, 2015, "year"))
var aoi = ee.Geometry.Polygon([[[-100.501, 42.9819],[-100.501, 42.4045], [-98.39, 42.40457], [-98.39, 42.98192]]])
var CDL_2015 = ee.Image("USDA/NASS/CDL/2015").select("cultivated").clip(aoi)
var DYM_2015 = ee.Image(daymet.first()).select("tmin").clip(aoi)
// Operation
var image_frac=CDL_2015.eq(2).reduceNeighborhood({
reducer: ee.Reducer.mean(),
kernel: ee.Kernel.square(250,"meters"),
}).reproject(DYM_2015.projection().atScale(1000)).rename("cultivated")
//Visualization
Map.centerObject(aoi, 12)
Map.addLayer(DYM_2015.randomVisualizer(), {}, 'DAYMET tmin')
Map.addLayer(CDL_2015.select("cultivated").eq(2), {min:0, max:1, opacity: 0.8, palette: ["beaed4","7fc97f"]}, "CDL coverage original")
Map.addLayer(image_frac.select("cultivated"), {min:0, max:1, opacity: 0.4}, "CDL coverage")