Skip to main content

Array

Resumen

The Array object can contain points and arrays and is used to construct geometry objects.

Sintaxis

Array({items})

Nombre Explicación Tipo de datos

items

(Opcional)

Items can include a Point object, another Array object, or any iterable object that returns Point objects.

Object

Propiedades

Nombre Explicación Tipo de datos

count

(Solo lectura)

The element count of the array.

Integer

Métodos

add(value)

Adds a Point or Array object to the end of the array.

Nombre Explicación Tipo de datos

value

Either a Point or Array object can be appended to the array.

Object

append(value)

Appends an object to the array in the last position.

Nombre Explicación Tipo de datos

value

Either a Point or Array object can be appended to the array.

Object

clone(point_object)

Clone the Point object.

Nombre Explicación Tipo de datos

point_object

A Point object.

Point

extend(items)

Extend the array by appending elements.

Nombre Explicación Tipo de datos

items

Extend the array by adding strings, integers, or lists.

Object

getObject(index)

Returns the object at the given index position in the array.

The getObject method is equivalent to indexing an object; that is, obj.getObject(0) is equivalent to obj[0].

Nombre Explicación Tipo de datos

index

The index position of the array.

Integer

Valor de retorno

Tipo de datos Explicación

Object

The Array or Point object at the index position.

insert(index, value)

Adds an object to the Array object at the specified index.

Nombre Explicación Tipo de datos

index

The index position of the Array object.

Integer

value

The Point or Array object to be inserted.

Object

next()

Returns the next object at the current index.

Valor de retorno

Tipo de datos Explicación

Object

The next object at the current index.

remove(index)

Removes the object at the specified index position from the array.

Nombre Explicación Tipo de datos

index

The index position that will be removed.

Integer

removeAll()

Removes all values and creates an empty object.

replace(index, value)

Replaces the object at the specified index position in the Array object.

Nombre Explicación Tipo de datos

index

The index position that will be replaced.

Integer

value

The new Point or Array object to be added to the Array object.

Object

reset()

Sets the current enumeration index (used by the next method) back to the first element.

Muestra de código

Array example

Create a polyline feature class from scratch.

import arcpy

# A list of features and coordinate pairs
feature_info = [[[425585.75, 3769682.59],
                 [426151.56, 3767215.02],
                 [424941.35, 3764983.2]],
                [[416248.53, 3770551.91],
                 [416229.21, 3769315.87],
                 [417851.51, 3769270.81],
                 [417870.83, 3770493.97]]]

spatial_ref = arcpy.SpatialReference(26911)  # NAD 1983 UTM Zone 11N

# A list that will hold each of the Polyline objects
features = []

for feature in feature_info:
    # Create a Polyline object based on the array of points
    # Append to the list of Polyline objects
    features.append(
        arcpy.Polyline(
            arcpy.Array([arcpy.Point(*coords) for coords in feature]),
            spatial_ref))

# Persist a copy of the Polyline objects using CopyFeatures
arcpy.management.CopyFeatures(features, "c:/geometry/polylines.shp")