1

Ultimately, what I am trying to do is calculate overlap between (1) polygons of a species' range and (2) polygons of Protected Areas. There can be multiple overlapping polygons for the range (e.g. breeding vs. non-breeding range), so I simply want to perform a union such that there is just one Feature made up of multiple polygon geometries (with no overlaps). I tried the following:

var spRange = ee.FeatureCollection('users/rasenior/Necrosyrtes_monachus');
var rangeUnion = ee.Feature(spRange.union().first()); 

But when this is mapped as follows:

Map.addLayer(spRange, {color: 'blue'}, 'original');
Map.addLayer(rangeUnion, {color: 'green'}, 'union');

Output of FeatureCollection union in GEE

It seems that the union is only a sliver of one tiny section of the overall range. Why?

Possibly related: I've encountered a lot of problems for this particular species, which I think might be due to the geometry becoming messy when I upload to GEE. Specifically, one of the features becomes a GeometryCollection, containing both LineStrings and Polygons. I have no idea why, nor how to remove the LineStrings (or convert them to Polygons?).

Script here: https://code.earthengine.google.com/?scriptPath=users%2Frasenior%2Ftest%3AgetSpRange

UPDATE 1: it's nothing to do with the weird geometry. I have now resolved that issue (use 'users/rasenior/Necrosyrtes_monachus_fix') such that all geometries are Polygons or MultiPolygons. But, alas, a union of the FeatureCollection still results in the sliver seen in the screenshot.

UPDATE 2: now that the FeatureCollection is free of weird geometries I was able to export it as a shapefile to inspect in ArcGIS. The FeatureCollection is made up of four Features, and the green sliver in the screenshot corresponds to the fourth of these. I don't know why this is the only thing being returned by union. All I can say is that the fourth Feature is the only one with a Polygon geometry, whereas the other three Features have MultiPolygon geometries.

1 Answer 1

0

As alluded to in my second update, the problem stems from union only considering Polygon Features, and not the MultiPolygon Features.

I solved the problem by combining all Polygons of all geometries into one single MultiPolygon Feature:

// Break each feature into constituent geometries
var polyFt = ee.List([spRange
    .filter(ee.Filter.eq('geotype', 'Polygon'))
    .geometry()]);
var multiFt = spRange    
    .filter(ee.Filter.eq('geotype', 'MultiPolygon'))
    .geometry()
    .geometries();

// Combine all Polygons
var spRangeCombi = ee.FeatureCollection(
    ee.Feature(
    ee.Geometry.MultiPolygon(polyFt.cat(multiFt))));

For which union now works as expected:

// Try union again
var spRangeUnion = ee.Feature(spRangeCombi.union().first());
Map.addLayer(spRangeUnion, {color: 'pink'}, 'union'); 

Script here (same link as in question, now updated).

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.