InsertCursor 可在要素类或表上建立写入游标。可以使用 InsertCursor 来添加新行。

对点要素类使用 InsertCursor 时,创建 PointGeometry 并将其设置为 SHAPE@ 令牌操作的代价相对较高。此时,使用诸如 SHAPE@XY、SHAPE@Z 和 SHAPE@M 等令牌定义的点要素访问反而更为快速有效。

使用 InsertCursor 在表中插入新行。

import arcpy
import datetime
# Create an insert cursor for a table specifying the fields that will
# have values provided
fields = ['rowid', 'distance', 'CFCC', 'DateInsp']
cursor = arcpy.da.InsertCursor('D:/data/base.gdb/roads_maint', fields)
# Create 25 new rows. Set default values on distance and CFCC code
for x in range(0, 25):
    cursor.insertRow((x, 100, 'A10', datetime.datetime.now()))
# Delete cursor object
del cursor

使用 InsertCursor 和 SHAPE@XY 令牌将点要素添加到点要素类中。

import arcpy
# A list of values that will be used to construct new rows
row_values = [('Anderson', (1409934.4442000017, 1076766.8192000017)),
              ('Andrews', (752000.2489000037, 1128929.8114))]
# Open an InsertCursor
cursor = arcpy.da.InsertCursor('C:/data/texas.gdb/counties',
                               ['NAME', 'SHAPE@XY'])
# Insert new rows that include the county name and a x,y coordinate
#  pair that represents the county center
for row in row_values:
    cursor.insertRow(row)
# Delete cursor object
del cursor

使用 InsertCursor 和 SHAPE@ 令牌添加一个使用几何对象的新要素。

import arcpy

# Create a polyline geometry
array = arcpy.Array([arcpy.Point(459111.6681, 5010433.1285),
                     arcpy.Point(472516.3818, 5001431.0808),
                     arcpy.Point(477710.8185, 4986587.1063)])
polyline = arcpy.Polyline(array)

# Open an InsertCursor and insert the new geometry
cursor = arcpy.da.InsertCursor('C:/data/texas.gdb/counties', ['SHAPE@'])
cursor.insertRow([polyline])

# Delete cursor object
del cursor

Logo

汇聚全球AI编程工具,助力开发者即刻编程。

更多推荐