1

Given two FeatureCollections in Earth Engine, one being a regular grid, the other a number of country shapefiles, I would like to produce a new FeatureCollection with the geometry of the regular grid, but, in addition, the underlying country name, which is stored in a property of the country shapefile FeatureCollections.

In particular, as I am used in other GIS softwares, would it be possible to specify intersecting/overlapping as the condition for the spatial join?

Here is the EE demo link: https://code.earthengine.google.com/e50d27dd851e07f98cdabc69efc33da8

1 Answer 1

4

Something like this will return a new feature collection where all the zones are named by the country they are in. As the feature collection is over 5000 elements, you will need to export it because it cannot be printed in the console.

// map over all the countries
var mappedGadm = gadm.map(function(feat){
  feat = ee.Feature(feat);
  var name = feat.get('NAME');
  var zonesFilt = zones.filterBounds(feat.geometry()).map(function(zone){
    return ee.Feature(zone).set('NAME', name);
  });
  return zonesFilt;
}).flatten();

The function filterBounds() is fast, but will along the border of course result in many grids belonging to both countries along the border. If you want the zones to be cut off along the border, you will need to use intersection() on an ee.Geometry, but that will increase the computation time heavily.

Link script

2

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.