CreateTable

摘要

CreateTable 函数用于在指定位置创建具有已定义字段集的表或要素类。

说明

此函数允许定义字段,并可用于结合 InsertCursor 类准备新的要素类或表。

不要将此函数与创建表格工具混淆。

语法

CreateTable (path, {fields}, {shape}, configuration)
参数说明数据类型
path

The path to the new table or feature class.

String
fields
[fields,...]

The fields that will be added to the table or feature class.

Fields can be specified using any of the following:

  • The field descriptions as a list of tuples. Each tuple will include the field name and the field type, and, optionally, the field alias, field length, a Boolean indicating whether the field is nullable, and default values.
  • A list of Field objects
  • A set of numpy.dtype() records.

(默认值为 None)

Field
shape

The shape field. If no value is provided, a table will be created.

The geometry is defined using a tuple of the geometry type, and, optionally, the spatial reference and whether z- and has m-values will be supported.

These values are defined as follows:

  • Geometry type—Use POINT, MULTIPOINT, POLYGON, POLYLINE, or MULTIPATCH keywords.
  • Spatial reference (optional)—A WKID string or SpatialReference object.
  • Has z (optional)—A Boolean value that specifies whether the feature class will support z-values.
  • Has m (optional)—A Boolean value that specifies whether the feature class will support m-values.

The geometry type options are defined as follows:

  • POINTThe geometry type will be point.
  • MULTIPOINTThe geometry type will be multipoint.
  • POLYGONThe geometry type will be polygon.
  • POLYLINEThe geometry type will be polyline.
  • MULTIPATCHThe geometry type will be multipatch.

(默认值为 None)

String
configuration

The configuration keyword applies to enterprise geodatabase data only. It determines the storage parameters of the database table.

(默认值为 None)

String
返回值
数据类型说明
tuple

两个值的元组,其中第一个值是表或要素类的路径,第二个值是字段名称的列表。 字段名称已经过验证,可能与 fields 参数指定的名称不同。

代码示例

CreateTable 示例 1

使用字段描述的元组创建表。

import arcpy

path = r"C:\data\myFGDB.gdb\myTable"
fields = [("street", "Text", "Street Address"),
          ("city", "Text"),
          ("state", "Text", "", 2),
          ("zip", "Long")]

arcpy.da.CreateTable(path, fields)
CreateTable 示例 2

使用现有要素类中的 Field 对象创建面要素类。

import arcpy

tbl = r"C:\data\myFGDB.gdb\myTable"
path = r"C:\data\myFGDB.gdb\polyFC"
fields = [i for i in arcpy.ListFields(tbl) if (i.type != "OID")]

table_path, field_names = arcpy.da.CreateTable(path, fields, ("POLYGON", 4326))