I am trying to use in Google Earth Engine the function area() or centroid() on a simple polygon. According to the documentation, there seems to exist a method area() for objects ee.Geometry.Polygon. However, I get an error message with this simple code:

var polygon = ee.Geometry.Polygon([
  [[-5, 40], [65, 40], [65, 60], [-5, 60], [-5, 60]]

var a = area(polygon);
var aa = polygon.area();

Gives message:

"area" is not defined in this scope.

What am I doing wrong?

  • 1
    var a = area(polygon); is probably what is giving the error. Remove it. The remainder of the code looks valid according to developers.google.com/earth-engine/geometry_visualization_info
    – kttii
    Nov 15, 2016 at 20:52
  • 1
    Should the last coordinate be a repeat of the first coordinate? I see it's right from the doc. However, on this page, the last coordinate is a repeat of the first coordinate.
    – mkennedy
    Nov 15, 2016 at 21:43
  • Thanks @kttii , you are right! Happy to accept your solution if you post it. I am not sure in general why functionobject) does not work, and one needs object.function()? I thought these were interchangeable? As a coutnerexampl, one should use ee.Feature(object), not object.ee.Feature() ... what's the rule?
    – Matifou
    Nov 16, 2016 at 18:10

1 Answer 1


var a = area(polygon); is what is giving the error. Remove it because it is not a valid function in this context.

The remainder of the code looks valid according to http://developers.google.com/earth-engine/geometry_visualization_in‌​fo

Your Answer

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

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