摘要
此 CreateTable 函数用于在指定位置创建具有已定义字段集的表或要素类。
语法
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:
(默认值为 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:
The geometry type options are defined as follows:
(默认值为 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 参数指定的名称不同。 |
代码示例
使用字段描述的元组创建表。
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)使用现有要素类中的 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))