Краткая информация
Функция 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:
(Значение по умолчанию — 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))