forked from GISGIT/GEE-Python-API
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathelement.py
More file actions
executable file
·94 lines (76 loc) · 3.04 KB
/
element.py
File metadata and controls
executable file
·94 lines (76 loc) · 3.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env python
"""Base class for Image, Feature and Collection.
This class is never intended to be instantiated by the user.
"""
# Using lowercase function naming to match the JavaScript names.
# pylint: disable=g-bad-name
from . import apifunction
from . import computedobject
from . import ee_exception
class Element(computedobject.ComputedObject):
"""Base class for ImageCollection and FeatureCollection."""
_initialized = False
def __init__(self, func, args, opt_varName=None):
"""Constructs a collection by initializing its ComputedObject."""
super(Element, self).__init__(func, args, opt_varName)
@classmethod
def initialize(cls):
"""Imports API functions to this class."""
if not cls._initialized:
apifunction.ApiFunction.importApi(cls, 'Element', 'Element')
cls._initialized = True
@classmethod
def reset(cls):
"""Removes imported API functions from this class."""
apifunction.ApiFunction.clearApi(cls)
cls._initialized = False
@staticmethod
def name():
return 'Element'
def set(self, *args):
"""Overrides one or more metadata properties of an Element.
Args:
*args: Either a dictionary of properties, or a vararg sequence of
properties, e.g. key1, value1, key2, value2, ...
Returns:
The element with the specified properties overridden.
"""
if len(args) == 1:
properties = args[0]
# If this is a keyword call, unwrap it.
if (isinstance(properties, dict) and
(len(properties) == 1 and 'properties' in properties) and
isinstance(properties['properties'],
(dict, computedobject.ComputedObject))):
# Looks like a call with keyword parameters. Extract them.
properties = properties['properties']
if isinstance(properties, dict):
# Still a plain object. Extract its keys. Setting the keys separately
# allows filter propagation.
result = self
for key, value in properties.items():
result = apifunction.ApiFunction.call_(
'Element.set', result, key, value)
elif (isinstance(properties, computedobject.ComputedObject) and
apifunction.ApiFunction.lookupInternal('Element.setMulti')):
# A computed dictionary. Can't set each key separately.
result = apifunction.ApiFunction.call_(
'Element.setMulti', self, properties)
else:
raise ee_exception.EEException(
'When Element.set() is passed one argument, '
'it must be a dictionary.')
else:
# Interpret as key1, value1, key2, value2, ...
if len(args) % 2 != 0:
raise ee_exception.EEException(
'When Element.set() is passed multiple arguments, there '
'must be an even number of them.')
result = self
for i in range(0, len(args), 2):
key = args[i]
value = args[i + 1]
result = apifunction.ApiFunction.call_(
'Element.set', result, key, value)
# Manually cast the result to an image.
return self._cast(result)