0

I have 2 FeatureCollections (FCs), roi and fc, that I want to merge. Naively I did it this like below but now I am worried about the overlap in the mergedFC.

var mergedFC = roi.merge(fc);
Map.addLayer(mergedFC, {}, 'merged flooded and non');

The problem is that I don't want my resulting FC to contain duplicates where there is spatial overlap (fc is spatially a subset of roi), I want to keep only the data for fc. This is important because later when I create a training set with .sampleRegions, I'm concerned about functions getting confused about class labels (all roi is non-flooded, whereas all of fc is flooded and of course the latter is what should take priority in an overlap situation).

I thought if I map over fc, taking the .symmetricDifference between each Feature and the roi Feature (there is only one simple Geometry in that FC), then I will end up with a FC that excludes fc because it is a spatial subset of roi. See code below. I thought I could then merge this output with fc which would give me what I want. But when I visualise this output, the whole roi/area seems to be shaded, which suggests it hasn't worked as I expected.

var trying = function(feature) {
  return feature.symmetricDifference(roi.first());
}

var output = fc.map(trying);
Map.addLayer(output, {color: 'FF0000'}, 'output', true, 0.1);

Questions:

  • Am I correct in assuming there is a problem here, that spatial overlap will introduce class label confusion in a mergedFC that is used for building a training set?
  • How can I test whether using .symmetricDifference worked?
  • Is there a better way?
  • What else might I not have considered?

For context, the example I am learning from is from the TF and EE demo script from the Earth Engine Users Summit 2018.

I'm new to both GEE and to EO.

closed as too broad by PolyGeo Sep 13 '18 at 21:05

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

4

Taking the symmetricDiffence of each feature isn't what you want; each feature will grow to be the size of the union of roi and the feature, and will cover the other features in the process. So instead of having overlap just between roi and each fc, you'll have overlap between all the fc features as well.

It sounds like what you want to do is to "exclude" the flooded geometries from the non-flooded roi. You can do that with a simple difference, but you want to subtract all of the flooded features from the roi in one go. Something like this:

var diff = ee.Feature(roi.first()).difference(fc.geometry(), 10)
var result = fc.merge(diff)

https://code.earthengine.google.com/09aba9b9d2e1ec8f62328ab9d3dce02d

  • Yep that's exactly what I was trying to do, thanks! The surprising thing for me was that you can get all the geometries of a FeatureCollection with .geometry(). – Tam Borine Sep 11 '18 at 16:21
  • The fc I'm working with is too large for the .difference function. When I cut down the size of the fc using filterBounds it works but otherwise not. Not sure what's going on under the hood. I guess I could do it piece by piece and stick it together again but not ideal. – Tam Borine Sep 13 '18 at 20:39
  • Ok turns out it does work for an fc with hundreds of geometry objects but just takes a long time (many tens of seconds). Many of my fcs have thousands of geometry objects. – Tam Borine Sep 13 '18 at 20:49
  • Ah - computation timed out, with an fc of 300 elements it can just about cope, but not 450. – Tam Borine Sep 13 '18 at 20:59

Not the answer you're looking for? Browse other questions tagged or ask your own question.