Python Toolbox에서 ArcGIS Reclassify 실패
잠수함 산사태를 분석하기 위해 Python Toolbox를 구축하려고합니다. 무엇보다도 저는 aspect 도구를 실행하고 45도 간격으로 측면을 그룹으로 재 분류하고 싶습니다. 따라서 다음을 수행합니다.
import arcpy
import arcpy.sa
arcpy.env.workspace = r'C:\FIP_Tools20191118\GIS_files\SBP_Toolbox.gdb'
arcpy.CheckOutExtension('Spatial')
aspect_ras = arcpy.sa.Aspect('Smooth_Bathymetry', 'PLANAR', 'METER')
aspect_ras.save('aspect_raster')
remap = RemapRange([[0, 45, 45], [45, 90, 90], [90, 135, 135], [135, 180, 180], [180, 225, 225], [225, 270, 270], [270, 315, 315], [315, 360, 360]])
reclass_ras = arcpy.sa.Reclassify('aspect_raster', 'Value', remap, 'NODATA')
arcpy.CopyRaster_management(reclass_ras, 'reclass_Ras')
이상한 점은 위의 코드가 Pycharm 또는 ArcGIS Python 창에서 실행하는 한 잘 작동하지만 Python 도구 상자 (.pyt)에 넣고 실행하려고하면 다음 오류가 발생한다는 것입니다.
오류 000864 : 재 분류 : 입력이 정의 된 도메인 내에 없습니다.
오류 000893 : 빈 GP 값 또는 텍스트가 입력되었습니다.
도구 상자에서 작동하지 않는 이유를 정말로 이해하지 못합니다. 그렇지 않으면 작동한다는 사실은 내 코드 내에 근본적인 문제가 없다는 것을 알려주기 때문에 내가 놓친 배경 자료가 될 것으로 예상하는 이유입니다. 나는 여기서 정말로 헤매고있다.
Windows 10에서 ArcGIS 10.6.1을 사용하고 있습니다.
답변
좋아, 사실 방금 고쳤어. 내 질문에 답하려면 약간의 추가 배경 정보를 제공해야합니다.
기본적으로 aspect interval은 하드 코딩되지 않고 매개 변수를 통해 제공됩니다. 그러나 값을 문자열로 반환하는 .ValueAsText 메서드를 통해 액세스되었습니다. 그러나 나중에 오류가 발생하는 정수로 처리됩니다. 확실히 PyCharm에서는 잘 작동하지만 .pyt로는 작동하지 않는 이유도 확실합니다. 아래 mwe를 참조하십시오.
import arcpy
from arcpy.sa import *
arcpy.CheckOutExtension('Spatial')
class Toolbox(object):
def __init__(self):
"""Define the toolbox (the name of the toolbox is the name of the
.pyt file)."""
self.label = "ShearBandPropagation"
self.alias = "Shear Band Propagation"
# List of tool classes associated with this toolbox
self.tools = [CreateGeometry]
def getParameterInfo(self):
"""Define parameter definitions"""
param0 = arcpy.Parameter(
displayName='Workspace',
name='workspace',
datatype='DEWorkspace',
parameterType='Required',
direction='Input')
param1 = arcpy.Parameter(
displayName='Smooth Bathymetry',
name='smooth_bathymetry',
datatype='Raster Layer',
parameterType='Required',
direction='Input')
param2 = arcpy.Parameter(
displayName='Aspect Interval',
name='aspect_interval',
datatype='GPLong',
parameterType='Required',
direction='Input')
param2.value = 45
param2.filter.type = "Range"
param2.filter.list = [1, 360]
param3 = arcpy.Parameter(
displayName='Output',
name='output_name',
datatype='Raster Layer',
parameterType='Required',
direction='Output')
params = [param0, param1, param2, param3]
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."""
workspace = parameters[0].valueAsText
smooth_bathymetry = parameters[1].valueAsText
aspect_interval = parameters[2].valueAsText
output = parameters[3].ValueAsText
aspect_ras = arcpy.sa.Aspect(smooth_bathymetry, 'PLANAR', 'METER')
aspect_ras.save('aspect_raster')
reclassified_list = [] # create values for remap range based on input parameter
# here is where it went wrong: the correct thing to do would have been: aspect_range = int(aspect_interval)
aspect_range = aspect_interval
while aspect_range <= 360:
if aspect_range % 1 != 0:
reclassified_list.append([aspect_range - aspect_interval, aspect_range, int(aspect_range*10)])
aspect_range += aspect_interval
else:
reclassified_list.append([aspect_range - aspect_interval, aspect_range, int(aspect_range)])
aspect_range += aspect_interval
reclass_ras = arcpy.sa.Reclassify('aspect_raster', 'Value', RemapRange(reclassified_list), 'NODATA')
arcpy.CopyRaster_management(reclass_ras, output)