0

Up until sometime in the last week or so, the following code was working to convert the features of a filtered FeatureCollection into a single multipolygon geometry:

var predicates = ee.Filter.inList('GEOID', countylist);
var unioncounties = ee.FeatureCollection(counties.filter(predicates).geometry());

Now however, the features all remain separate and I have to use the following to get a single geometry, which is much slower:

var predicates = ee.Filter.inList('GEOID', countylist);
var unioncounties = ee.FeatureCollection(counties.filter(predicates).geometry().dissolve());

Anybody else seeing this change of behavior?

UPDATED TO EXCLUDE COUNTIES WITH LINESTRINGS from Noel's answer below. Still, .geometry() no longer is merging the features into a single geometry like it did a month ago. It does not matter what FC is used, the behavior has somehow changed:

Full working code example here: https://code.earthengine.google.com/6d3c7110f0994cfde2a467cd9ee3911b

0

One of the counties has an extra linestring in the geometry.

GeometryCollection
    type: GeometryCollection
    geometries: List (5 elements)
        0: LineString, 2 vertices
        1: Polygon, 727 vertices
        2: Polygon, 3920 vertices
        3: Polygon, 1778 vertices
        4: Polygon, 3687 vertices

Since there are different types of geometries in the result, you get a GeometryCollection instead of a simple MultiPolygon when you take the geometry of the collection (which is a little dangerous to do anyway; e.g.: if the polygons ever overlap, you get the difference in the overlapping regions). You can filter out the linestring with a map (or as you found, just flatten it with a a dissolve):

var filtered = unioncounties.geometries().map(function(g) {
  var type = ee.Geometry(g).type();
  return ee.Algorithms.If(ee.Algorithms.IsEqual(type, "Polygon"), g, null)
}, true)

unioncounties = ee.FeatureCollection(ee.Geometry.MultiPolygon(filtered))
2
  • Thanks for the explanation, it makes sense. However, there must be something else going on as well, as when I shorten the county list to exclude the county that had the linestring, .geometry() still is not merging the geometries anymore. Code: code.earthengine.google.com/fcc920716499736cdda75f9863b5df24 Again, the strange thing is that merging geometries this way was working fine a week or more ago so something must have changed in the EE inner-workings recently. (The code I am using has not changed and it does not seem to matter what FC I test it on, the behavior has changed) – l_r May 10 at 12:41
  • Updated original question above to show this still is not working even when LineString geometries are excluded – l_r May 26 at 18:11

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.