ArcGIS for Desktop

  • Dokumentation
  • Preise
  • Support

  • My Profile
  • Hilfe
  • Sign Out
ArcGIS for Desktop

ArcGIS Online

Die Mapping-Plattform für Ihre Organisation

ArcGIS for Desktop

Ein vollständiges professionelles GIS

ArcGIS for Server

GIS in Ihrem Unternehmen

ArcGIS for Developers

Werkzeuge zum Erstellen standortbezogener Apps

ArcGIS Solutions

Kostenlose Karten- und App-Vorlagen für Ihre Branche

ArcGIS Marketplace

Rufen Sie Apps und Daten für Ihre Organisation ab.

  • Dokumentation
  • Preise
  • Support
Esri
  • Anmelden
user
  • Eigenes Profil
  • Abmelden

Help

  • Startseite
  • Erste Schritte
  • Karte
  • Analysieren
  • Verwalten von Daten
  • Werkzeuge
  • Mehr...

InsertCursor

  • Zusammenfassung
  • Diskussion
  • Syntax
  • Eigenschaften
  • Methodenübersicht
  • Methoden
  • Codebeispiel

Zusammenfassung

InsertCursor establishes a write cursor on a feature class or table. InsertCursor can be used to add new rows.

Diskussion

When using InsertCursor on a point feature class, creating a PointGeometry and setting it to the SHAPE@ token is a comparatively expensive operation. Instead, define the point feature using tokens such as SHAPE@XY, SHAPE@Z, and SHAPE@M for faster, more efficient access.

Hinweis:

Opening simultaneous insert or update operations on the same workspace using different cursors requires the start of an edit session.

Hinweis:

arcpy.da.InsertCursor should not to be confused with arcpy.InsertCursor.

Syntax

InsertCursor (in_table, field_names)
ParameterErläuterungDatentyp
in_table

The feature class, layer, table, or table view.

String
field_names
[field_names,...]

A list (or tuple) of field names. For a single field, you can use a string instead of a list of strings.

Use an asterisk (*) instead of a list of fields if you want to access all fields from the input table (raster and BLOB fields are excluded). However, for faster performance and reliable field order, it is recommended that the list of fields be narrowed to only those that are actually needed.

Raster fields are not supported.

Additional information can be accessed using tokens (such as OID@) in place of field names:

  • SHAPE@XY —Ein Tupel von XY-Koordinaten für den Feature-Schwerpunkt.
  • SHAPE@TRUECENTROID —Ein Tupel von XY-Koordinaten für den tatsächlichen Feature-Schwerpunkt.
  • SHAPE@X —Duplikat der X-Koordinate des Features.
  • SHAPE@Y —Duplikat der Y-Koordinate des Features.
  • SHAPE@Z —Duplikat der Z-Koordinate des Features.
  • SHAPE@M —Duplikat des M-Wertes des Features.
  • SHAPE@JSON — Die Esri JSON-Zeichenfolge für die Geometrie.
  • SHAPE@WKB —Das Well-known Binary (WKB)-Format für OGC-Geometrie. Es bietet eine übertragbare Darstellung eines Geometriewertes in Form eines zusammenhängenden Datenstroms.
  • SHAPE@WKT —Das Well-Known Text (WKT)-Format für OGC-Geometrie. Es bietet eine übertragbare Darstellung eines Geometriewertes in Form einer Textzeichenfolge.
  • SHAPE@ —Ein Geometrie-Objekt für das Feature.

Polygon, polyline, or multipoint features can only be created using the SHAPE@ token.

Hinweis:

Die Token SHAPE@JSON, SHAPE@WKB und SHAPE@WKT werden ab ArcGIS 10.1 Service Pack 1 bereitgestellt.

String

Eigenschaften

EigenschaftErläuterungDatentyp
fields
(Schreibgeschützt)

A tuple of field names used by the cursor.

The tuple will include all fields (and tokens) specified by the field_names argument. If the field_names argument is set to "*", the fields property will include all fields used by the cursor. When using "*", geometry values will be returned in a tuple of the x,y-coordinates (equivalent to the SHAPE@XY token).

tuple

Methodenübersicht

MethodeErläuterung
insertRow (row)

Inserts a row into a table.

Methoden

insertRow (row)
ParameterErläuterungDatentyp
row
[row,...]

A list or tuple of values. The order of values must be in the same order as specified when creating the cursor.

When updating fields, if the incoming values match the type of field, the values will be cast as necessary. For example, a value of 1.0 to a string field will be added as "1.0", and a value of "25" added to a float field will be added as 25.0.

tuple

Rückgabewert

DatentypErläuterung
Integer

insertRow returns the objectid of the new row.

Codebeispiel

Use InsertCursor to insert new rows into a table.

import arcpy
import datetime

# Create an insert cursor for a table specifying the fields that will
# have values provided
fields = ['rowid', 'distance', 'CFCC', 'DateInsp']
cursor = arcpy.da.InsertCursor('D:/data/base.gdb/roads_maint', fields)

# Create 25 new rows. Set default values on distance and CFCC code
for x in range(0, 25):
    cursor.insertRow((x, 100, 'A10', datetime.datetime.now()))

# Delete cursor object
del cursor

Use InsertCursor with the SHAPE@XY token to add point features to a point feature class.

import arcpy

# A list of values that will be used to construct new rows
row_values = [('Anderson', (1409934.4442000017, 1076766.8192000017)),
              ('Andrews', (752000.2489000037, 1128929.8114))]

# Open an InsertCursor
cursor = arcpy.da.InsertCursor('C:/data/texas.gdb/counties',
                               ['NAME', 'SHAPE@XY'])

# Insert new rows that include the county name and a x,y coordinate
#  pair that represents the county center
for row in row_values:
    cursor.insertRow(row)

# Delete cursor object
del cursor

Use InsertCursor with the SHAPE@ token to add a new feature using a geometry object.

import arcpy

# Create a polyline geometry
array = arcpy.Array([arcpy.Point(459111.6681, 5010433.1285),
                     arcpy.Point(472516.3818, 5001431.0808),
                     arcpy.Point(477710.8185, 4986587.1063)])
polyline = arcpy.Polyline(array)

# Open an InsertCursor and insert the new geometry
cursor = arcpy.da.InsertCursor('C:/data/texas.gdb/counties', ['SHAPE@'])
cursor.insertRow([polyline])

# Delete cursor object
del cursor

Verwandte Themen

  • SearchCursor
  • UpdateCursor
  • Zugreifen auf Daten mit Cursorn
Feedback zu diesem Thema?

ArcGIS for Desktop

  • Startseite
  • Dokumentation
  • Preise
  • Support

ArcGIS Plattform

  • ArcGIS Online
  • ArcGIS for Desktop
  • ArcGIS for Server
  • ArcGIS for Developers
  • ArcGIS Solutions
  • ArcGIS Marketplace

Über Esri

  • Über uns
  • Karriere
  • Insider-Blog
  • User Conference
  • Developer Summit
Esri
© Copyright 2016 Environmental Systems Research Institute, Inc. | Datenschutz | Rechtliches