Skip to main content

查询类

需具备 Spatial Analyst 许可方可使用。

您可能希望识别形式参数中使用的单个实际参数,并根据该值执行一组特定的函数。 以下部分提供了查询 Spatial Analyst 类的实际参数的规则。

使用固定数量的输入创建的类

  • 要查询类对象中的实际参数的值,您可以访问对象属性。

    circle = NbrCircle(5, "CELL")
    # varRadius will be assigned the radius property (which is 5)
    varRadius = circle.radius
    
  • 您可以查看对象的值或对象属性。

    >>> circle = NbrCircle(5, "CELL")
    >>> print(circle)
    Circle 5 Cell
    >>> print(circle.radius)
    5
    

根据列表或列表中的列表创建的类

  • 要查看整个重映射表,您可以使用 Python 的 print 函数。

    >>> remap = RemapValue([[1, 11], [2, 12], [3, 13]])
    >>> print(remap)
    1 11; 2 12; 3 13
    >>> print(remap.remapTable)
    [[1, 11], [2, 12], [3, 13]]
    
  • 要查询根据列表中的列表创建的类对象列表中的条目,请识别该条目所在的列表并确定该条目在列表中的位置。

    >>> remap = RemapValue([[1, 11], [2, 12], [3, 13]])
    >>> print(remap.remapTable[1][1])
    12
    

根据列表中的一系列类创建的类

  • 要查询根据列表中一系列类创建的类对象列表中的点的单个 x 或 y 坐标或 x,y 坐标,请访问输入系列中单个类的属性。

    >>> points = [Point(0, 5), Point(15, 175), Point(225, 450)]
    >>> # The following statement queries the x value of the second input point
    >>> xvalue = points[1].X
    >>> print(xvalue)
    15.0
    

类型确定

  • 要确定类对象的类型,可以使用 Python 的 type 函数。

    >>> neighborhood = NbrCircle(5, "CELL")
    >>> neighType = type(neighborhood)
    >>> print(neighType)
    <class 'arcpy.sa.ParameterClasses.NbrCircle'>
    
  • 要比较类型,可以使用 Python 的 isinstance 函数。

    circle = NbrCircle(5, "CELL")
    # The general format is: isinstance(AnyObject, AnyClass)
    # In the following statement, val will be assigned True
    val = isinstance(circle, NbrCircle)
    # In the following statement, val will be assigned False
    val = isinstance(circle, NbrRectangle)