Changing arguments within classes

Available with Spatial Analyst license.

You may wish to change an individual argument to a parameter because you have gained additional information about the phenomena that you were modeling, you would like to test alternative scenarios, you would like to perform error or sensitivity analysis, or you would simply like to correct an error. Through a series of examples, you will learn how to change the wide variety of input arguments.

Changing class values or properties

  • To change a value of a class object, you can just re-create the class.
    neighborhood = NbrCircle(5, "MAP")
    
    # The neighborhood object can be changed from a circle to a rectangle
    neighborhood = NbrRectangle(3, 3, "MAP")
  • A single argument can be directly changed by accessing the property that stores the argument within the object.
    >>> neighborhood = NbrCircle(5, "MAP")
    >>> # The following statements change the radius to 7 and the units to CELL
    >>> neighborhood.radius = 7 
    >>> neighborhood.units = "CELL"
    
    >>> print(neighborhood)
    CIRCLE 7 CELL
  • A numeric argument stored as a property within an object can be changed algebraically.
    circle = NbrCircle(5, "CELL")
    
    # The following statement changes the radius to 5.5
    circle.radius = circle.radius * 1.1

    You can also use an assignment operator to change the value.

    # The following statement changes the radius to 5.5
    circle.radius *= 1.1

Changing classes created with python lists

  • You can add elements to the inFeatures list for classes that were created from lists.
    >>> arguments = TopoStream(["features1", "features2"]) 
    
    >>> arguments.inFeatures.append("features3")
    >>> arguments.inFeatures += ["features4", "features5"]
    
    >>> print(arguments.inFeatures)
    ['features1', 'features2', 'features3', 'features4', 'features5']
  • You can also delete an element from the input list.
    >>> arguments = TopoStream(["features1", "features2", "features3", "features4", "features5"])
    >>> del arguments.inFeatures[2]
    
    >>> print(arguments.inFeatures)
    ['features1', 'features2', 'features4', 'features5']
  • You can change a specific entry within the list.
    >>> arguments = TopoStream(["features1", "features2"]) 
    >>> arguments.inFeatures[1] = "lake2"
    
    >>> print(arguments.inFeatures)
    ['features1', 'lake2']

Classes created with lists within lists

  • You can change an entry in a remap table (altering entries within inner lists) for classes that were created from lists within lists.
    >>> remap = RemapValue([[1, 11], [2, 12], [3, 13]])
    
    >>> # Change the newValue 12 in the second reclassification to a 10
    >>> remap.remapTable[1][1] = 10
    
    >>> print(remap.remapTable)
    [[1, 11], [2, 10], [3, 13]]
  • An individual entry in a remap table can be changed algebraically.
    remap = RemapRange([[1, 10, 5], [10, 20, 8], [20, 30, 10]])
    
    # The following statement increases the endValue 20 by 5 percent
    remap.remapTable[1][1] *= 1.05 
    
    # Another implementation of increasing an entry by 5 percent
    remap.remapTable[1][1] = remapTable.table[1][1] * 1.05
  • This shows how to change an individual row in the remap table (altering entire inner lists).
    >>> remap = RemapValue([[1, 11], [2, 12], [4, 13]])
    
    >>> # Change the second reclassification [2, 12] to [3,10]
    >>> remap.table[1] = [3, 10]
      
    >>> print(remap.remapTable)
    [[1, 11], [3, 10], [4, 13]]
  • This shows how to add entries to a remap table (adding an inner list).
    >>> remap = RemapValue([[1, 11], [2, 12], [3, 13]])
    
    >>> # Add a forth reclassification, [4, 14] to the end
    >>> remap.remapTable.append([4, 14]) 
    
    >>> # Another approach for adding a row
    >>> remap.remapTable += [[5, 15]] 
    
    >>> print(remap.remapTable)
    [[1, 11], [2, 12], [3, 13], [4, 14], [5, 15]]
  • This shows how to delete entries from a remap table (deleting an inner list).
    >>> remap = RemapValue([[1, 11], [2, 12], [3, 13], [4, 14], [5, 15]])
    
    >>> # Delete the entire second reclassification
    >>> del remap.remapTable[1]
    
    >>> print(remap.remapTable)
    [[1, 11], [3, 13], [4, 14], [5, 15]]

Classes created from a series of classes within a list

  • You can change a specific point within the list for a class that was created from a series of classes within a list.
    >>> points = [Point(0, 5), Point(15, 175)]
    
    >>> # Change the X value of the second input to 25
    >>> points[1].X = 25 
    
    >>> print(points)
    [<Point (0.0, 5.0, #, #)>, <Point (25.0, 175.0, #, #)>]

Related topics