Skip to main content

CreateTable

Краткая информация

Функция CreateTable создает таблицу или класс объектов с определенным набором полей в указанном месте.

Обсуждение

Эта функция позволяет определять поля и может использоваться для подготовки нового класса объектов или таблицы в сочетании с классом InsertCursor.

Эту функцию не следует путать с инструментом Создать таблицу.

Синтаксис

CreateTable(path, {fields}, {shape}, configuration)

Параметр Объяснение Тип данных

path

The path to the new table or feature class.

String

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:

  • POINT—The geometry type will be point.

  • MULTIPOINT—The geometry type will be multipoint.

  • POLYGON—The geometry type will be polygon.

  • POLYLINE—The geometry type will be polyline.

  • MULTIPATCH—The 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))