Return a tree structure representing an EE object. The source code was adapted from https://github.com/google/earthengine-jupyter. Credits to Tyler Erickson. Args: ee_object: The Earth Engine object. layer_name: The name of the layer. opened: Whether to expand t
(
ee_object: ee.FeatureCollection | ee.Image | ee.Geometry | ee.Feature,
layer_name: str = "",
opened: bool = False,
)
| 192 | |
| 193 | |
| 194 | def build_computed_object_tree( |
| 195 | ee_object: ee.FeatureCollection | ee.Image | ee.Geometry | ee.Feature, |
| 196 | layer_name: str = "", |
| 197 | opened: bool = False, |
| 198 | ) -> dict[str, Any]: |
| 199 | """Return a tree structure representing an EE object. |
| 200 | |
| 201 | The source code was adapted from https://github.com/google/earthengine-jupyter. |
| 202 | Credits to Tyler Erickson. |
| 203 | |
| 204 | Args: |
| 205 | ee_object: The Earth Engine object. |
| 206 | layer_name: The name of the layer. |
| 207 | opened: Whether to expand the tree. |
| 208 | |
| 209 | Returns: |
| 210 | The node representing the Earth Engine object information. |
| 211 | """ |
| 212 | # Convert EE object props to dicts. It's easier to traverse the nested structure. |
| 213 | if isinstance(ee_object, ee.FeatureCollection): |
| 214 | ee_object = ee_object.map(lambda f: ee.Feature(None, f.toDictionary())) |
| 215 | |
| 216 | layer_info = ee_object.getInfo() |
| 217 | if not layer_info: |
| 218 | return {} |
| 219 | |
| 220 | # Strip geometries because they're slow to render as text. |
| 221 | if "geometry" in layer_info: |
| 222 | layer_info.pop("geometry") |
| 223 | |
| 224 | # Sort the keys in layer_info and the nested properties. |
| 225 | if properties := layer_info.get("properties"): |
| 226 | layer_info["properties"] = dict(sorted(properties.items())) |
| 227 | ordering_list = ["type", "id", "version", "bands", "properties"] |
| 228 | layer_info = _order_items(layer_info, ordering_list) |
| 229 | |
| 230 | ee_type = layer_info.get("type", ee_object.__class__.__name__) |
| 231 | |
| 232 | band_info = "" |
| 233 | if bands := layer_info.get("bands"): |
| 234 | band_info = f" ({len(bands)} bands)" |
| 235 | if layer_name: |
| 236 | layer_name = f"{layer_name}: " |
| 237 | |
| 238 | return new_tree_node( |
| 239 | f"{layer_name}{ee_type}{band_info}", |
| 240 | _generate_tree(layer_info, opened), |
| 241 | expanded=opened, |
| 242 | ) |
| 243 | |
| 244 | |
| 245 | def get_info( |
no test coverage detected