0

This works:

(with geometry being a Polygon and sent3 an ImageCollection):

var image = sent3.filterBounds(roi).first();
var mask = image.select("Oa07_radiance").mask().rename('mask');
var area = ee.Image.pixelArea().multiply(mask).rename('area');

var sumDictionarypolygon1 = mask.addBands(area).reduceRegion({
  reducer: ee.Reducer.sum(),
  geometry: roi,
  scale: 300,
  maxPixels: 1e9
});
print('sum for pol 1 mask, scale=300', sumDictionarypolygon1);

While this does not (roi being a Feature containing a geometry)

var rois = ee.FeatureCollection("users/guillaumh/embalsescba"),
    sent3 = ee.ImageCollection("COPERNICUS/S3/OLCI");
var roi = rois.toList(99).get(26);
print(roi);

var image = sent3.filterBounds(roi).first();
var mask = image.select("Oa07_radiance").mask().rename('mask');
var area = ee.Image.pixelArea().multiply(mask).rename('area');

var sumDictionarypolygon1 = mask.addBands(area).reduceRegion({
  reducer: ee.Reducer.sum(),
  geometry: ee.Geometry(roi),
  scale: 300,
  maxPixels: 1e9
});
print('sum for pol 1 mask, scale=300', sumDictionarypolygon1);

The error is:

Dictionary (Error)
Feature, argument 'geometry': Invalid type. Expected type: Geometry. Actual type: Feature.

Why cannot I extract the geometry from the feature? It seems ee.Geometry( ) does not do anything.

1 Answer 1

1

First, instead of ee.Geometry(roi) (which in this case is essentially "assume this is already a Geometry", which it isn't), you need to use ee.Feature(roi).geometry(), which returns the geometry of the feature.

Second, you modified your call to reduceRegion but you also wrote filterBounds(roi), which also needs a Geometry rather than a Feature.

Therefore, try this:

var roi = ee.Feature(rois.toList(99).get(26)).geometry();

Then both of the places you use roi will work.

6
  • I also tried this but I'm getting the error roi.geometry is not a function. Also tried with ee.Feature(roi).geometry() and got the error: Dictionary (Error) Feature, argument 'geometry': Invalid type. Expected type: Geometry. Actual type: Feature.
    – gh_
    Commented Jun 11, 2020 at 13:57
  • @gh_ Whoops, you're right, it won't work without a cast … not sure why it isn't working with a cast. Sorry. But if possible, you should avoid converting your (I assume) feature collection to a list — it's inefficient. Use an 'eq' filter instead of looking for a specific index.
    – Kevin Reid
    Commented Jun 11, 2020 at 15:03
  • @gh_ I can't reproduce the error. Could you please edit your question so that it contains complete code to reproduce the error (not having any undefined variables like rois)? You can get the code for drawn features in the Code Editor by clicking on the little button to the right of "Imports". Or a "Get Link" link will also do, but it would be good to have the question edited too.
    – Kevin Reid
    Commented Jun 11, 2020 at 16:37
  • indeed that should be more helpful, done!
    – gh_
    Commented Jun 11, 2020 at 19:16
  • @gh_ I found the problem — your filterBounds also needed a geometry rather than a feature. See my updated answer.
    – Kevin Reid
    Commented Jun 11, 2020 at 21:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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