2

Working on Google Earth Engine and still finding this challenging. I have two images, the first one is an image of landcover categories and the second one land management units. I want to cross these categorical images to obtain basically a count of pixels of each landcover in each unit.

I guess this is called a cross-tabulation, a contingency table or a tabulate operation (in ArcGIS). I have noted the tutorial on the reducer to get zonal statistics but this is not quite what I need https://developers.google.com/earth-engine/reducers_grouping.

Is this possible to implement in Earth Engine? I would be surprised if not!

Vectorizing one image to do the analysis seems like a very lousy approach.

  • How does the second example on the page you cited not do what you want? There are two raster inputs and one vector input (you have to specify what region in which you want to do this cross-tabulation). You may need to change the reducer to sum. – Nicholas Clinton May 22 '18 at 16:31
  • Thanks, Nick...I tried the example. The difference is that the example assumes that the second image is a continuous field that can be summarized by e.g. sum. What I actually have is a second categorical image (a second classification) and then I would like for each digital value of the first one get the count of pixels that intersect the second one discretized by NDs. A cross tabulation on ND in the first image against ND in the second image. In old-school GIS this output is represented as a matrix (like a confusion matrix in accuracy assessment of image classification). – jpardila May 24 '18 at 4:04
1

This may be what you want. (The data here are just for demonstration.) Obviously it's going to take a little more work to get this into a friendly format for what ever comes next, but I believe all the information is here. Note that geometry is some ee.Geometry representing an area of interest. Also note that you get some fractional pixels on the edge of the geometry, but you can either round or make that go away by calling unweighted() on the reducer.

// Load MODIS land cover.
var mcd12 = ee.ImageCollection("MODIS/051/MCD12Q1")
    .filterDate('2011-01-01', '2011-12-31')
    .select('Land_Cover_Type_1');
var landcover1 = ee.Image(mcd12.first());

// Load NLCD land cover.
var nlcd = ee.ImageCollection("USGS/NLCD")
     .filterDate('2011-01-01', '2011-12-31')
     .select('landcover');
var landcover2 = ee.Image(nlcd.first());

// Summarize frequency of NLCD w/in zones of IGBP.
var histograms = landcover2.addBands(landcover1).reduceRegion({
  reducer: ee.Reducer.frequencyHistogram().group({
    groupField: 1, 
    groupName: 'Land_Cover_Type_1'
  }),
  geometry: geometry,
  scale: 30,
  maxPixels: 1e9
});

print(histograms); 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.