【arcpy.da.InsertCursor 数据插入】

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

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值