CreateTable

サマリー

The CreateTable function creates a table or feature class with a defined set of fields in a specified location.

説明

This function allows for the definition of fields and can be used to prepare a new feature class or table in combination with the InsertCursor class.

This function is not to be confused with the Create Table tool.

構文

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

A tuple of two values in which the first value is the path to the table or feature class and the second value is a list of the field names. The field names have been validated and may differ from what was specified by the fields parameter.

コードのサンプル

CreateTable example 1

Create a table using a tuple of field descriptions.

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 example 2

Create a polygon feature class using Field objects from an existing feature class.

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))