Google Earth Engine Union – How to Get Union of Multiple Linestrings and Polygons in Google Earth Engine

google-earth-enginelinestringpolygonunion

I want to get the union of a list of multiple LineStrings and Polygons. The variable geoLeyte contains this list, but if I want to use the .dissolve() attribute, it gives an error. Who could help me?

var table = table.filter(ee.Filter.eq('ADM2_EN', 'Leyte'))

Map.centerObject(table)
Map.addLayer(table, {}, 'Leyte')

var geoLeyte = table.geometry().geometries()
var union = ee.Geometry.MultiPolygon(geoLeyte).dissolve() 
print(union)

See code here https://code.earthengine.google.com/dcc98657ae22092ed4909e02c96965cf

Best Answer

You've taken too many steps. Once you've called geometries(), you've turned it into a list, and getting back from there is tough if they're not all the same type. Just dissolve the table's geometry directly.

var geoLeyte = table.geometry().dissolve()

That said, the resulting geometry is pretty big, so you're probably going to run into problems using it. You should consider trying to use the original table directly instead.