Jerome_lau

GIS is changing the World!
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

注释一段GP工具中Python脚本(读取表中字段信息)

Posted on 2009-05-20 11:06  jerome  阅读(622)  评论(0)    收藏  举报

# ---------------------------------------------------------------------------
# Iterate Field Value.py
# ---------------------------------------------------------------------------

# Import system modules
import sys, string, os, arcgisscripting

# Create the Geoprocessor object
gp = arcgisscripting.create()

# Set the parameters.

# Input feature class or table for which the value has to be read from a field
inputTable = gp.GetParameterAsText(0)
if (inputTable == ''):
    gp.AddError("No input table provided")
    raise "No input table provided"

# The desired field for which the values will be read
inputField = gp.GetParameterAsText(1) #你要检索的字段 手动输入
if (inputField == ''):
    gp.AddError("No input field provided")
    raise "No input field provided"

# Setting value to increment the iteration number for next row in the table
index = int(gp.GetParameterAsText(2))# 让你的迭代次数和对表的索引号一致

# Insert Search Cursor
value = "0" #初始化输出值
bContinue = "false"
currentRow = 0
cur = gp.SearchCursor(inputTable) #开始扫描表
row = cur.Next()# 跳过表头 进入下一行
while row:
    if (index == currentRow):#判断行号和索引是否一致
        value = row.getValue(inputField)#获取该行 该字段中的值
        bContinue = "true" # 把进行一下步的预处理设为真
        break
   
    row = cur.Next()
    currentRow = currentRow + 1 #开始进入下次循环

del cur

gp.SetParameterAsText(3, str(value))
gp.SetParameterAsText(4, str(bContinue))# 输出