0

I have a series of buffers stored in a feature collection. Some but not all of the buffer polygons overlap. I need to dissolve the polygons in a way that Google Earth Engine still recognizes each as a separate polygon with a unique ID (its own feature in a feature collection) so that I can then determine the polygon that each of my sample points falls into.

The user support I've found on this topic uses the union function like this:

var buffsSample=buffers.union();

This creates a feature collection of one large polygon (one feature). I want a feature collection where each stand-alone polygon (some of them dissolved, some not) is its own unique feature with an ID.

UPDATE: I found that I could create a multipolygon with separate coordinates for each polygon as follows:

var buffsSample=buffers.geometry().dissolve();

The problem is that this is a multipolygon and not a feature collection. When I took this multipolygon and converted it to a feature collection as follows:

var buffsFeature = ee.FeatureCollection(buffsSample)

I end up with the exact feature collection I would have gotten using '''union()''' (only one feature, whereas I want each polygon to be a feature).

Please let me know if you have suggestions for converting the multipolygon into a feature collection where each buffer is its own feature. Or if you have an alternative suggestion for dissolving polygons within a feature collection and returning a feature collection where each polygon is its own feature.

Code here.

1

I think I found a solution based on this past post. Full code:


//Create demo data//////////////////////////////////////

var region = ee.Geometry.Rectangle(-120, 34.669, -99.536, 50.064);

// Create 10 random points in the region.
var randomPoints = ee.FeatureCollection.randomPoints(region, 1000);

//Produce 10 km buffers, these are the polygons we want to dissolve
var bufferPoly = function(feature) {
  return feature.buffer(10000); 
};

var buffers = randomPoints.map(bufferPoly);
Map.addLayer(buffers, {}, 'buffers');
//print(buffers.limit(10), "Overlapping buffers"); //Each buffer has its own ID but some overlap!



//Buffers: dissolve and transform to FC so that we can identify each
//tile's buffer ID

var buffsGeoDissolve =buffers.geometry().dissolve();
print(buffsGeoDissolve, "Dissolve using geometry().dissolve()"); //Multipolygon!
Map.addLayer(buffsGeoDissolve, {}, 'Dissolve using geometry().dissolve()');


var fc = ee.FeatureCollection([
  ee.Feature(buffsGeoDissolve)
]);
print(fc);

var multiGeomExplodeList = fc.toList(fc.size()).map(function(feature) {
  var geomList = ee.Feature(feature).geometry().geometries();
  var featureList = geomList.map(function(geom) {
    return ee.Feature(ee.Geometry(geom));
  });
  return featureList;
})
.flatten();

var buffDissolveFC = ee.FeatureCollection(multiGeomExplodeList);

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.