-
Notifications
You must be signed in to change notification settings - Fork 81
/
Copy pathMaskRaster.py
40 lines (35 loc) · 1.26 KB
/
MaskRaster.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
import numpy as np
class MaskRaster():
def __init__(self):
self.name = "Mask Raster Function"
self.description = "Applies a raster as the NoData mask of the input raster."
def getParameterInfo(self):
return [
{
'name': 'r',
'dataType': 'raster',
'value': None,
'required': True,
'displayName': "Input Raster",
'description': "The primary input raster."
},
{
'name': 'm',
'dataType': 'raster',
'value': None,
'required': True,
'displayName': "Mask Raster",
'description': "The input mask raster."
},
]
def getConfiguration(self, **scalars):
return {
'inputMask': True
}
def updatePixels(self, tlc, shape, props, **pixelBlocks):
M = np.zeros(shape, 'u1')
I = (pixelBlocks['m_pixels'] > 0) & (pixelBlocks['m_mask'] > 0)
np.putmask(M, I, 1)
pixelBlocks['output_mask'] = M
pixelBlocks['output_pixels'] = pixelBlocks['r_pixels'].astype(props['pixelType'], copy=False)
return pixelBlocks