5

I would like to dissolve a polygon/featurecollection in GEE to run some statistics by the country level. I have tried union and dissolve and cannot find a solution. Union dissolves everything to get the boundary of all polygons. How can I dissolve by a property in GEE? It would be similar to dissolve by attribute in ArcMap/QGIS.

//Purpose: Dissolve featurecollection by a property 

//Name WDPA variable
var WDPA = ee.FeatureCollection("WCMC/WDPA/current/polygons");
print(WDPA.first(), 'WDPA'); //28 properties
Map.addLayer(WDPA, {}, 'WDPA'); //adds featurecollection to map

//Union using the property
var WDPA_union = table.union('ISO3'); //ERROR: Invalid argument specified for ee.Number(): ISO3
print(WDPA_union.first(), 'WDPA Union by ISO');
Map.addLayer(WDPA_union, {}, 'WDPA Union by ISO');

//Dissolve using the property
var WDPA_dissolve = WDPA_ISO.dissolve('ISO3'); //ERROR: Cannot read property 'dissolve' of undefined
print(WDPA_dissolve.first(), 'WDPA Dissolve by ISO');
Map.addLayer(WDPA_dissolve, {}, 'WDPA Dissolve by ISO');

link code

1 Answer 1

4

Yes that is possible. First make a list of all property values which are present in your feature collection. Then filter the featurecollection on all the features with a similar value for that property, and union only that features.

//// ---- Union using the property ---- \\\\

// first get a list of all posible property values
var propVals = ee.List(WDPA.aggregate_array(nameProperty)).distinct();
// then make a feature the union of all features having the same propVal
var unionByProp = ee.FeatureCollection(propVals.map(function(propVal){
  var tempFC = WDPA.filter(ee.Filter.eq(nameProperty, propVal));
  var unionFC = tempFC.union(maxError); // specifying a max error overcomes issues with features of diff projection
  // cast the featureCollection (output union()) to a single feature
  return ee.Feature(unionFC.first()).set(nameProperty, propVal);
}));

See the link for a full working example. Note that for printing, you will need to limit the size of this feature collection. Export the result if printing a subset satisfied your needs.

1
  • Thanks! This answered my question. Now I want to figure out how to attach some additional properties back to this (not just ISO3). Is that possible with .copyProperties? Sep 21, 2020 at 17:48

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.