Different Results in GEE when using manually upload polygon and uploaded shapefile
When you use .geometry()
on a FeatureCollection, you're getting back a Geometry
object, not a Geometry.MultiPolygon
object. Try these in your code at the beginning:
print(shapefile.geometry() instanceof ee.Geometry.MultiPolygon);
print(Manual_test instanceof ee.Geometry.MultiPolygon);
You'll get false and then true. shapefile.geometry()
is an instanceof ee.Geometry
.
You can then turn around and pass that to the MultiPolygon constructor which expects a list of coordinates:
var geometry=ee.Geometry.MultiPolygon(shapefile.geometry().coordinates());
Your Shapefile has now been successfully converted to a MultiPolygon and you get the mosaiced result that you're looking for.
I think more broadly, the issue you're running into is that when you have a Multipolygon you're mapping a function onto each distinct polygon and mosaicing the result. That's not what happens with a FeatureCollection - it's considering the geometries of the collection in aggregate and producing one result. If you consider how you're handling the distinct object types in your code:
var ndviClassImg = geometry instanceof ee.Geometry.MultiPolygon
? ee.ImageCollection(
geometry.coordinates().map(function (coordinates) {
return getNdviClassImg(ee.Geometry.Polygon(coordinates));
})
).mosaic()
: getNdviClassImg(geometry);
You can see where the mosaicing happens for the MultiPolygon.