ValueTable (arcpy)

Resumen

A value table is a flexible object that can be used as input for a multivalue parameter. It exists only during the lifetime of the geoprocessing object that created it.

Debate

setRow's value argument is space delimited. Any value used in the value argument that contains spaces must be enclosed in quotations. In the following example, a value table with two columns has a feature class and an index value added:

vtab.setRow(0, "'c:/temp/land use.shp' 2")

Sintaxis

ValueTable ({columns})
ParámetroExplicaciónTipo de datos
columns

The number of columns.

(El valor predeterminado es 1)

Integer

Propiedades

PropiedadExplicaciónTipo de datos
columnCount
(Sólo lectura)

The number of columns.

Integer
rowCount
(Sólo lectura)

The number of rows.

Integer

Descripción general de los métodos

MétodoExplicación
addRow (value)

Adds a row to the value table.

addRow's value argument is space-delimited. Any value used in the value argument that contains spaces must be enclosed in quotations. In the following example, a value table with two columns has a feature class and an index value added:

vtab.addRow("'c:/temp/land use.shp' 2")

exportToString ()

Exports the object to its string representation.

getRow (row)

Gets a row from the value table.

getTrueValue (row, column)

Gets value from a given column and row.

getValue (row, column)

Gets value from a given column and row.

loadFromString (string)

Restore the object using its string representation. The exportToString method can be used to create a string representation.

removeRow (row)

Deletes a row from the value table.

setColumns (number_of_columns)

Sets the number of columns for the value table.

setRow (row, value)

Updates a given row within the value table.

setRow's value argument is space-delimited. Any value used in the value argument that contains spaces must be enclosed in quotations. In the following example, a value table with two columns has a feature class and an index value added:

vtab.setRow(0, "'c:/temp/land use.shp' 2")
setValue (row, column, value)

Updates the value of a given row and column.

Métodos

addRow (value)
ParámetroExplicaciónTipo de datos
value

The row to be added.

Object
exportToString ()
Valor de retorno
Tipo de datosExplicación
String

The string representation of the object.

getRow (row)
ParámetroExplicaciónTipo de datos
row

The row index position.

Integer
Valor de retorno
Tipo de datosExplicación
String

A row from the value table.

getTrueValue (row, column)
ParámetroExplicaciónTipo de datos
row

The row index position.

Integer
column

The column index position.

Integer
Valor de retorno
Tipo de datosExplicación
String

The value of a given column and row.

getValue (row, column)
ParámetroExplicaciónTipo de datos
row

The row index position.

Integer
column

The column index position.

Integer
Valor de retorno
Tipo de datosExplicación
String

The value of a given column and row.

loadFromString (string)
ParámetroExplicaciónTipo de datos
string

The string representation of the object.

String
removeRow (row)
ParámetroExplicaciónTipo de datos
row

The index position of the row to remove.

Integer
setColumns (number_of_columns)
ParámetroExplicaciónTipo de datos
number_of_columns

The number of columns for the value table.

Integer
setRow (row, value)
ParámetroExplicaciónTipo de datos
row

The index position of the row to update.

Integer
value

The value to update the given row.

Object
setValue (row, column, value)
ParámetroExplicaciónTipo de datos
row

The row index.

Integer
column

The column index

Integer
value

The value to update the given row and column.

Object

Ejemplo de código

ValueTable example

Use ValueTable to hold feature class names and ranks for the Union tool.

import arcpy
from arcpy import env

# Set the workspace. List all of the feature classes in the dataset
#
env.workspace = "C:/Data/Landbase.gdb/Wetlands"
fcs = arcpy.ListFeatureClasses()

# Create the value table for the Analysis Union tool with 2 columns
#
vtab = arcpy.ValueTable(2)

# Iterate through the list of feature classes
#
for fc in fcs:
    # Update the value table with a rank of 2 for each record, except    
    #   for BigBog
    #
    if fc.lower() <> "bigbog":
       vtab.addRow(fc + " 2")
    else:
       vtab.addRow(fc + " 1")

# Union the wetlands feature classes with the land use feature class to create
#   a single feature class with all of the wetlands and land use data
#
vtab.addRow("C:/Data/Landbase.gdb/land_use 2")
arcpy.Union_analysis(vtab, "C:/Data/Landbase.gdb/wetlands_use")
ValueTable example 2

A value table can be populated with a multivalue string that has been passed to a script as an argument, making it easy to extract each record. The example below shows how to do this:

import arcpy
from arcpy import env
import os

# Set the output workspace
#
env.workspace = arcpy.GetParameterAsText(1)

# Create a value table with 2 columns
#
vtab = arcpy.ValueTable(2)

# Set the values of the table with the contents of the first argument
#
vtab.loadFromString(arcpy.GetParameterAsText(0))
x = 1

# Loop through the list of inputs
#
while x < vtab.rowCount:
    # Validate the output name for the new workspace
    #
    name = vtab.getRow(x)
    out_name = arcpy.ValidateTablename(os.path.basename(name))

    # Copy the features to the new workspace
    #
    arcpy.CopyFeatures_management(name, out_name)
    x += 1

Temas relacionados

9/11/2013