ArcGIS จัดประเภทใหม่ล้มเหลวใน Python Toolbox

Sep 28 2020

ฉันกำลังพยายามสร้าง Python Toolbox เพื่อวิเคราะห์การถล่มของเรือดำน้ำ เหนือสิ่งอื่นใดฉันต้องการเรียกใช้เครื่องมือด้านมุมมองจากนั้นจัดประเภทด้านใหม่เป็นกลุ่มโดยมีช่วงเวลา 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 ว่างหรือข้อความ

ฉันไม่เข้าใจจริงๆว่าทำไมมันไม่ทำงานในกล่องเครื่องมือ ความจริงที่ว่ามันใช้งานได้เป็นอย่างอื่นบอกฉันว่าไม่มีปัญหาพื้นฐานในโค้ดของฉันซึ่งเป็นสาเหตุที่ฉันคาดหวังว่ามันจะเป็นพื้นหลังบางอย่างที่ฉันขาดหายไป ฉันสูญเสียที่นี่จริงๆ

ฉันใช้ ArcGIS 10.6.1 บน Windows 10

คำตอบ

1 coleuch Sep 28 2020 at 19:56

ตกลงตอนนี้ฉันเพิ่งแก้ไขไปแล้ว ในการตอบคำถามของฉันฉันต้องให้ข้อมูลพื้นฐานเพิ่มเติมเล็กน้อย:

โดยทั่วไปแล้วช่วงเวลาภาพไม่ได้ถูกเข้ารหัสอย่างหนัก แต่จะจัดทำผ่านพารามิเตอร์ อย่างไรก็ตามมันถูกเข้าถึงผ่านเมธอด. 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)