10

For debugging it would be great to figure out which EE object type an object is.

Example code which adds a buffer to a point in a random area:

var polygon = ee.Geometry.Point([0,51.477]).buffer(10000); // a circle in London
var random_points = ee.FeatureCollection.randomPoints(polygon.bounds(), 100); // 100 random points in London
var point_list = random_points.geometry().geometries();
print(point_list); // prints -- List (100 elements)
var one_point = point_list.get(10); // The 11th point.
print(one_point); // prints -- Point (-0.03, 51,52)
var small_circle = one_point.buffer(100);
print(small_circle); // Error -- one_point.buffer is not a function...

Since the console prints Point..., I would think that one_point is of type ee.Geometry.Point. However, according to the docs ee.Geometry objects are supposed to support the .buffer() function, which this one does not support. Hence I assume it's a different kind of object but I have no clue which. When I code in Earth Engine, I run into these kind of problems very frequently.

Is there a way to figure out which type of EE object an object is? Something like the fantasy .EE_OBJECT_TYPE() function here:

print(polygon.EE_OBJECT_TYPE()); // should print -- ee.Geometry.Polygon
print(one_point.EE_OBJECT_TYPE()); // should print -- ee.WhateverObjectThisIs

Non-solutions:

  • print(my_object) often indicates the type of object but, as the example above demonstrates, this is not always the case (or correct).
  • my_object.type() only specifies the kind of ee.Geometry and doesn't work on any other EE objects according to the docs.
  • my_object.typeOf() always returns object for EE objects.

3 Answers 3

5

The answer is dangerously close to your non-solution, but the type of object you're dealing with is ee.ComputedObject. The solution to your issue in this case is to cast to ee.Geometry.

var polygon = ee.Geometry.Point([0,51.477]).buffer(10000); // a circle in London    
var random_points = ee.FeatureCollection.randomPoints(polygon.bounds(), 100); // 100 random points in London
var point_list = random_points.geometry().geometries();
print(point_list); // prints -- List (100 elements)
var one_point = point_list.get(10); // The 11th point.
print(one_point); // prints -- Point (-0.03, 51,52)
var small_circle = ee.Geometry(one_point).buffer(100);
print(small_circle);

print(one_point instanceof ee.ComputedObject) // true
4
  • Is is a valid use-case to request the type off ee.Object ?
    – intotecho
    Sep 21, 2017 at 8:23
  • This behavior is typical for the platform, there are many cases in which you have to type cast the results. For example, the List.get() function returns an Computed Object, so you have to cast the result. Sep 22, 2017 at 1:25
  • Very helpful but doesn't answer the question as asked in the title and in bold. I didn't know about instanceof and it's pretty helpful. Thanks! However, I'm looking for a function that returns the prototype hierarchy of an object -- i. e. all the objects (or just EE objects) for which instanceof would return true.
    – Joooeey
    Sep 25, 2017 at 19:37
  • However, instanceof can be misleading. For instance, ee.Geometry(ee.Feature(ee.Geometry.Point([0,51.477]))) returns an ambiguous object. It's mostly a feature because it's printed as a feature and only supports the functions of an ee.Feature object. However it's an instance of ee.Geometry and not of ee.Feature.
    – Joooeey
    Sep 25, 2017 at 22:33
3

one_point.name() // ComputedObject returns what type this object is cast to. From my quick tests it looks like that's the lowest-level object prototype for which instanceof returns true. Source (You need to log in to access this link but everyone working with EE can get access to this group.)

Good old print(one_point) returns the 'actual' object type (followed by the object itself) -- i. e. how the object behaves.

These can differ. To really understand an object, you'll need to call both. If you want to use the object as a function parameter for a function that only takes e.g. ee.Geometry, you'll need one_point.name() === 'Geometry'. The type indicated by print() tells you which functions the object supports.

These conclusions are only derived from a few tests I did and could be wrong.

-2

You can use type: type(my_object).

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.