ValueTable

Zusammenfassung

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.

Diskussion

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:

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

Syntax

 ValueTable  ({columns})
ParameterErläuterungDatentyp
columns

The number of columns.

(Der Standardwert ist 1)

Integer

Eigenschaften

EigenschaftErläuterungDatentyp
columnCount
(Schreibgeschützt)

The number of columns.

Integer
rowCount
(Schreibgeschützt)

The number of rows.

Integer

Methodenübersicht

MethodeErläuterung
addRow (value)

Adds a row to the value table.

exportToString ()

Exports the object to its string representation.

getRow (row)

Returns a row from the ValueTable.

getTrueValue (row, column)

Returns the value from a given column and row.

getValue (row, column)

Returns the value from a given column and row.

loadFromString (string)

Restore or update the spatial reference object using a WKT string. The exportToString method can be used to export a WKT string representation of the spatial reference.

  • Using a WKT string with a horizontal coordinate system.
    # The following string is the WKT for the 
    # Geographic Coordinate system "WGS 1984" (factory code=4326)
    wkt = 'GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],\
                  PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]];\
                  -400 -400 1000000000;-100000 10000;-100000 10000;8.98315284119522E-09;\
                  0.001;0.001;IsHighPrecision'
    
    sr = arcpy.SpatialReference()
    sr.loadFromString(wkt)
  • Using a WKT string with a horizontal and vertical coordinate system. Note that the vertical coordinate system is defined in the VERTCS section of the WKT.
    # The following string is the WKT for the 
    # Geographic Coordinate system "WGS 1984" (factory code=4326), 
    # with a vertical coordinate system "WGS 1984" (factory code=115700)
    
    wkt = 'GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],\
                  PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],\
                  VERTCS["WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],\
                  PARAMETER["Vertical_Shift",0.0],PARAMETER["Direction",1.0],UNIT["Meter",1.0]];\
                  -400 -400 1000000000;-100000 10000;-100000 10000;8.98315284119522E-09;\
                  0.001;0.001;IsHighPrecision'
    
    sr = arcpy.SpatialReference()
    sr.loadFromString(wkt)

removeRow (row)

Deletes a row from the ValueTable object.

setColumns (number_of_columns)

Sets the number of columns for the value table.

setRow (row, value)

Updates a given row within the ValueTable object.

The 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 ValueTable object 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)

Aktualisiert den Wert der angegebenen Spalte und Zeile.

Methoden

addRow (value)
ParameterErläuterungDatentyp
value

The row to be added.

The value argument is space-delimited. Any value used 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")
Object
exportToString ()
Rückgabewert
DatentypErläuterung
String

The WKT string representation of the object.

getRow (row)
ParameterErläuterungDatentyp
row

The row index position.

Integer
Rückgabewert
DatentypErläuterung
String

A row from the ValueTable object.

getTrueValue (row, column)
ParameterErläuterungDatentyp
row

The row index position.

Integer
column

The column index position.

Integer
Rückgabewert
DatentypErläuterung
String

The value of a given column and row.

getValue (row, column)
ParameterErläuterungDatentyp
row

The row index position.

Integer
column

The column index position.

Integer
Rückgabewert
DatentypErläuterung
String

The value of a given column and row.

loadFromString (string)
ParameterErläuterungDatentyp
string

The WKT string representation of the object.

String
removeRow (row)
ParameterErläuterungDatentyp
row

The index position of the row to remove.

Integer
setColumns (number_of_columns)
ParameterErläuterungDatentyp
number_of_columns

The number of columns for the value table.

Integer
setRow (row, value)
ParameterErläuterungDatentyp
row

The index position of the row to update.

Integer
value

The value to update in the given row.

Object
setValue (row, column, value)
ParameterErläuterungDatentyp
row

The row index.

Integer
column

The column index

Integer
value

The value to update the given row and column.

Object

Codebeispiel

ValueTable example

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

import arcpy

# Set the workspace. List all of the feature classes in the dataset
arcpy.env.workspace = "c:/data/landbase.gdb/Wetlands"
feature_classes = arcpy.ListFeatureClasses()

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

# Iterate through the list of feature classes
for fc in feature_classes:
    # Update the value table with a rank of 2 for each record, except
    #   for BigBog
    if fc.lower() != "bigbog":
        value_table.addRow(fc + " 2")
    else:
        value_table.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
value_table.addRow("c:/data/landbase.gdb/land_use 2")
arcpy.Union_analysis(value_table, "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 os
import arcpy

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

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

# Set the values of the table with the contents of the first argument
value_table.loadFromString(arcpy.GetParameterAsText(0))

# Loop through the list of inputs
for i in range(0, value_table.rowCount):
    # Validate the output name for the new workspace
    name = value_table.getRow(i)
    out_name = arcpy.ValidateTableName(os.path.basename(name))

    # Copy the features to the new workspace
    arcpy.CopyFeatures_management(name, out_name)