Howto: 使用UpdateCursor来根据一个字段值计算另外一个字段值
文章编号 : 35223
软件: ArcGIS - ArcEditor 9.2, 9.3, 9.3.1 ArcGIS - ArcInfo 9.2, 9.3, 9.3.1 ArcGIS - ArcView 9.2, 9.3, 9.3.1
操作系统: N/A
软件: ArcGIS - ArcEditor 9.2, 9.3, 9.3.1 ArcGIS - ArcInfo 9.2, 9.3, 9.3.1 ArcGIS - ArcView 9.2, 9.3, 9.3.1
操作系统: N/A
1 个回复
易智瑞技术支持
赞同来自:
有时候我们需要根据一个字段的值来设定另外一个字段的值,这可以通过使用UpdateCursor及条件语句来实现。
内容: 思路:
1. 创建geoprocessor对象。
2. 输入需要更新的要素类。
3. 创建UpdateCursor对象。
4. 逐行根据条件语句对指定字段赋值。
# Import the standard modules and create the geoprocessor...
import arcgisscripting, os, string, sys, time
gp = arcgisscripting.create()
# Set the overwrite to true...
gp.overwriteoutput = 1
# The file to be updated...
fc = r"C:\Temp\testdata.shp"
# Create the UpdateCursor Object
cur = gp.updatecursor(fc)
row = cur.next()
while row:
# Get the value of the field the calculation will be based on...
field1 = str(row.getvalue("FIELD1"))
# Conditional Statements
# if the field1 = value1, set field2 to equal NewVal1, etc...
if field1 == "Value1":
row.FIELD2 = "NewVal1"
cur.updaterow(row)
row = cur.next()
elif field1 == "Value2":
row.FIELD2 = "NewVal2"
cur.updaterow(row)
row = cur.next()
else:
row.FIELD2 = "NewVal3"
cur.updaterow(row)
row = cur.next()
del cur, row, gp
创建时间:2008-07-15
最近更新: 2011-05-03
【原文链接】
http://support.esrichina.com.c ... .html
要回复问题请先登录或注册