0

I'm new to Earth Engine and am having a difficult time determining what the best method of obtaining tabular data at the pixel level based on raster and vector data inputs and geographic points of interest.

I have a fusion table of geographic points of interest for Africa ("interest"), the Hansen Global Forest Cover Watch rasters ("gfc2014_c"), and a Shapefile of districts and countries in sub-Saharan Africa ("SSA").

//Load the Hansen data and create layers
var gfc2014 = ee.Image('UMD/hansen/global_forest_change_2015');

//Load the SSA administrative district shapefile
var SSA = ee.FeatureCollection('users/salem043/Africa_Districts')

//Crop the Hansen data we are interested in to the SSA admin shapefile
var gfc2014_c = gfc2014.clip(SSA);

//Load the data points of interest from the fusion table
var interest = ee.FeatureCollection('ft:1DCL5m_EO8kKMis2BWTdzfg-i9uc4uAZ2xNLQuhf7');

I want to extract the GFC data (all underlying bands) for each of the points of interest. But I also want the information from the shapefile - I need variables that identify which geometries the points lie in.

The one page I found with some information on this task was here:

So I tried their method, just using the GFC data, which looks like the following (again, this is mostly taken from the link above).

var mapfunc = function(feat) {
  // get feature id
  var id = ee.String(feat.id())
  // get feature geometry
  var geom = feat.geometry()
  // make an empty list to store the features
  var newfc = ee.List([])
  // function to iterate over the ImageCollection
  var addProp = function(img, fc) {
    // the initial value is the empty list
    fc = ee.List(fc)
    // get the date as string
    var date = img.date().format()
    // extract the value of 'waterClass'
    var value = img.reduceRegion(ee.Reducer.first(), geom, 30).get('waterClass')
    // If the value is null then store it as 'No data'
    var val = ee.String(ee.Algorithms.If(value, ee.String(value), ee.String('No data')))
    // make the name of the feature (feat_id-date)
    var featname = ee.String("feat_").cat(id).cat(ee.String("-")).cat(date)
    // make the Feature
    var newfeat = ee.Feature(geom, {name:featname,
                                    value:val})
    // add the value to the list
    return fc.add(newfeat)
  }
  var newfeat = ee.FeatureCollection(ee.List(gfc2014.iterate(addProp, newfc)))
  return newfeat
};

var newft = interest.map(mapfunc).flatten();

Export.table.toDrive(newft,
"export_Points",
"export_Points",
"export_Points");

When I run this I get an error that "gfc2014.iterate is not a function"

Even if I could get the function above working, I don't know how to also extract other information from the shapefile. The end result should have point of interest ID (which is in the fusion table), point of interest country, district, and all Hansen data values for the point of interest.

I am so grateful for any leads or suggestions! Thank you so much for your time!

C. Ashley
  • 150
  • 1
  • 5
  • I don't have an answer for how to get the result you want, but the reason for the specific error is that `gfc2014` is a single image — `iterate` is only for collections and lists. Perhaps you meant to load an image collection? – Kevin Reid Jun 04 '19 at 20:27
  • Thank you for getting back to me. I figured that this particular issue was due to the fact it's an image and not an image collection. The data I am working with loads as an image, so I am not sure what other alternatives I have. – C. Ashley Jun 04 '19 at 22:07

1 Answers1

0

I have one of the methods to do this. Since your layers were not accessible to me, i took the liberty and created a couple of points and polygons of my own.

First you need to copy the properties from your polygons to all the points that lie within that polygon. I do this my spatially joining the polygon(SSA) and point(interest) layers first so that I can have properties of the points in the polygons. I can do this by creating a Join object that looks at .geo

// Define a spatial filter as geometries that intersect.
var spatialFilter = ee.Filter.intersects({
  leftField: '.geo',
  rightField: '.geo'
});

// Join the points and polygons and apply spatial filter to keep only
// intersecting ones
var joinAll = ee.Join.saveAll('matched').apply(points, poly, spatialFilter);

Since the join simply adds qualifying polygons as a new property of the point, i do this to extract the information.

var featuresWithProp = joinAll.map(function(feature){
  var joinedFeat =  ee.List(feature.get('matched'));
  var polygon = ee.Feature(ee.FeatureCollection(joinedFeat).first());
  return ee.Feature(feature.copyProperties(polygon, properties)).select(properties);
});

Finally I sample the gfc layer using those points

var sampledPoints = gfc2014.sampleRegions({
  collection:featuresWithProp,
  properties:properties,
  scale:30,
  geometries:true
})

You can see a working example here

Nishanta Khanal
  • 316
  • 2
  • 4