ValueTable (arcpy)
摘要
值表是一种灵活的对象,可用作多值参数的输入。它仅在创建此表的地理处理对象的生存时间内存在。
讨论
setRow 的值参数以空格分隔。所有含空格值参数中使用的值均必须用引号括起。在下例中,向包含两列的值表中分别添加了一个要素类和一个索引值:
value_table.setRow(0, "'c:/temp/land use.shp' 2")
语法
参数 | 说明 | 数据类型 |
columns |
The number of columns. (默认值为 1) | Integer |
属性
属性 | 说明 | 数据类型 |
columnCount (只读) |
The number of columns. | Integer |
rowCount (只读) |
The number of rows. | Integer |
方法概述
方法 | 说明 |
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: |
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:
|
setValue (row, column, value) |
Updates the value of a given row and column. |
方法
参数 | 说明 | 数据类型 |
value |
The row to be added. | Object |
数据类型 | 说明 |
String |
The string representation of the object. |
参数 | 说明 | 数据类型 |
row |
The row index position. | Integer |
数据类型 | 说明 |
String |
A row from the value table. |
参数 | 说明 | 数据类型 |
row |
The row index position. | Integer |
column |
The column index position. | Integer |
数据类型 | 说明 |
String |
The value of a given column and row. |
参数 | 说明 | 数据类型 |
row |
The row index position. | Integer |
column |
The column index position. | Integer |
数据类型 | 说明 |
String |
The value of a given column and row. |
参数 | 说明 | 数据类型 |
string |
The string representation of the object. | String |
参数 | 说明 | 数据类型 |
row |
The index position of the row to remove. | Integer |
参数 | 说明 | 数据类型 |
number_of_columns |
The number of columns for the value table. | Integer |
参数 | 说明 | 数据类型 |
row |
The index position of the row to update. | Integer |
value |
The value to update the given row. | Object |
参数 | 说明 | 数据类型 |
row |
The row index. | Integer |
column |
The column index | Integer |
value |
The value to update the given row and column. | Object |
代码实例
使用 ValueTable 保存联合工具的要素类名称和等级。
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")
如果已将多值字符串作为参数传递到脚本,则可用其填充值表,以使提取各记录更为简便。以下示例将对此操作方法进行说明:
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 xrange(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)