-
Notifications
You must be signed in to change notification settings - Fork 0
/
ApplyScaleFactor_Tool.py
68 lines (56 loc) · 2.17 KB
/
ApplyScaleFactor_Tool.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
import os
import sys
import arcpy
class ApplyScaleFactor(object):
def __init__(self):
"""Define the tool (tool name is the name of the class)."""
self.label = "ApplyScaleFactor"
self.description = ""
def getParameterInfo(self):
"""Define parameter definitions"""
# First parameter
param0 = arcpy.Parameter(
displayName="Input Raster Layer",
name="in_raster",
datatype="GPRasterLayer",
parameterType="Required",
direction="Input")
# Second parameter
param1 = arcpy.Parameter(
displayName="Scale Factor",
name="scale_factor",
datatype="Double",
parameterType="Required",
direction="Input")
# Third parameter
param2 = arcpy.Parameter(
displayName="Output Raster Layer",
name="out_raster",
datatype="DERasterDataset",
parameterType="Required",
direction="Output")
params = [param0, param1, param2]
return params
def isLicensed(self):
"""Set whether tool is licensed to execute."""
return True
def updateParameters(self, parameters):
"""Modify the values and properties of parameters before internal
validation is performed. This method is called whenever a parameter
has been changed."""
return
def updateMessages(self, parameters):
"""Modify the messages created by internal validation for each tool
parameter. This method is called after internal validation."""
return
def execute(self, parameters, messages):
"""The source code of the tool."""
inRaster = parameters[0].valueAsText
scaleFactor = parameters[1].value
outRaster = parameters[2].valueAsText
r = arcpy.Raster(inRaster)
a = arcpy.RasterToNumPyArray(r)
ext = r.extent
llc = arcpy.Point(ext.XMin, ext.YMin)
r_scaled = arcpy.NumPyArrayToRaster((a*scaleFactor), llc, r.meanCellWidth, r.meanCellWidth, (r.noDataValue*scaleFactor))
return(r_scaled.save(outRaster))