1

I have a feature collection of badly drawn geometries (a subset is shared with the script). I need to identify the features that overlap in some way (for later processing).

The idea was to map each feature of the collection to every other feature in the collection and identify if they are overlapping. And set the number of overlaps in the property of the feature. If the number is greater than 1, then it overlaps with more than itself. However, I always end up with 12. (the number of features in my collection).

var fields = ee.FeatureCollection("users/JASPR/Results/fields");

var intersect = function(feature){

  var fc = fields.map(function(f){
    var intersects = feature.geometry().intersects(f.geometry())
    return(f.set({intersects: intersects}))
  })
  var status = fc.aggregate_count("intersects")
  return(feature.set({overlaps: status}))

}


var newFields = fields.map(intersect)

print(newFields)

Map.addLayer(newFields)

What do I need to change to get the correct number of overlaps?

1

I was using the wrong aggregate. Obviously I was counting 12, as there were always 12 "intersects" even if the value was false.

With this modification in the code, the result is the number of overlaps.

var fields = ee.FeatureCollection("users/JASPR/Results/fields");

var intersect = function(feature){

  var fc = fields.filterBounds(feature.geometry()).map(function(f){
    var intersects = feature.geometry().intersects(f.geometry())
    return(f.set({intersects: intersects}))
  })
  // aggregate the "intersects" to an array and get the frequency of TRUE.
  // Add that result as a property to the feature.  Any overlaps greater than 1
  // means the feature overlaps with a different feature.
  var status = ee.List(fc.aggregate_array("intersects")).frequency(true)
  return(feature.set({overlaps: status}))

}


var newFields = fields.map(intersect)

print(newFields)

Map.addLayer(newFields)

Now I have a feature collection that has a property added that contains the number of overlaps. Anything over 1 means it is overlapping a different feature.


EDIT

Modified the function so that it doesn't do the whole collection, just the features that are in the filterBounds()

.filterBounds(feature.geometry())
  • Nice!! Add maybe Map.centerObject(newFields) to the code, and eventually different colour for overlap? – Matifou Feb 21 at 18:23
  • Colours are for the next step. Which also calculates the % of overlap, and eventually the elimination of all overlapping fields that meat certain property criteria. – Sean Roulet Feb 22 at 12:45

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.