What is purpose of arcpy.Array()?

What is purpose of arcpy.Array()?

I am wondering what the purpose ofarcpy.Array()is. It seems an intermediate step between creating a list of objects and performing some sort of conversion, for example, such as in the sample code for the 10.1 help.

features.append( arcpy.Polyline( arcpy.Array([arcpy.Point(*coords) for coords in feature])))

What purpose does the arcpy array serve? Why can't a list suffice? What's the logic behind this intermediate step?

This is all my own speculation, so take it with a grain of salt:

From what I think I understand, arcpy is a wrapper/bridge to the arcgisscripting.pyd (essentially a DLL) which I think is a course grained wrapper of a lot of ArcObjects functionality written in C++. I do know for a fact that ArcObjects is not directly exposed in arcpy/arcgisscripting but you can get at them using the comtypes module.

My main point is I think that usingarcpy.Array()is the arcpy version of the ArcObjects IPointArray or probably more closely the IPointCollection interface. This data structure is probably enforced so that some internal data validation can happen under the hood to make sure there are valid inputs. Just using lists of lists could cause some problems (explicit is better than implicit :) ) without validation. That way, anyarcpy.Geometryobject knows it is getting valid input if it contains anarcpy.Array(even if it is empty). Thearcpy.Arrayalso understands things like donut holes.

ArcGIS provides its internal Functions through a python interface. Because some of them operate with a list of objects and they use the type Array as a function parameter, python lists do not work in this context. It isn't very 'pythonic' but there are examples in other modules too, numpy for example, where python standard types are substituted with specialized ones. The reason behind is, that there are tools like swig for 'converting' C++ Code to python, by putting a python caller to every c++ function (or class). This is an interesting (at least old) alternative approach to access arcobjects from python: Accessing ArcObjects from Python?

One example for using an array would be creating a polyline from an array of points. I am by no means a python expert (yet) but from my understanding is that it can provide a way of automating creating features from a list (array) of other features. Here is an article I found that may help a little.

ESRI Desktop 10.1 Help Article

Watch the video: Python: Working with Feature Data using ArcPy