Skip to main content

创建类

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

要将类作为地理处理工具的输入参数,您必须先创建类。 进行实例化后,即可访问其属性并查询或修改对象。 了解如何创建多种类对象的最佳方式是查看使用不同输入类型创建类的示例。

提示:

每个类的文档包含一个脚本示例,说明如何定义每个类以及如何将其用于工具参数。

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

  • 以下是根据固定数量的输入创建多种类的示例:

    # Creating a neighborhood class and assigning it to a variable
    neighborhood = NbrRectangle(10, 10, "CELL")
    outFocalStats = FocalStatistics(inRas, neighborhood, "MINORITY")
    
    # Creating the Kriging model to be used
    kModelOrdinary = KrigingModelOrdinary("CIRCULAR", 2000, 2.6, 542, 0)
    # Creating a radius class and assigning it to a variable
    kRadius = RadiusFixed(20000, 1)
    outKriging = Kriging(inFeatures, field, kModelOrdinary, cellSize,
                         kRadius, outVarRaster)
    

使用 Python 列表或列表中的列表创建的类

  • 以下是根据列表创建类以用于地形转栅格工具的实例:

    # Create classes as input for TopoToRaster
    myTopoPtElev = TopoPointElevation([["spots.shp", "spot_meter"],
                                       ["spots2.shp", "elev"]])
    myTopoContour = TopoContour([["contours.shp", "spot_meter"]])
    myTopoBoundary = TopoBoundary(["boundary.shp"])
    myTopoLake = TopoLake(["lakes.shp"])
    myTopoSink = TopoSink([["sink1.shp", "elevation"], ["sink2.shp", "NONE"]])
    myTopoStream = TopoStream(["streams.shp"])
    # Applying the tool
    outTopoToRaster = TopoToRaster([myTopoPtElev, myTopoContour, myTopoBoundary,
                                    myTopoLake, myTopoSink, myTopoStream])
    
  • 以下是根据列表创建类以用于重分类工具的实例:

    # The RemapValue class has a usage of:
    #   RemapRange(startValue, endValue, newValue)
    RemapTable = RemapValue([[1, 5], [2, 8], [3, 1], [4, 10]])
    # Run the tool
    outReclass = Reclassify("inRas", RemapTable)
    

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

  • 以下是根据列表中的一系列 Point 类创建类的示例(将用于栅格像元提取):

    # Identify the points to be extracted by creating a list
    #   of Point objects.
    PointsToExtract = [Point(0, 5), Point(15, 175), Point(225, 450)]
    # Run the tool
    Outraster = ExtractByPoints(PointsToExtract)
    

默认参数

  • 某些参数为可选参数,在使用过程中通过 {}(括号或大括号)定义。 例如,楔形邻域类的语法如下:

    NbrWedge({radius}, {startAngle}, {endAngle}, {units})
    
  • 如果未指定可选参数,则将使用默认值。

    # The circle neighborhood will default to
    #   a radius of 3 and units of CELL
    circle = NbrCircle()
    
  • 可以使用空引号 ""# 来指定可选参数,表示要跳过该值,并且需要默认值。