InsertCursor

摘要

Inserts rows into a feature class, shapefile, or table. The InsertCursor returns an enumeration object that hands out row objects.

讨论

New row objects can be obtained using the newRow method on the enumeration object into which rows are to be inserted. Each call to insertRow on the cursor creates a new row in the table whose initial values are set to the values in the input row.

语法

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
返回值
数据类型说明
Object

Returns a Cursor object against the specified feature class, shapefile, or table.

代码示例

InsertCursor example

Inserts 25 new rows into table.

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

相关主题


7/10/2012