-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathraster_input.py
41 lines (35 loc) · 1.23 KB
/
raster_input.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 arcpy
from arcpy import env
from arcpy.sa import *
# Check out Spatial Analyst license
arcpy.CheckOutExtension("spatial")
class RasterInput:
"""
A single data input to the combination process, consisting of:
- a raster file
- a weighting coefficient (value between 0 and 1)
- flag indicating whether to invert values before processing
"""
def __init__(self, raster, weighting=0.125, inverse_required=False, overlay_method='SUM'):
self.raster = raster
self.weighted_raster = None
self.weighting = float(weighting) # must be numeric
self.inverse_required = inverse_required
self.overlay_method = overlay_method
def invert_if_required(self):
"""
Invert raster cell values if required
To do this we just subtract the raster from 1
"""
if self.inverse_required:
self.raster = Minus(1,self.raster)
return self.raster
def weigh(self):
"""
Multiply raster cell values by weighting coefficient
"""
self.invert_if_required()
self.weighted_raster = Times(self.raster, self.weighting)
return self.weighted_raster
def __unicode__(self):
return self.raster