-
Notifications
You must be signed in to change notification settings - Fork 81
/
Copy pathKeyMetadata.py
73 lines (61 loc) · 2.38 KB
/
KeyMetadata.py
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
class KeyMetadata():
def __init__(self):
self.name = "Key Metadata Function"
self.description = "Override key metadata in a function chain."
self.propertyName = ''
self.propertyValue = None
self.bandNames = []
def getParameterInfo(self):
return [
{
'name': 'raster',
'dataType': 'raster',
'value': None,
'displayName': "Raster",
'required': True,
'description': "The primary raster input."
},
{
'name': 'property',
'dataType': 'string',
'value': '',
'displayName': "Property Name",
'required': False,
'description': "The name of the optional key metadata to override."
},
{
'name': 'value',
'dataType': 'string',
'value': None,
'displayName': "Property Value",
'required': False,
'description': "The overriding new value of the key metadata."
},
{
'name': 'bands',
'dataType': 'string',
'value': '',
'displayName': "Band Names",
'required': False,
'description': "A comma-separated string representing updated band names."
}
]
def getConfiguration(self, **scalars):
return {
'invalidateProperties': 8, # reset any key properties held by the parent function raster dataset
}
def updateRasterInfo(self, **kwargs):
self.propertyName = kwargs.get('property', "") # remember these user-specified scalar inputs
self.propertyValue = kwargs.get('value', "")
self.bandNames = []
b = kwargs.get('bands', "").strip()
if len(b) > 0:
self.bandNames = b.split(',')
return kwargs
def updateKeyMetadata(self, names, bandIndex, **keyMetadata):
if bandIndex == -1:
if len(self.propertyName) > 0:
keyMetadata[self.propertyName] = self.propertyValue
elif bandIndex < len(self.bandNames):
keyMetadata['bandname'] = self.bandNames[bandIndex]
return keyMetadata