InsertCursor (arcpy)

摘要

向要素类、shapefile 或表中插入行。InsertCursor 返回一个分发行对象的枚举对象。

讨论

可使用 newRow 方法从插入行的枚举对象获取新的行对象。每次调用光标上 insertRow 都会在表中创建新行,该行的初始值设置为输入行中的值。

语法

InsertCursor (dataset, {spatial_reference})
参数说明数据类型
dataset

The table, feature class, or shapefile into which rows will be inserted.

String
spatial_reference

Coordinates are specified in the spatial_reference provided and converted on the fly to the coordinate system of the dataset.

Object
返回值
数据类型说明
Cursor

返回针对指定要素类、shapefile 或表的光标对象。

代码实例

InsertCursor 示例

向表中插入 25 个新行。

import arcpy

# Create insert cursor for table 
# 
rows = arcpy.InsertCursor("D:/St_Johns/data.gdb/roads_lut") 
x = 1 

# Create 25 new rows. Set the initial row ID and distance values 
# 
while x <= 25: 
    row = rows.newRow() 
    row.rowid = x 
    row.distance = 100
    rows.insertRow(row) 
    x += 1

# Delete cursor and row objects to remove locks on the data 
# 
del row 
del rows

相关主题

9/15/2013