ArcGIS Desktop

  • 文档
  • 支持

  • My Profile
  • 帮助
  • Sign Out
ArcGIS Desktop

ArcGIS Online

专为贵组织打造的制图平台

ArcGIS Desktop

全面的专业性 GIS

ArcGIS Enterprise

面向企业的 GIS

ArcGIS for Developers

用于构建位置感知应用程序的工具

ArcGIS Solutions

适用于行业的免费模板地图和应用程序

ArcGIS Marketplace

获取适用于组织的应用程序和数据

  • 文档
  • 支持
Esri
  • 登录
user
  • 我的个人资料
  • 登出

ArcMap

  • 主页
  • 入门
  • 地图
  • 分析
  • 管理数据
  • 工具
  • 扩展模块

InsertCursor

  • 摘要
  • 说明
  • 语法
  • 属性
  • 方法概述
  • 方法
  • 代码示例

摘要

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

说明

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

注:

使用不同游标在同一个工作空间上开启同步插入或更新操作时,需要启动编辑会话。

旧版本:

在 ArcGIS 10.1 中引入了 arcpy.da 游标(arcpy.da.SearchCursor、arcpy.da.UpdateCursor 和 arcpy.da.InsertCursor),与先前已存在的游标功能(arcpy.SearchCursor、arcpy.UpdateCursor 和 arcpy.InsertCursor)组相比性能要快得多。仍然会提供原始游标,不过仅仅是为了能够继续向后兼容。

语法

InsertCursor (in_table, field_names)
参数说明数据类型
in_table

要素类、图层、表或表视图。

String
field_names
[field_names,...]

字段名称列表(或组)。对于单个字段,可以使用一个字符串,而不使用字符串列表。

如果要访问输入表中的所有字段(栅格和 BLOB 字段除外),可以使用星号 (*) 代替字段列表。但是,为了获得较快的性能和可靠的字段顺序,建议您将字段列表限制在实际需要的字段。

不支持栅格字段。

以令牌(如 OID@)取代字段名称可访问更多的信息:

  • SHAPE@XY —一组要素的质心 x,y 坐标。
  • SHAPE@TRUECENTROID —一组要素的真正质心 x,y 坐标。
  • SHAPE@X —要素的双精度 x 坐标。
  • SHAPE@Y —要素的双精度 y 坐标。
  • SHAPE@Z —要素的双精度 z 坐标。
  • SHAPE@M —要素的双精度 m 值。
  • SHAPE@JSON — 表示几何的 esri JSON 字符串。
  • SHAPE@WKB —OGC 几何的熟知二进制 (WKB) 制图表达。该存储类型将几何值表示为不间断的字节流形式。
  • SHAPE@WKT —OGC 几何的熟知文本 (WKT) 制图表达。其将几何值表示为文本字符串。
  • SHAPE@ —要素的几何对象。

面、折线或多点要素仅可使用 SHAPE@ 令牌创建。

String

属性

属性说明数据类型
fields
(只读)

游标使用的一组字段名称。

该组将包括由 field_names 参数指定的所有字段(和令牌)。如果 field_names 参数设置为 *,则字段属性将包括游标使用的全部字段。使用 * 时,几何值将以 x,y 坐标组返回(相当于 SHAPE@XY 令牌)。

fields 属性中字段名称的排序顺序将与 field_names 参数的传递顺序一致。

tuple

方法概述

方法说明
insertRow (row)

向表中插入一行。

方法

insertRow (row)
参数说明数据类型
row
[row,...]

A list or tuple of values. The order of values must be in the same order as specified when creating the cursor.

When updating fields, if the incoming values match the type of field, the values will be cast as necessary. For example, a value of 1.0 to a string field will be added as "1.0", and a value of "25" added to a float field will be added as 25.0.

tuple

返回值

数据类型说明
Integer

insertRow 将返回新行的 objectid。

代码示例

使用 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

相关主题

  • SearchCursor
  • UpdateCursor
  • 使用游标访问数据

ArcGIS Desktop

  • 主页
  • 文档
  • 支持

ArcGIS 平台

  • ArcGIS Online
  • ArcGIS Desktop
  • ArcGIS Enterprise
  • ArcGIS for Developers
  • ArcGIS Solutions
  • ArcGIS Marketplace

关于 Esri

  • 关于我们
  • 招贤纳士
  • 内部人员博客
  • 用户大会
  • 开发者峰会
Esri
分享您的想法。
Copyright © 2018 Esri. | 隐私政策 | 法律声明